Search bundle for Symfony2. Use entities, collections for search directly. Great for handling complex search forms.
$fm = $this->get('padam87_search.filter.manager');
$filter = new Filter($data, 'YourBundle:Entity', 'alias');
$qb = $fm->createQueryBuilder($filter);
$data
can be an array, an entity, or even a doctrine collection.
You can add your own converter to handle any type of data.
$fm = $this->get('padam87_search.filter.manager');
$filter1 = new Filter($data1, 'YourBundle:Entity1', 'alias1');
$filter2 = new Filter($data2, 'YourBundle:Entity2', 'alias2');
$qb = $fm->joinToQueryBuilder($filter2, $fm->createQueryBuilder($filter1), 'associationName');
'associationName'
is the name of the relation in your entity, eg 'users'
$fm = $this->get('padam87_search.filter.manager');
$filter = new Filter($data, 'YourBundle:Entity', 'alias');
$qb = $fm->createQueryBuilder($filter);
When $data
is an entity, it can have *ToMany associations. By default, the bundle assumes OR relationship between the elements of the collection. To change that, you can use the 2nd parameter of $fm->createQueryBuilder
:
$fm = $this->get('padam87_search.filter.manager');
$filter = new Filter($data, 'YourBundle:Entity', 'alias');
$qb = $fm->createQueryBuilder($filter, array(
'relationName' => 'AND'
));
$data = array(
'integerField>=' => 10
'stringFiled' => 'A*'
);
$filter = new Filter($data, 'YourBundle:Entity', 'alias');
The bundle will search for operators in the field names and values, and use the appropriate Expr.
For a nicer, and entity-compatible solution you can use the 4th parameter of the Filter to set default operators:
$filter = new Filter($data, 'YourBundle:Entity', 'alias', array(
'integerField' => '>='
));
"padam87/search-bundle": "2.0.*",
$bundles = array(
...
new Padam87\SearchBundle\Padam87SearchBundle(),
);