<?php


class SearchController  extends MainController implements ControllerInterface
{

	/**
	  * (non-PHPdoc)
	  * @see class/ControllerInterface#IndexAction($param)
	  */
	public function IndexAction($param) {
		//Utils::ArrayDisplay($param);
		//Utils::ArrayDisplay($_POST);

		if (Request::GetPost('search')) {

			//Art
			$search= trim(Request::GetPost('search'));
			$arraySearch = explode(' ', $search);

			$dalDataArt = SimpleArticle_MfArticleDAL::GetDalDataObj();
			if (count($arraySearch) > 0) {
				$where = ' ( ';
				foreach ($arraySearch as $key => $search) {
					$where .= $key == 0 ? '' : ' OR ';
					$where .= ' mf_article_description.title LIKE "%'.Utils::AddSlashes($search).'%" ';
					$where .= ' OR mf_article_description.description LIKE "%'.Utils::AddSlashes($search).'%" ';
				}
				$where .= ' ) ';
				//Utils::ArrayDisplay($where);
				$dalDataArt->addCondition('mf_article_description.lang', $param['lang']);
				$dalDataArt->addCondition('mf_article_description.publication', 1);
				$dalDataArt->addCondition(' ', $where, ' ');
			}
			$dalDataArt->setJoin(array('SimpleArticle_MfArticleDescription' => ' LEFT JOIN mf_article_description ON mf_article.id_mf_article=mf_article_description.id_mf_article'));
			$arrayObjArt = SimpleArticle_MfArticleDAL::GetResult($dalDataArt);

			$arrayObjArtStr = array();
			foreach ($arrayObjArt as $objArt) {
				$dalDataStr = StructureDAL::GetDalDataObj();
				$dalDataStr->addCondition('id_content', $objArt->GetId());
				$obStr = StructureDAL::GetResult($dalDataStr);
				if (isset($obStr[0])) {
					$objArt->setStructure($obStr[0]);
					$arrayObjArtStr[] = $objArt;
				}

			}
			$this->smarty->assign('arrayObjArtStr', $arrayObjArtStr);
			$this->smarty->assign('search', Request::GetPost('search'));

		} else {
			$this->smarty->assign('arrayObjArtStr', array());
		}

	}


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


		//$this->AddTitle('');
		//		$this->RunShared('Banner', $param);

	}
	/**
	 * 
	 * @param unknown_type $param
	 * @return unknown_type
	 */
	public function postDispatch($param) {

	}
}
?>