add post and edito to search + tpl edito

This commit is contained in:
Thibault GUILLAUME 2015-09-21 17:26:42 +02:00
parent 0113e5109a
commit ba5812bb12
8 changed files with 125 additions and 39 deletions

View File

@ -1,2 +1,2 @@
<?xml version="1.0"?> <?xml version="1.0"?>
<modules_list><modules type="untrusted"><module name="bankwire"/><module name="blockadshooks"/><module name="blockadvertising"/><module name="blockbanner"/><module name="blockbestsellers"/><module name="blockcart"/><module name="blockcategories"/><module name="blockcms"/><module name="blockcmsinfo"/><module name="blockcontact"/><module name="blockcontactinfos"/><module name="blockcurrencies"/><module name="blockcustomerprivacy"/><module name="blocklanguages"/><module name="blocklayered"/><module name="blocklink"/><module name="blockmanufacturer"/><module name="blockmyaccount"/><module name="blockmyaccountfooter"/><module name="blocknewproducts"/><module name="blocknewsletter"/><module name="blockpaymentlogo"/><module name="blockpermanentlinks"/><module name="blockreinsurance"/><module name="blockrss"/><module name="blocksearch"/><module name="blocksharefb"/><module name="blocksocial"/><module name="blockspecials"/><module name="blockstore"/><module name="blocksupplier"/><module name="blocktags"/><module name="blocktopmenu"/><module name="blockuserinfo"/><module name="blockviewed"/><module name="blockwishlist"/><module name="categorieshome"/><module name="cheque"/><module name="cms_comments"/><module name="cms_extrafields"/><module name="cms_menu"/><module name="cms_pack"/><module name="cmsps"/><module name="cronjobs"/><module name="crossselling"/><module name="dashactivity"/><module name="dashgoals"/><module name="dashproducts"/><module name="dashtrends"/><module name="gamification"/><module name="graphnvd3"/><module name="gridhtml"/><module name="homefeatured"/><module name="homeslider"/><module name="pagesnotfound"/><module name="productcomments"/><module name="productpaymentlogos"/><module name="productscategory"/><module name="producttooltip"/><module name="referralprogram"/><module name="sekeywords"/><module name="sendtoafriend"/><module name="seourl"/><module name="socialsharing"/><module name="statsbestcategories"/><module name="statsbestcustomers"/><module name="statsbestmanufacturers"/><module name="statsbestproducts"/><module name="statsbestsuppliers"/><module name="statsbestvouchers"/><module name="statscarrier"/><module name="statscatalog"/><module name="statscheckup"/><module name="statsdata"/><module name="statsequipment"/><module name="statsforecast"/><module name="statslive"/><module name="statsnewsletter"/><module name="statsorigin"/><module name="statspersonalinfos"/><module name="statsproduct"/><module name="statsregistrations"/><module name="statssales"/><module name="statssearch"/><module name="statsstock"/><module name="statsvisits"/><module name="trackingfront"/><module name="vatnumber"/></modules></modules_list> <modules_list><modules type="untrusted"><module name="bankwire"/><module name="blockadshooks"/><module name="blockadvertising"/><module name="blockbanner"/><module name="blockbestsellers"/><module name="blockcart"/><module name="blockcategories"/><module name="blockcms"/><module name="blockcmsinfo"/><module name="blockcontact"/><module name="blockcontactinfos"/><module name="blockcurrencies"/><module name="blockcustomerprivacy"/><module name="blocklanguages"/><module name="blocklink"/><module name="blockmanufacturer"/><module name="blockmyaccount"/><module name="blockmyaccountfooter"/><module name="blocknewproducts"/><module name="blocknewsletter"/><module name="blockpaymentlogo"/><module name="blockpermanentlinks"/><module name="blockreinsurance"/><module name="blockrss"/><module name="blocksearch"/><module name="blocksharefb"/><module name="blocksocial"/><module name="blockspecials"/><module name="blockstore"/><module name="blocksupplier"/><module name="blocktags"/><module name="blocktopmenu"/><module name="blockuserinfo"/><module name="blockviewed"/><module name="blockwishlist"/><module name="categorieshome"/><module name="cheque"/><module name="cms_comments"/><module name="cms_extrafields"/><module name="cms_menu"/><module name="cms_pack"/><module name="cmsps"/><module name="cronjobs"/><module name="crossselling"/><module name="dashactivity"/><module name="dashgoals"/><module name="dashproducts"/><module name="dashtrends"/><module name="graphnvd3"/><module name="gridhtml"/><module name="homefeatured"/><module name="homeslider"/><module name="pagesnotfound"/><module name="productcomments"/><module name="productpaymentlogos"/><module name="productscategory"/><module name="producttooltip"/><module name="referralprogram"/><module name="sekeywords"/><module name="sendtoafriend"/><module name="seourl"/><module name="socialsharing"/><module name="vatnumber"/></modules></modules_list>

