mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-06-07 18:44:08 +00:00
mark search service provider as private
This commit is contained in:
parent
9b4a71ef8b
commit
c74f242050
@ -4,7 +4,7 @@ namespace Chill\MainBundle;
|
||||
|
||||
use Symfony\Component\HttpKernel\Bundle\Bundle;
|
||||
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
||||
use Chill\MainBundle\DependencyInjection\SearchableServicesCompilerPass;
|
||||
use Chill\MainBundle\DependencyInjection\CompilerPass\SearchableServicesCompilerPass;
|
||||
use Chill\MainBundle\DependencyInjection\ConfigConsistencyCompilerPass;
|
||||
use Chill\MainBundle\DependencyInjection\CompilerPass\TimelineCompilerClass;
|
||||
use Chill\MainBundle\DependencyInjection\RoleProvidersCompilerPass;
|
||||
|
@ -31,15 +31,44 @@ use Chill\MainBundle\Search\SearchInterface;
|
||||
use Symfony\Component\Form\Extension\Core\Type\SubmitType;
|
||||
use Symfony\Component\Form\Extension\Core\Type\FormType;
|
||||
use Symfony\Component\HttpFoundation\JsonResponse;
|
||||
use Chill\MainBundle\Search\SearchProvider;
|
||||
use Symfony\Component\Translation\TranslatorInterface;
|
||||
use Chill\MainBundle\Pagination\PaginatorFactory;
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @author julien.fastre@champs-libres.coop
|
||||
* @author marc@champs-libres.coop
|
||||
*/
|
||||
class SearchController extends Controller
|
||||
{
|
||||
/**
|
||||
*
|
||||
* @var SearchProvider
|
||||
*/
|
||||
protected $searchProvider;
|
||||
|
||||
/**
|
||||
*
|
||||
* @var TranslatorInterface
|
||||
*/
|
||||
protected $translator;
|
||||
|
||||
/**
|
||||
*
|
||||
* @var PaginatorFactory
|
||||
*/
|
||||
protected $paginatorFactory;
|
||||
|
||||
function __construct(
|
||||
SearchProvider $searchProvider,
|
||||
TranslatorInterface $translator,
|
||||
PaginatorFactory $paginatorFactory
|
||||
) {
|
||||
$this->searchProvider = $searchProvider;
|
||||
$this->translator = $translator;
|
||||
$this->paginatorFactory = $paginatorFactory;
|
||||
}
|
||||
|
||||
|
||||
public function searchAction(Request $request, $_format)
|
||||
{
|
||||
@ -50,7 +79,7 @@ class SearchController extends Controller
|
||||
case 'html':
|
||||
return $this->render('ChillMainBundle:Search:error.html.twig',
|
||||
array(
|
||||
'message' => $this->get('translator')->trans("Your search is empty. "
|
||||
'message' => $this->translator->trans("Your search is empty. "
|
||||
. "Please provide search terms."),
|
||||
'pattern' => $pattern
|
||||
));
|
||||
@ -72,7 +101,7 @@ class SearchController extends Controller
|
||||
}
|
||||
|
||||
// no specific search selected. Rendering result in "preview" mode
|
||||
$results = $this->get('chill.main.search_provider')
|
||||
$results = $this->searchProvider
|
||||
->getSearchResults(
|
||||
$pattern,
|
||||
0,
|
||||
@ -81,17 +110,12 @@ class SearchController extends Controller
|
||||
);
|
||||
} else {
|
||||
// we want search on a specific search provider. Display full results.
|
||||
|
||||
// create a paginator to get the startPage and stopPage
|
||||
/* @var $paginatorFactory \Chill\MainBundle\Pagination\PaginatorFactory */
|
||||
$paginatorFactory = $this->get('chill_main.paginator_factory');
|
||||
|
||||
$results = [$this->get('chill.main.search_provider')
|
||||
$results = [$this->searchProvider
|
||||
->getResultByName(
|
||||
$pattern,
|
||||
$name,
|
||||
$paginatorFactory->getCurrentPageFirstItemNumber(),
|
||||
$paginatorFactory->getCurrentItemsPerPage(),
|
||||
$this->paginatorFactory->getCurrentPageFirstItemNumber(),
|
||||
$this->paginatorFactory->getCurrentItemsPerPage(),
|
||||
array(
|
||||
SearchInterface::SEARCH_PREVIEW_OPTION => false,
|
||||
SearchInterface::REQUEST_QUERY_PARAMETERS => $request
|
||||
@ -116,8 +140,8 @@ class SearchController extends Controller
|
||||
} catch (ParsingException $ex) {
|
||||
return $this->render('ChillMainBundle:Search:error.html.twig',
|
||||
array(
|
||||
"message" => $this->get('translator')->trans('Invalid terms').
|
||||
": ".$this->get('translator')->trans($ex->getMessage()),
|
||||
"message" => $this->translator->trans('Invalid terms').
|
||||
": ".$this->translator->trans($ex->getMessage()),
|
||||
'pattern' => $pattern
|
||||
));
|
||||
}
|
||||
@ -131,7 +155,7 @@ class SearchController extends Controller
|
||||
public function advancedSearchListAction(Request $request)
|
||||
{
|
||||
/* @var $variable Chill\MainBundle\Search\SearchProvider */
|
||||
$searchProvider = $this->get('chill.main.search_provider');
|
||||
$searchProvider = $this->searchProvider;
|
||||
$advancedSearchProviders = $searchProvider
|
||||
->getHasAdvancedFormSearchServices();
|
||||
|
||||
@ -150,9 +174,9 @@ class SearchController extends Controller
|
||||
{
|
||||
try {
|
||||
/* @var $variable Chill\MainBundle\Search\SearchProvider */
|
||||
$searchProvider = $this->get('chill.main.search_provider');
|
||||
$searchProvider = $this->searchProvider;
|
||||
/* @var $variable Chill\MainBundle\Search\HasAdvancedSearchFormInterface */
|
||||
$search = $this->get('chill.main.search_provider')
|
||||
$search = $this->searchProvider
|
||||
->getHasAdvancedFormByName($name);
|
||||
|
||||
} catch (\Chill\MainBundle\Search\UnknowSearchNameException $e) {
|
||||
@ -171,7 +195,7 @@ class SearchController extends Controller
|
||||
$form->handleRequest($request);
|
||||
|
||||
if ($form->isValid()) {
|
||||
$pattern = $this->get('chill.main.search_provider')
|
||||
$pattern = $this->searchProvider
|
||||
->getHasAdvancedFormByName($name)
|
||||
->convertFormDataToQuery($form->getData());
|
||||
|
||||
@ -194,13 +218,13 @@ class SearchController extends Controller
|
||||
$builder = $this
|
||||
->get('form.factory')
|
||||
->createNamedBuilder(
|
||||
null,
|
||||
null,
|
||||
FormType::class,
|
||||
$data,
|
||||
[ 'method' => Request::METHOD_POST ]
|
||||
);
|
||||
|
||||
$this->get('chill.main.search_provider')
|
||||
$this->searchProvider
|
||||
->getHasAdvancedFormByName($name)
|
||||
->buildForm($builder)
|
||||
;
|
||||
|
@ -121,6 +121,7 @@ class ChillMainExtension extends Extension implements PrependExtensionInterface,
|
||||
$loader->load('services/cache.yml');
|
||||
$loader->load('services/templating.yml');
|
||||
$loader->load('services/timeline.yml');
|
||||
$loader->load('services/search.yml');
|
||||
|
||||
$this->configureCruds($container, $config['cruds'], $loader);
|
||||
}
|
||||
|
@ -18,7 +18,7 @@
|
||||
* 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\DependencyInjection;
|
||||
namespace Chill\MainBundle\DependencyInjection\CompilerPass;
|
||||
|
||||
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
||||
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
|
||||
@ -33,13 +33,13 @@ class SearchableServicesCompilerPass implements CompilerPassInterface
|
||||
*/
|
||||
public function process(ContainerBuilder $container)
|
||||
{
|
||||
if (!$container->hasDefinition('chill.main.search_provider')) {
|
||||
throw new \LogicException('service chill.main.search_provider '
|
||||
if (!$container->hasDefinition('chill_main.search_provider')) {
|
||||
throw new \LogicException('service chill_main.search_provider '
|
||||
. 'is not defined.');
|
||||
}
|
||||
|
||||
$definition = $container->getDefinition(
|
||||
'chill.main.search_provider'
|
||||
'chill_main.search_provider'
|
||||
);
|
||||
|
||||
$taggedServices = $container->findTaggedServiceIds(
|
@ -37,10 +37,6 @@ services:
|
||||
arguments:
|
||||
- "@doctrine.orm.entity_manager"
|
||||
|
||||
chill.main.search_provider:
|
||||
class: Chill\MainBundle\Search\SearchProvider
|
||||
public: true
|
||||
|
||||
chill.main.validator.role_scope_scope_presence:
|
||||
class: Chill\MainBundle\Validation\Validator\RoleScopeScopePresence
|
||||
arguments:
|
||||
|
@ -10,3 +10,10 @@ services:
|
||||
arguments:
|
||||
$chillLogger: '@monolog.logger.chill'
|
||||
tags: ['controller.service_arguments']
|
||||
|
||||
Chill\MainBundle\Controller\SearchController:
|
||||
arguments:
|
||||
$searchProvider: '@chill_main.search_provider'
|
||||
$translator: '@Symfony\Component\Translation\TranslatorInterface'
|
||||
$paginatorFactory: '@Chill\MainBundle\Pagination\PaginatorFactory'
|
||||
tags: ['controller.service_arguments']
|
||||
|
@ -123,7 +123,7 @@ services:
|
||||
chill.main.form.advanced_search_type:
|
||||
class: Chill\MainBundle\Form\AdvancedSearchType
|
||||
arguments:
|
||||
- "@chill.main.search_provider"
|
||||
- "@chill_main.search_provider"
|
||||
tags:
|
||||
- { name: form.type }
|
||||
|
||||
|
3
Resources/config/services/search.yml
Normal file
3
Resources/config/services/search.yml
Normal file
@ -0,0 +1,3 @@
|
||||
services:
|
||||
chill_main.search_provider:
|
||||
class: Chill\MainBundle\Search\SearchProvider
|
@ -9,7 +9,7 @@ use Chill\MainBundle\Search\HasAdvancedSearchFormInterface;
|
||||
* 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')
|
||||
* $container->get('chill_main.search_provider')
|
||||
*
|
||||
* the syntax for search string is :
|
||||
* - domain, which begin with `@`. Example: `@person`. Restrict the search to some
|
||||
|
Loading…
x
Reference in New Issue
Block a user