mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-08-24 08:33:49 +00:00
add search possibility throught all bundles, and remove deps between mainbundle and person bundle.
refs #223
This commit is contained in:
38
Search/AbstractSearch.php
Normal file
38
Search/AbstractSearch.php
Normal file
@@ -0,0 +1,38 @@
|
||||
<?php
|
||||
|
||||
|
||||
/*
|
||||
*
|
||||
* Copyright (C) 2014, Champs Libres Cooperative SCRLFS, <http://www.champs-libres.coop>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
namespace Chill\MainBundle\Search;
|
||||
|
||||
use Chill\MainBundle\Search\SearchInterface;
|
||||
|
||||
/**
|
||||
* This class implements abstract search with most common responses.
|
||||
*
|
||||
* you should use this abstract class instead of SearchInterface : if the signature of
|
||||
* search interface change, the generic method will be implemented here.
|
||||
*
|
||||
* @author Julien Fastré <julien.fastre@champs-libres.coop>
|
||||
*
|
||||
*/
|
||||
abstract class AbstractSearch implements SearchInterface
|
||||
{
|
||||
|
||||
}
|
76
Search/SearchInterface.php
Normal file
76
Search/SearchInterface.php
Normal file
@@ -0,0 +1,76 @@
|
||||
<?php
|
||||
|
||||
|
||||
/*
|
||||
*
|
||||
* Copyright (C) 2014, Champs Libres Cooperative SCRLFS, <http://www.champs-libres.coop>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
namespace Chill\MainBundle\Search;
|
||||
|
||||
/**
|
||||
* This interface must be implemented on services which provide search results.
|
||||
*
|
||||
* @todo : write doc and add a link to documentation
|
||||
*
|
||||
* @author Julien Fastré <julien.fastre@champs-libres.coop>
|
||||
*
|
||||
*/
|
||||
interface SearchInterface #-> good name ?
|
||||
{
|
||||
/*
|
||||
* return the result in a html string. The string will be inclued (as raw)
|
||||
* into a global view.
|
||||
*
|
||||
* The global view may be :
|
||||
* {% for result as resultsFromDifferentSearchInterface %}
|
||||
* {{ result|raw }}
|
||||
* {% endfor %}
|
||||
*
|
||||
* @param string $pattern the string to search
|
||||
* @param int $start the first result (for pagination)
|
||||
* @param int $limit the number of result (for pagination)
|
||||
* @param array $option the options, specific for each search
|
||||
* @return string, an HTML string
|
||||
*/
|
||||
public function renderResult($pattern, $start=0, $limit=50, array $options = array());
|
||||
|
||||
/*
|
||||
* we may desactive the search interface by default. in this case,
|
||||
* the search will be launch and rendered only with "advanced search"
|
||||
*
|
||||
* this may be activated/desactived from bundle definition in config.yml
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function isActiveByDefault();
|
||||
|
||||
/*
|
||||
* a string used in advanced search to activate the search
|
||||
*
|
||||
* @return string a string which will be translated by twig
|
||||
*/
|
||||
public function getLabel();
|
||||
|
||||
/*
|
||||
* the order in which the results will appears in the global view
|
||||
*
|
||||
* (this may be eventually defined in config.yml)
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function getOrder();
|
||||
}
|
58
Search/SearchProvider.php
Normal file
58
Search/SearchProvider.php
Normal file
@@ -0,0 +1,58 @@
|
||||
<?php
|
||||
namespace Chill\MainBundle\Search;
|
||||
|
||||
use Chill\MainBundle\Search\SearchInterface;
|
||||
|
||||
/**
|
||||
* a service which gather all search services defined into the bundles
|
||||
* installed into the app.
|
||||
* the service is callable from the container with
|
||||
* $container->get('chill.main.search_provider')
|
||||
*/
|
||||
class SearchProvider
|
||||
{
|
||||
/**
|
||||
*
|
||||
* @var SearchInterface[]
|
||||
*/
|
||||
private $searchServices = array();
|
||||
|
||||
/*
|
||||
* return search services in an array, ordered by
|
||||
* the order key (defined in service definition)
|
||||
* the conflicts in keys (twice the same order) are resolved
|
||||
* within the compiler : the function will preserve all services
|
||||
* defined (if two services have the same order, the will increment
|
||||
* the order of the second one.
|
||||
*
|
||||
* @return SearchInterface[], with an int as array key
|
||||
*/
|
||||
public function getByOrder()
|
||||
{
|
||||
//sort the array
|
||||
uasort($this->searchServices, function(SearchInterface $a, SearchInterface $b) {
|
||||
if ($a->getOrder() == $b->getOrder()) {
|
||||
return 0;
|
||||
}
|
||||
return ($a->getOrder() < $b->getOrder()) ? -1 : 1;
|
||||
});
|
||||
|
||||
return $this->searchServices;
|
||||
}
|
||||
|
||||
/*
|
||||
* return search services with a specific name, defined in service
|
||||
* definition.
|
||||
*
|
||||
* @return SearchInterface
|
||||
*/
|
||||
public function getByName($name)
|
||||
{
|
||||
return $this->searchServices[$name];
|
||||
}
|
||||
|
||||
public function addSearchService(SearchInterface $service, $name)
|
||||
{
|
||||
$this->searchServices[$name] = $service;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user