Ncmodel.php
3.61 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
<?php
/**
* @package anc_playlist
* @category magento
* @mailto code [at] netz.coop
* @author netz.coop eG*
* @copyright (c) 2014, netz.coop eG
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
class Anc_Playlist_Helper_Ncmodel extends Mage_Core_Helper_Abstract {
/**
* cache für anc_image/ncimage models
* @var array
*/
private $NcPlaylists = array();
public function getNcAlbumByAlbumId($param_id) {
return Mage::helper('anc_lib/ncrights')->loadNcModel('anc_album/ncalbum', $param_id);
}
public function getNcAlbumByUrlauth($param_id) {
$ncplaylist = Mage::helper('anc_lib/ncrights')->getNcModelBy('anc_playlist/ncplaylist', 'urlauth', $param_id);
return Mage::helper('anc_lib/ncrights')->loadNcModel('anc_album/ncalbum', $ncplaylist->getNcalbumId());
}
public function getOneNcImageFromNcAlbum($param_ncalbum_id, $param_image_nr=false) {
if(!$param_image_nr) {
$param_image_nr = 0;
}
if($param_image_nr !== false) {
$ncimages_collection = Mage::helper('anc_lib/ncrights')->getNcModelsByOneFilter('anc_image/ncimage', 'ncalbum_id', $param_ncalbum_id) ;
$ncimages = $ncimages_collection->getData();
if($param_image_nr >= count($ncimages)) {
$param_image_nr = $param_image_nr % count($ncimages);
}
if($param_image_nr < 0) {
$howmuchplus = round($param_image_nr/count($ncimages))*-1;
$param_image_nr = ($param_image_nr+count($ncimages)) + ($howmuchplus*count($ncimages));
}
//D::show($ncimages, '$ncimages :'.$param_image_nr,1,1);
return $ncimages[$param_image_nr];
} else {
// $ncimage = Mage::getModel("anc_image/ncimage")->load($param_ncalbum_id, 'ncalbum_id');
$ncimage = Mage::helper('anc_lib/ncrights')->getNcModelBy('anc_image/ncimage', 'ncalbum_id', $param_ncalbum_id);
//D::show($ncimage->getData(), '$ncimage->getData()',1,1) ;
return $ncimage->getData();
}
}
public function getNcPlaylist($param_playlist_id) {
if($param_playlist_id) {
if(!array_key_exists($param_playlist_id, $this->NcPlaylists)) {
// $ncplaylist = Mage::getModel('anc_playlist/ncplaylist')->load($param_playlist_id);
$ncplaylist = Mage::helper('anc_lib/ncrights')->loadNcModel('anc_playlist/ncplaylist', $param_playlist_id);
$this->NcPlaylists[$param_playlist_id] = $ncplaylist;
}
return $this->NcPlaylists[$param_playlist_id];
} else {
return false;
}
}
public function getBlancoNcPlaylist() {
$ncplaylist = Mage::getModel('anc_playlist/ncplaylist');
if(is_object($ncplaylist)) {
return $ncplaylist;
} else {
D::show($ncplaylist,'getBlancoNcPlaylist leer',1,1);
}
}
public function saveNcPlaylist(Anc_Playlist_Model_Ncplaylist $param_ncplaylist) {
if(is_object($param_ncplaylist)) {
$param_ncplaylist->save();
$this->NcPlaylists[$param_ncplaylist->getId()] = $param_ncplaylist;
return $this->NcPlaylists[$param_ncplaylist->getId()];
} else {
return false;
}
}
public function setNewUrlauth(Anc_Playlist_Model_Ncplaylist $param_ncplaylist) {
$param_ncplaylist->setData('urlauth',uniqid('pl', true));
}
}