Ncmodel.php 3.61 KB
<?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));
	}
}