2017 © Pedro Peláez
 

symfony-bundle multi-search-bundle

Symfony bundle for Multi Criteria Search for doctrine entities using Form or Service.

image

petkopara/multi-search-bundle

Symfony bundle for Multi Criteria Search for doctrine entities using Form or Service.

  • Monday, April 9, 2018
  • by petkopara
  • Repository
  • 3 Watchers
  • 6 Stars
  • 18,522 Installations
  • PHP
  • 3 Dependents
  • 0 Suggesters
  • 1 Forks
  • 6 Open issues
  • 2 Versions
  • 18 % Grown

The README.md

MultiSearchBundle

This bundle provides basic service and form type for Multi Search in Doctrine., (*1)

Build Status Scrutinizer Code Quality SensioLabsInsight Latest Stable Total Downloads, (*2)

Description

Search in all of entity columns by given search term. In response returns Doctrine\ORM\QueryBuilder containing the multiple search criteria. The searched columns can be specified., (*3)

Installation

Using composer

composer require petkopara/multi-search-bundle

Add it to the AppKernel.php class:, (*4)

new Petkopara\MultiSearchBundle\PetkoparaMultiSearchBundle(),

Usage

Service

You can directly use the service and to apply the multi search to any doctrine query builder., (*5)

public function indexAction(Request $request)
{
    $search = $request->get('search');
    $em = $this->getDoctrine()->getManager();

    $qb = $em->getRepository('AppBundle:Post')->createQueryBuilder('e');
    $qb = $this->get('petkopara_multi_search.builder')->searchEntity($qb, 'AppBundle:Post', $search);
   //$qb = $this->get('petkopara_multi_search.builder')->searchEntity($qb, 'AppBundle:Post', $search, array('name', 'content'), 'wildcard');

    ..
}

Form

Create your form type and include the multiSearchType in the buildForm function:, (*6)

use Petkopara\MultiSearchBundle\Form\Type\MultiSearchType;

public function buildForm(FormBuilderInterface $builder, array $options)
{
    $builder
            ->add('search', MultiSearchType::class, array(
                'class' => 'AppBundle:Post', //required
                'search_fields' => array( //optional, if it's empty it will search in the all entity columns
                    'name',
                    'content'
                 ), 
                 'search_comparison_type' => 'wildcard' //optional, what type of comparison to applied ('wildcard','starts_with', 'ends_with', 'equals')

            ))
    ;
}

In the controller add call to the multi search service:, (*7)

public function indexAction(Request $request)
{
    $search = $request->get('search');
    $em = $this->getDoctrine()->getManager();
    $queryBuilder = $em->getRepository('AppBundle:Post')->createQueryBuilder('e');
    $filterForm = $this->createForm('AppBundle\Form\PostFilterType');

    // Bind values from the request
    $filterForm->handleRequest($request);

    if ($filterForm->isValid()) {
        // Build the query from the given form object
        $queryBuilder = $this->get('petkopara_multi_search.builder')->searchForm($queryBuilder, $filterForm->get('search'));
    }

    ..
}

Render your form in the view, (*8)

{{ form_rest(filterForm) }}

Available Options

The provided type has 2 options:, (*9)

  • search_fields - array of the entity columns that will be added in the search. If it's not set then will search in all columns
  • search_comparison_type - how to compare the search term., (*10)

    • wildcard - it's equivalent to the %search% like search., (*11)

    • equals - like operator without wildcards. Wildcards still can be used with equals if the search term contains *., (*12)

    • starts_with - it's equivalent to the %search like search., (*13)

    • ends_with - it's equivalent to the search% like search., (*14)

These parameters can be applyed to the service as well as 4th and 5th parameter to searchEntity() method, (*15)

Author

Petko Petkov - petkopara@gmail.com, (*16)

License

MultiSearchBundle is licensed under the MIT License., (*17)

The Versions

09/04 2018

dev-master

9999999-dev https://github.com/petkopara/PetkoparaMultiSearchBundle

Symfony bundle for Multi Criteria Search for doctrine entities using Form or Service.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Petko Petkov

doctrine symfony3 query builder criteria multi-search

24/10 2016

v1.0.0

1.0.0.0 https://github.com/petkopara/PetkoparaMultiSearchBundle

Symfony3 bundle that provides multi search doctrine query builder for forms and entities .

  Sources   Download

MIT

The Requires

 

The Development Requires

by Petko Petkov

doctrine symfony3 query-builder multi-search