toutpratique/override/controllers/front/SearchController.php
Marion Muszynski 7a4a19cfc4 search tag
2015-09-24 14:54:03 +02:00

100 lines
3.0 KiB
PHP

<?php
require _PS_MODULE_DIR_.'cmsps/cmsps.php';
class SearchController extends SearchControllerCore
{
public function initContent()
{
if (Tools::getValue('ajax')) {
if (Tools::getValue('type')=='tag')
$this->displayAjaxgetRelationPostTaches();
elseif (Tools::getValue('type')=='support')
$this->displayAjaxgetRelationPostSupport();
}
if (Tools::getValue('tagWhat') || Tools::getValue('tagWhere')){
if(Tools::getValue('tagWhat'))
$tags[] = (int)Tools::getValue('tagWhat');
if(Tools::getValue('tagWhere'))
$tags[] = (int)Tools::getValue('tagWhere');
$post = CmsPsPost::specificSearch($tags, $this->context->language->id);
if($post)
Tools::redirect($this->context->link->getPostCmsLink($post->id_post));
else
Tools::redirect($this->context->link->getPostCmsLink(48));
}
parent::initContent();
if (($query = Tools::getValue('search_query', Tools::getValue('ref'))) && !is_array($query)) {
$posts = CmsPsPost::search($query, 15, $this->context->language->id);
$editos = CmsPsEdito::search($query, 15, $this->context->language->id);
$this->context->smarty->assign(array(
'posts' => $posts,
'editos' => $editos,
'test' => 'test'
));
}
}
public function displayAjaxgetRelationPostTaches()
{
if(!class_exists('Cms_ExtraFields')) {
require _PS_MODULE_DIR_.'cms_extrafields/cms_extrafields.php';
}
$id_lang = Context::getContext()->language->id;
$sql = '
SELECT x.id_cmsps_extrafields_value as id, lx.value as content
FROM `'._DB_PREFIX_.'cmsps_extrafields_value` x
LEFT JOIN `'._DB_PREFIX_.'cmsps_extrafields_value_lang` lx
ON x.`id_cmsps_extrafields_value` = lx.`id_cmsps_extrafields_value`
AND lx.id_lang = '.$id_lang.'
WHERE 1
AND x.id_group = '.Cms_ExtraFields::TACHES.'
'.( Tools::getValue('q') != '' ? ' AND lx.value LIKE "%'.pSQL(Tools::getValue('q')).'%"' : '' ).'
GROUP BY x.id_cmsps_extrafields_value';
if (isset($id_shop) && $id_shop) {
$sql.= ' AND lx.`id_shop` = '.(int)$id_shop;
}
$res = Db::getInstance()->executeS($sql);
die(json_encode(array('results' => $res)));
}
public function displayAjaxgetRelationPostSupport()
{
if(!class_exists('Cms_ExtraFields')) {
require _PS_MODULE_DIR_.'cms_extrafields/cms_extrafields.php';
}
$id_lang = Context::getContext()->language->id;
$sql = '
SELECT x.id_cmsps_extrafields_value as id, lx.value as content
FROM `'._DB_PREFIX_.'cmsps_extrafields_value` x
LEFT JOIN `'._DB_PREFIX_.'cmsps_extrafields_value_lang` lx
ON x.`id_cmsps_extrafields_value` = lx.`id_cmsps_extrafields_value`
AND lx.id_lang = '.$id_lang.'
WHERE 1
AND x.id_group = '.Cms_ExtraFields::SUPPORT.'
'.( Tools::getValue('q') != '' ? ' AND lx.value LIKE "%'.pSQL(Tools::getValue('q')).'%"' : '' ).'
GROUP BY x.id_cmsps_extrafields_value';
if (isset($id_shop) && $id_shop) {
$sql.= ' AND lx.`id_shop` = '.(int)$id_shop;
}
$res = Db::getInstance()->executeS($sql);
die(json_encode(array('results' => $res)));
}
}