<?php


class ProductController  extends ModuleController implements ControllerInterface
{

	/**
	  * (non-PHPdoc)
	  * @see class/ControllerInterface#IndexAction($param)
	  */
	public function IndexAction($param) {
		//Utils::ArrayDisplay($param);
		$idCategory = $param['idCategory'];
		$this->smarty->assign('idCategory', $idCategory);

		$idsProduct = MfProductLinkDAL::GetIdStringDestinaion('mf_product_category', 'mf_product',$idCategory, $param['lang']);

		$dalData = MfProductDAL::GetDalDataObj();
		$dalData->setJoin(array('MfProductDescription' => ' LEFT JOIN mf_product_description ON mf_product.id_mf_product=mf_product_description.id_mf_product'));
		$dalData->setCondition(array('lang' => $param['lang']));
		//Utils::ArrayDisplay('ss'.$idsProduct);
		$dalData->addCondition('   ', 'mf_product.id_mf_product IN ('.$idsProduct.') ', ' ');
		$arrayObj = MfProductDAL::GetResult($dalData);

		$this->smarty->assign('arrayObj', $arrayObj);
		$this->smarty->assign('urlProductDetailLabel', $param['urlDetailLabel']);


	}

	public function ViewAction($param) {

		$idCategory = $param['idCategory'];
		$this->smarty->assign('idCategory', $idCategory);

		//====Attribute======================================================

		$idsAttribute = MfProductLinkDAL::GetIdStringDestinaion('mf_product_category', 'mf_product_attribute', $idCategory, $param['lang']);
		$dalData = MfProductAttributeDAL::GetDalDataObj();
		$dalData->setCondition(array('lang' => $param['lang']));
		$dalData->addCondition('   ', 'mf_product_attribute.id_mf_product_attribute IN ('.$idsAttribute.') ', ' ');
		$dalData->setJoin(array('MfProductAttributeDescription' => ' LEFT JOIN mf_product_attribute_description ON mf_product_attribute.id_mf_product_attribute=mf_product_attribute_description.id_mf_product_attribute'));

		$arrayObjAttribute = MfProductAttributeDAL::GetResult($dalData);
		//--------------------------------------------------------------------

		//====Attribute=Value=================================================
		$dalDataValue = MfProductAttributeValueDAL::GetDalDataObj();
		$dalDataValue->setCondition(array('lang' => $param['lang'], 'id_mf_product' => $param['id']));
		$dalDataValue->addCondition('   ', 'id_mf_product_attribute IN ('.$idsAttribute.') ', ' ');
		$arrayObjAttributeValue = MfProductAttributeValueDAL::GetResult($dalDataValue);
		//Utils::ArrayDisplay($dalDataValue);
		//Utils::ArrayDisplay($arrayObjAttributeValue);
		$arrayObjAttributeValueTmp = array();
		foreach ($arrayObjAttributeValue as $attrValKey => $objAttributValue ) {
			$arrayObjAttributeValueTmp[$objAttributValue->getIdMfProductAttribute()] = $objAttributValue;
		}
		$arrayObjAttributeValue = $arrayObjAttributeValueTmp;
		foreach ($arrayObjAttribute as $attrKey => $objAttribut ) {
			if (key_exists($objAttribut->getId(), $arrayObjAttributeValue)) {
				$arrayObjAttribute[$attrKey]->setValue($arrayObjAttributeValue[$objAttribut->getId()]->getValue());
			}
		}
		//---------------------------------------------------------------------


		//=====Product=========================================================

		$dalData = MfProductAttributeDAL::GetDalDataObj();
		$dalData->setCondition(array('lang' => $param['lang']));
		$dalData->addCondition('   ', 'mf_product_attribute.id_mf_product_attribute IN ('.$idsAttribute.') ', ' ');
		$dalData->setJoin(array('MfProductAttributeDescription' => ' LEFT JOIN mf_product_attribute_description ON mf_product_attribute.id_mf_product_attribute=mf_product_attribute_description.id_mf_product_attribute'));

		$objProduct = MfProductDAL::GetById($param['id'], $param['lang']);






		$this->smarty->assign('arrayObjAttribute', $arrayObjAttribute);
		$this->smarty->assign('idProduct', $param['id']);
		$this->smarty->assign('objProduct', $objProduct);

		$this->addScript('jQuery/jquery.jcarousel.min.js');
		$this->addScript('jQuery/jquery.lightbox-0.5.js');

		$this->addScript('gallery.js');
		$this->AddCSS('jquery.lightbox-0.5.css');
		$this->AddCSS('skin.css');
		$this->smarty->assign('showGallery', true);

	}



	/**
	 * 
	 * @param unknown_type $param
	 * @return unknown_type
	 */
	public function preDispatch($param) {
		$this->smarty->assign('lang', $param['lang']);

		$this->Run($param);
		//$this->AddTitle('');
		//		$this->RunShared('Banner', $param);
	}
	/**
	 * 
	 * @param unknown_type $param
	 * @return unknown_type
	 */
	public function postDispatch($param) {

	}
}
?>