Developed with love by KnpLabs Hire us for your project!
24

SearchBundle

by Padam87

Search bundle for Symfony2. Use entities, collections for search directly.

Build Status
Coverage Status
Scrutinizer Quality Score
SensioLabsInsight
Latest Stable Version
Total Downloads
Latest Unstable Version
License

Search Bundle

Search bundle for Symfony2. Use entities, collections for search directly. Great for handling complex search forms.

1. Examples

1.1 Simple

$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.

1.2 Joins

$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'

1.3 Collection valued associations

$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'
));

1.4 Operators

$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' => '>='
));

2. Installation

2.1. Composer

"padam87/search-bundle": "2.0.*",

2.2. AppKernel

$bundles = array(
    ...
    new Padam87\SearchBundle\Padam87SearchBundle(),
);
padam87_search:       []
  • Fixed token generator
    By Padam87, 3 years ago
  • Added phpunit dev dependency
    By Padam87, 3 years ago
  • More badges
    By Padam87, 3 years ago
  • Filter entity name validation
    By Padam87, 3 years ago
  • Updated changelog
    By Padam87, 3 years ago
  • Readme 2.0
    By Padam87, 3 years ago
  • Fix Converter code duplication
    By Padam87, 3 years ago
  • Fixed SLInsight issues^2
    By Padam87, 3 years ago
  • Fixed SLInsight issues
    By Padam87, 3 years ago
  • Added Sensio badge, Removed Bitdeli
    By Padam87, 3 years ago
  • Fixed service problem
    By Padam87, 3 years ago
  • Big refactor for 2.0
    By Padam87, 3 years ago
  • Added Symfony 2.4 to travis
    By Padam87, 3 years ago
  • Add a Bitdeli badge to README
    By bitdeli-chef, 3 years ago
  • Merge pull request #4 from bitdeli-chef/master
    By Padam87, 3 years ago
  • Updated changelog
    By Padam87, 3 years ago
  • Tests for SearchableRepository
    By Padam87, 3 years ago
  • Refactored SearchableRepository
    By Padam87, 3 years ago
  • Fixed SearchableRepository
    By Padam87, 3 years ago
  • Fixed CS
    By Padam87, 3 years ago
  • Fixed CS and typos
    By Padam87, 3 years ago
  • Update README.md
    By Padam87, 3 years ago
  • Scrutinizer
    By Padam87, 3 years ago
  • Improved join tests
    By Padam87, 3 years ago
  • Updated changelog
    By Padam87, 3 years ago
  • Added tests operators
    By Padam87, 3 years ago
  • Fixed default operator bug
    By Padam87, 3 years ago
  • Fixed IS NULL and IS NOT NULL operator issues
    By Padam87, 3 years ago
  • Added test for joined filters
    By Padam87, 3 years ago
  • Add idea folder to gitignore
    By Padam87, 3 years ago