Ncsvginterface.php 5.32 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_Ncsvginterface extends Mage_Core_Helper_Abstract {
	/**
	 *  Bearbeiten eines BildElementes in einer SVG (erstellt mit Inkscape Erweiterung)
	 * @param type $domel
	 * @param type $p_parentitemId
	 * @param type $MagentoID - Produkt id
	 * @return type
	 */
	private function editSiteSVG(DOMNode $domel, $p_parentitemId, $MagentoID, $p_subroductarray, $p_siteID, $p_magentoSiteWidth, $p_is_preview) {
//		D::li("editSiteSVG(DOMNode $domel, $p_parentitemId, $MagentoID, $p_subroductarray, $p_siteID, $p_magentoSiteWidth, $p_is_preview)",1,1);

		
		
		if (true) {

			
			$ChildrenItemIds = Mage::helper('anc_printconfigproduct/cart')->getChildrenItemIds($p_parentitemId, $MagentoID);
			$ncplaylist_id = Mage::helper('anc_lib/quoteitem')->getItemProductOptionByOptionSku($ChildrenItemIds[0], Mage::helper('anc_playlist/ncconstant')->AncPlaylistOptionSku);
		
			if($ncplaylist_id) {
				$NcPlaylist = Mage::helper('anc_playlist/ncmodel')->getNcPlaylist($ncplaylist_id);
				$QrText = Mage::getUrl('playlist/site/showplaylist',array('urlauth' => $NcPlaylist->getUrlauth()));
			} else {
				$QrText = 'Konfigurieren Sie bitte Ihre Playlist.';
			}
			/*
			 * wenn vorschau und es soll ne homepage sein, dann nehme die dump homepage
			 * @author n @since 20140428
			 */
			if ($p_is_preview) {
//				$QrText = Mage::getUrl('playlist/site/showplaylist',array('ncalbum_id' => $ncplaylist_id));

				$path = Mage::helper('anc_lib/ncfilepath')->getModuleCustomerFilepath('anc_playlist', true);
			} else {
//				$path = '/media/serviceplus/qrcodes/';
				$path = Mage::helper('anc_lib/ncfilepath')->getModuleCustomerFilepath('anc_playlist', true);
			}
			
//			$filename = 'qrcode_'.$p_subroductarray['cal']['item_id'].'_'.$p_subroductarray['qr'][$MagentoID]['item_id'].'_'.Mage::helper('anc_printconfigproduct/xml')->get('calside') .'.png';
			if(is_object($NcPlaylist) && $urlauth = $NcPlaylist->getUrlauth()) {
				$urlauth = '_'.$urlauth;
			}
			$filename = 'qrcode_item'.$p_parentitemId.$urlauth.'.png';

			
			$filepath =Mage::helper('anc_lib/ncfilepath')->getThisMagentoInstallationPath().$path.$filename;
//			D::li('$QrText: '.$QrText,1,1);
			$height=$domel->getAttribute('height');
			$file = $this->createQR($QrText, $filepath, $height, 0);
			$domel->setAttribute('xlink:href', 'file://' . $file);
			$domel->setAttribute('qrfilepath', $filepath);
			$domel->setAttribute('qrtext', $QrText);
			$domel->setAttribute('parentitemid', $p_parentitemId);
		} else {
			$domel->removeAttribute('xlink:href');
		}



		return $domel;
	}
	
	/**
	 * Create QR 
	 */
	private function createQR($p_qrtxt, $p_tmp_qrfilepath, $p_size = '100', $p_margin = 0) {
		$qrcodequality = Mage::helper('anc_printconfigproduct/constant')->get('ancpcpqrcodequality'); //
		$varsize = $p_size * $qrcodequality;
//		D::ulli('$varsize'.$varsize.'$p_size: '.$p_size.' $qrcodequality '.$qrcodequality,5,1,1);
		QRcode::png($p_qrtxt, $p_tmp_qrfilepath, $level = QR_ECLEVEL_L, $varsize, $p_margin, $saveandprint = false);
		return $p_tmp_qrfilepath;
	}	

	
	
	public function prepareEditSiteSVG($domel, $p_parentitemId, $MagentoID, $p_subproductarray) {
		$siteID = $p_subproductarray['site'][$MagentoID]['item_id'];
		$domel->setAttribute('itemId', $siteID);
		$magentoSiteWidth = $domel->getAttribute('width');
		$is_preview = true;
//		$product = Mage::getModel('catalog/product')->load($siteID);
//		$product= Mage::getModel('catalog/product')->load($siteID);
//		$BundleSelectionProductIds = Mage::helper('anc_printconfigproduct/bundleindividual')->getBundleSelectionProductIds($product);
//		D::s($BundleSelectionProductIds,'$BundleSelectionProductIds',5,1,1);
//		$BundleSelectionProductIds = Mage::helper('anc_printconfigproduct/bundleindividual')->getBundleItemSelections($p_parentitemId);
//		$product= Mage::getModel('catalog/product')->load($MagentoID);
//		$_option = $product->getOptions();
////D::fe($_option, '$_option')
//		D::s($_option,'$_option',5,1,1);

		if ($siteID) {
			$order_id = Mage::helper('anc_lib/sql')->selectFetchOne('order_id', 'sales/order_item', array('quote_item_id' => $siteID));

			/*
			 * wenn nicht order id dann vorschau
			 */
			if (!$order_id) {
				$is_preview = true;
			} else {
				$is_preview = false;
			}
		}
//		$domel = Mage::helper('anc_printconfigproduct/xmlextensions')->editSiteSVG($domel, $p_parentitemId, $MagentoID, $p_subproductarray, $siteID, $magentoSiteWidth, $is_preview);
		$domel = Mage::helper('anc_playlist/ncsvginterface')->editSiteSVG($domel, $p_parentitemId, $MagentoID, $p_subproductarray, $siteID, $magentoSiteWidth, $is_preview);
	}	
}