View File

@ -66,4 +66,32 @@ class CmsPsEdito extends ObjectModel {
return $articles = $collection_post->getResults(); return $articles = $collection_post->getResults();
} }
public static function search($query, $limit, $id_lang)
{
$result = array();
$query_posts = '
SELECT p.`id_edito`
FROM `'._DB_PREFIX_.'cmsps_editos` p
LEFT JOIN `'._DB_PREFIX_.'cmsps_editos_lang` pl ON(p.`id_edito` = pl.`id_edito`)
WHERE p.`active` = 1
AND (
pl.`title` LIKE "%'.pSql($query).'%"
OR pl.`content` LIKE "%'.pSql($query).'%"
)
ORDER BY p.`date_add` DESC
LIMIT '.(int)$limit
;
$ids = Db::getInstance()->executeS($query_posts);
if ($ids) {
foreach ($ids as $key => $id) {
$result[] = new CmsPsEdito($id['id_edito'], $id_lang);
}
}
return $result;
}
} }

View File

@ -330,6 +330,33 @@ class CmsPsPost extends ObjectModel {
} }
} }
public static function search($query, $limit, $id_lang)
{
$result = array();
$query_posts = '
SELECT p.`id_post`
FROM `'._DB_PREFIX_.'cmsps_posts` p
LEFT JOIN `'._DB_PREFIX_.'cmsps_posts_lang` pl ON(p.`id_post` = pl.`id_post`)
WHERE p.`active` = 1
AND (
pl.`title` LIKE "%'.pSql($query).'%"
OR pl.`content` LIKE "%'.pSql($query).'%"
)
ORDER BY p.`note` DESC
LIMIT '.(int)$limit
;
$ids = Db::getInstance()->executeS($query_posts);
if ($ids) {
foreach ($ids as $key => $id) {
$result[] = new CmsPsPost($id['id_post'], $id_lang);
}
}
if ($result)
return self::injectsData($result);
return $result;
}
} }

View File

@ -0,0 +1,24 @@
<?php
require _MODULE_DIR_.'/cmsps/cmsps.php';
class SearchController extends SearchControllerCore
{
public function initContent()
{
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'
));
}
}
}

View File

@ -0,0 +1,9 @@
<div class="col-md-{$column} edito">
<div class="inner">
<h3><a href="{$link->getPostEditoLink($edito->id)}" title="{$edito->title}">{$edito->title}</a></h3>
<p>{$edito->intro|substr:0:250}</p>
<div class="readmore">
<a href="{$link->getPostEditoLink($edito->id)}" title="{$edito->title}">{l s='Lire la suite ...'}</a>
</div>
</div>
</div>

View File

