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()
{