Ncmodel.php 4.55 KB
<?php
/**
 * @package  anc_image
 * @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_Image_Helper_Ncmodel extends Mage_Core_Helper_Abstract {
	/**
	 *	cache für anc_image/ncimage models
	 * @var array
	 */
	private $NcImages = array();
	/**
	 * gibt zurück wie oft das bild schon für den kauf verwendet wurde
	 * 
	 * @param int $param_ncimage_id
	 * @return Anc_Image_Model_Resource_Mysql4_Ncimage_Quoteitemoption_Collection
	 */
	public function getNcImageMetaData($param_ncimage_id) {
		$collection = Mage::getModel('anc_image/ncimage_quoteitemoption')->getCollection();
		$Quoteitemoption_Collection = $collection->addFieldToFilter('ncimage_id',$param_ncimage_id);
		return $Quoteitemoption_Collection;
	}	
	
	/**
	 * 
	 * @param int $param_ncimage_id
	 * @return anc_image/ncimage
	 */
	public function getNcImage($param_ncimage_id) {
		if($param_ncimage_id) {
			if(!array_key_exists($param_ncimage_id, $this->NcImages)) {
//				$ncimage = Mage::getModel('anc_image/ncimage')->load($param_ncimage_id);
				$ncimage = Mage::helper('anc_lib/ncrights')->loadNcModel('anc_image/ncimage', $param_ncimage_id);
				$this->NcImages[$param_ncimage_id] = $ncimage;
			}
			return $this->NcImages[$param_ncimage_id];			
		} else {
			return false;
		}
	}		

	public function getNcImagesForCustomer($param_customerid=null) {
//		D::ulli('$param_customerid'.$param_customerid ,1);
		if(!$param_customerid){
			$customerid = Mage::getSingleton('customer/session')->getCustomer()->getId();
		}else{
			$customerid=$param_customerid;
		}
		
		return Mage::getModel('anc_image/ncimage')->getCollection()->addFieldToFilter('customer_id', $customerid);
//		return Mage::helper('anc_lib/ncrights')->getNcModelsByOneFilter('anc_image/ncimage', 'customer_id', $customerid);
	}	

	public function getNcImagesForAlbum($param_album_id) {
//		$customer = Mage::getSingleton('customer/session')->getCustomer();
//		return Mage::getModel('anc_image/ncimage')->getCollection()->addFieldToFilter('ncalbum_id', $param_album_id);
		$param_arrayFields = array(
					'ncalbum_id',
					'ordered'
				);
				$param_arrayContent = array(
					array('eq' => $param_album_id),
					array('null' => true),
				);
		return Mage::helper('anc_lib/ncrights')->getNcModelsByOneFilter('anc_image/ncimage', $param_arrayFields, $param_arrayContent);
//		return Mage::helper('anc_lib/ncrights')->getNcModelsByOneFilter('anc_image/ncimage', 'ncalbum_id', $param_album_id);
	}	

	public function saveNcImage(Anc_Image_Model_Ncimage $param_ncimage) {
		if(is_object($param_ncimage)) {
			$param_ncimage->save();
			$this->NcImages[$param_ncimage->getId()] = $param_ncimage;
			return $this->NcImages[$param_ncimage->getId()];
		} else {
			return false;
		}
	}	
	
	public function deleteNcImage(Anc_Image_Model_Ncimage $param_ncimage) {
		if(is_object($param_ncimage)) {
 			$customer = Mage::getSingleton('customer/session')->getCustomer();
			if($customer->getId() && $customer->getId() === $param_ncimage->getCustomerId()) {
				Mage::helper('anc_image/ncmodel')->deleteNcImageFiles($param_ncimage);
				$param_ncimage->delete();
//				D::s($param_ncimage, '$param_ncimage');
				return true;
			} else {
				return false;
			}
		} else {
			return false;
		}
	}	
	
	public function deleteNcImageFiles(Anc_Image_Model_Ncimage $param_ncimage) {
		if(is_object($param_ncimage)) {
 			$customer = Mage::getSingleton('customer/session')->getCustomer();
			if($customer->getId() && $customer->getId() === $param_ncimage->getCustomerId()) {
//				mcFile::deleteFile(Mage::getBaseDir().$param_ncimage->getPath());								
				mcFile::deleteFile(Mage::helper('anc_lib/ncfilepath')->getThisMagentoInstallationPath().$param_ncimage->getPath());				
				return true;
			} else {
				return false;
			}
		} else {
			return false;
		}
	}	
	public function getBlancoNcImageQuoteitemoption() {
		return Mage::getModel('anc_image/ncimage_quoteitemoption');
	}	
}