mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-08-24 08:33:49 +00:00
@@ -124,20 +124,55 @@ class SearchProvider
|
||||
* @param number $start
|
||||
* @param number $limit
|
||||
* @return array of html results
|
||||
* @throws UnknowSearchDomainException if the domain is unknow
|
||||
*/
|
||||
public function getResults($pattern, $start = 0, $limit = 50)
|
||||
public function getSearchResults($pattern, $start = 0, $limit = 50)
|
||||
{
|
||||
$terms = $this->parse($pattern);
|
||||
$results = array();
|
||||
|
||||
foreach ($this->searchServices as $service) {
|
||||
if ($service->supports($terms['_domain'])) {
|
||||
$results[] = $service->renderResult($terms, $start, $limit);
|
||||
|
||||
//sort searchServices by order
|
||||
$sortedSearchServices = array();
|
||||
foreach($this->searchServices as $service) {
|
||||
$sortedSearchServices[$service->getOrder()] = $service;
|
||||
}
|
||||
|
||||
if ($terms['_domain'] !== NULL) {
|
||||
foreach ($sortedSearchServices as $service) {
|
||||
if ($service->supports($terms['_domain'])) {
|
||||
$results[] = $service->renderResult($terms, $start, $limit);
|
||||
}
|
||||
}
|
||||
|
||||
if (count($results) === 0) {
|
||||
throw new UnknowSearchDomainException($terms['_domain']);
|
||||
}
|
||||
} else { // no domain provided, we use default search
|
||||
foreach($sortedSearchServices as $service) {
|
||||
if ($service->isActiveByDefault()) {
|
||||
$results[] = $service->renderResult($terms, $start, $limit);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//sort array
|
||||
ksort($results);
|
||||
|
||||
return $results;
|
||||
}
|
||||
|
||||
public function getResultByName($pattern, $name, $start = 0, $limit = 50)
|
||||
{
|
||||
$terms = $this->parse($pattern);
|
||||
$search = $this->getByName($name);
|
||||
|
||||
if ($terms['_domain'] !== NULL && !$search->supports($terms['_domain']))
|
||||
{
|
||||
throw new ParsingException("The domain is not supported for the search name");
|
||||
}
|
||||
|
||||
return $search->renderResult($terms, $start, $limit);
|
||||
}
|
||||
|
||||
/**
|
||||
* return search services with a specific name, defined in service
|
||||
@@ -149,7 +184,7 @@ class SearchProvider
|
||||
public function getByName($name)
|
||||
{
|
||||
if (isset($this->searchServices[$name])) {
|
||||
return $this->searchServices;
|
||||
return $this->searchServices[$name];
|
||||
} else {
|
||||
throw new UnknowSearchNameException($name);
|
||||
}
|
||||
|
@@ -25,11 +25,19 @@ namespace Chill\MainBundle\Search;
|
||||
*
|
||||
* @author Julien Fastré <julien.fastre@champs-libres.coop>
|
||||
*/
|
||||
class UnknowSearchNameException extends \Exception
|
||||
class UnknowSearchDomainException extends \Exception
|
||||
{
|
||||
public function __construct($name)
|
||||
|
||||
private $domain;
|
||||
|
||||
public function __construct($domain)
|
||||
{
|
||||
parent::__construct( "The module search with name $name "
|
||||
. "is not found");
|
||||
parent::__construct( "The domain $domain is not found");
|
||||
$this->domain = $domain;
|
||||
}
|
||||
|
||||
public function getDomain()
|
||||
{
|
||||
return $this->domain;
|
||||
}
|
||||
}
|
||||
|
@@ -29,7 +29,6 @@ class UnknowSearchNameException extends \Exception
|
||||
{
|
||||
public function __construct($name)
|
||||
{
|
||||
parent::__construct( "The module search with name $name "
|
||||
. "is not found");
|
||||
parent::__construct( "No module search supports with the name $name");
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user