@ -19,15 +19,7 @@
{if $smarty.foreach.edito.index % 2 == 0} {if $smarty.foreach.edito.index % 2 == 0}
<div class="row"> <div class="row">
{/if} {/if}
<div class="col-md-6 edito"> {include file="./edito.tpl" post=$edito column=6}
<div class="inner">
<h3><a href="{$link->getPostEditoLink($edito->id)}" title="{$edito->title}">{$edito->title}</a></h3>
<p>{$edito->intro|substr:0:250}</p>
<div class="readmore">
<a href="{$link->getPostEditoLink($edito->id)}" title="{$edito->title}">{l s='Lire la suite ...'}</a>
</div>
</div>
</div>
{if $smarty.foreach.edito.index % 2 == 1} {if $smarty.foreach.edito.index % 2 == 1}
</div> </div>
{/if} {/if}

View File

@ -11,21 +11,7 @@
{/if} {/if}
<div class="container"> <div class="container">
<h1> <h1>
{l s='Search'}&nbsp; {l s='Search'}
{if $nbProducts > 0}
<span class="lighter">
"{if isset($search_query) && $search_query}{$search_query|escape:'html':'UTF-8'}{elseif $search_tag}{$search_tag|escape:'html':'UTF-8'}{elseif $ref}{$ref|escape:'html':'UTF-8'}{/if}"
</span>
{/if}
{if isset($instant_search) && $instant_search}
<a href="#" class="close">
{l s='Return to the previous page'}
</a>
{else}
<span class="heading-counter">
{if $nbProducts == 1}{l s='%d result has been found.' sprintf=$nbProducts|intval}{else}{l s='%d results have been found.' sprintf=$nbProducts|intval}{/if}
</span>
{/if}
</h1> </h1>
</div> </div>
</header> </header>
@ -33,16 +19,36 @@
{include file="$tpl_dir./errors.tpl"} {include file="$tpl_dir./errors.tpl"}
<div class="container account"> <div class="container account">
{if !$nbProducts}
<p class="alert alert-warning"> {if $posts}
{if isset($search_query) && $search_query} <h3 class="subtitle">{l s='Articles'}</h3>
{l s='No results were found for your search'}&nbsp;"{if isset($search_query)}{$search_query|escape:'html':'UTF-8'}{/if}" <div class="row">
{elseif isset($search_tag) && $search_tag} {foreach from=$posts item=post key=key}
{l s='No results were found for your search'}&nbsp;"{$search_tag|escape:'html':'UTF-8'}" <div class="col-md-4 col-sm-4">
{else} {include file="./post_img.tpl" post=$post}
{l s='Please enter a search keyword'} </div>
{/foreach}
</div>
<div class="separator"></div>
{/if} {/if}
</p>
{if $editos}
<h3 class="subtitle">{l s='Editos'}</h3>
<div class="row">
{foreach from=$editos item=edito name=edito}
{if $smarty.foreach.edito.index % 4 == 0}
<div class="row">
{/if}
{include file="./edito.tpl" post=$edito column=3}
{if $smarty.foreach.edito.index % 4 == 3}
</div>
{/if}
{/foreach}
</div>
<div class="separator"></div>
{/if}
{if !$nbProducts}
{else} {else}
{if isset($instant_search) && $instant_search} {if isset($instant_search) && $instant_search}
<p class="alert alert-info"> <p class="alert alert-info">
@ -51,9 +57,9 @@
{/if} {/if}
<div class="row"> <div class="row">
<div class="col-md-4 col-sm-6 col-xs-6 col-xxs-12 pull-right"> <div class="col-md-4 col-sm-6 col-xs-6 col-xxs-12 pull-right">
<div class="form-group"> <!-- <div class="form-group">
{include file="$tpl_dir./product-sort.tpl"} {include file="$tpl_dir./product-sort.tpl"}
</div> </div> -->
{if !isset($instant_search) || (isset($instant_search) && !$instant_search)} {if !isset($instant_search) || (isset($instant_search) && !$instant_search)}
{include file="./nbr-product-page.tpl"} {include file="./nbr-product-page.tpl"}
{/if} {/if}