implement search on content loop.

This commit is contained in:
Manuel Raynaud
2014-06-05 13:24:53 +02:00
parent 57cf2d1a10
commit a4e28e5561
2 changed files with 63 additions and 2 deletions

View File

@@ -18,6 +18,7 @@ use Thelia\Core\Template\Element\LoopResult;
use Thelia\Core\Template\Element\LoopResultRow;
use Thelia\Core\Template\Element\PropelSearchLoopInterface;
use Thelia\Core\Template\Element\SearchLoopInterface;
use Thelia\Core\Template\Loop\Argument\ArgumentCollection;
use Thelia\Core\Template\Loop\Argument\Argument;
@@ -37,7 +38,7 @@ use Thelia\Type\BooleanOrBothType;
* @package Thelia\Core\Template\Loop
* @author Etienne Roudeix <eroudeix@openstudio.fr>
*/
class Content extends BaseI18nLoop implements PropelSearchLoopInterface
class Content extends BaseI18nLoop implements PropelSearchLoopInterface, SearchLoopInterface
{
protected $timestampable = true;
protected $versionable = true;
@@ -82,6 +83,23 @@ class Content extends BaseI18nLoop implements PropelSearchLoopInterface
);
}
/**
* @return array of available field to search in
*/
public function getSearchIn()
{
return [
"title"
];
}
public function doSearch(&$search, $searchTerm, $searchIn, $searchCriteria)
{
$search->_and();
$search->where("CASE WHEN NOT ISNULL(`requested_locale_i18n`.ID) THEN `requested_locale_i18n`.`TITLE` ELSE `default_locale_i18n`.`TITLE` END ".$searchCriteria." ?", $searchTerm, \PDO::PARAM_STR);
}
public function buildModelCriteria()
{

View File

@@ -290,7 +290,7 @@
<td class="actions">
<div class="btn-group">
{loop type="auth" name="can_change" role="ADMIN" resource="admin.folder" access="UPDATE"}
<a class="btn btn-default btn-xs" title="{intl l='Edit this product'}" href="{url path='/admin/products/update' product_id=$ID}"><i class="glyphicon glyphicon-edit"></i></a>
<a class="btn btn-default btn-xs" title="{intl l='Edit this product'}" href="{url path="/admin/folders/update/{$ID}"}"><i class="glyphicon glyphicon-edit"></i></a>
{/loop}
</div>
</td>
@@ -303,6 +303,49 @@
</div>
{* end folder search *}
{* content search *}
<div class="general-block-decorator">
<div class="table-responsive">
<table class="table table-striped table-condensed table-left-aligned">
<caption class="clearfix">
{intl l='Content'}
</caption>
<thead>
<tr>
<th>{intl l="ID"}</th>
<th></th>
<th>{intl l="Content title"}</th>
<th class="actions">{intl l="Actions"}</th>
</tr>
</thead>
<tbody>
{loop type="content" name="content-search" visible="*" search_mode="sentence" search_term=trim($smarty.get.search_term) search_in="title"}
<tr>
<td>{$ID}</td>
<td></td>
<td class="object-title"><a href="{url path="/admin/content/update/{$ID}"}">{$TITLE}</a></td>
<td class="actions">
<div class="btn-group">
{loop type="auth" name="can_change" role="ADMIN" resource="admin.content" access="UPDATE"}
<a class="btn btn-default btn-xs" title="{intl l='Edit this product'}" href="{url path="/admin/content/update/{$ID}"}"><i class="glyphicon glyphicon-edit"></i></a>
{/loop}
</div>
</td>
</tr>
{/loop}
</tbody>
</table>
</div>
</div>
{* end content search *}
</div>
</div>