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