2017 © Pedro Peláez
 

library query-builder-repository-generator-bundle

Generate filters for queryBuilder in a repository

image

tbn/query-builder-repository-generator-bundle

Generate filters for queryBuilder in a repository

  • Monday, June 26, 2017
  • by thomasbeaujean
  • Repository
  • 2 Watchers
  • 1 Stars
  • 2,022 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 2 Forks
  • 0 Open issues
  • 7 Versions
  • 5 % Grown

The README.md

QueryBuilderRepositoryGeneratorBundle

The QueryBuilderRepositoryGeneratorBundle generates Repositories in the repository folders, (*1)

The functions allow to filter on the columns of the entity with a query builder., (*2)

See the create queries section for an example., (*3)

Installation

Import the bundle using composer

composer require --dev "tbn/query-builder-repository-generator-bundle"

Import the bundle in your AppKernel

if ('dev' === $this->getEnvironment()) {
    $bundles[] = new Tbn\QueryBuilderRepositoryGeneratorBundle\QueryBuilderRepositoryGeneratorBundle();
}

Configuration

Mandatory configuration

Add the bundles you want:, (*4)

    query_builder_repository_generator:
        bundles:
            - "<<YourBundleName>>"

Those bundles will have the repositories generated in the Repository directory of the bundles. Check the content by yourself., (*5)

Optional configuration

    query_builder_repository_generator:
        templates:
            top_repository: "QueryBuilderRepositoryGeneratorBundle:Generator:TopRepositoryTemplate.html.twig"
            column: "QueryBuilderRepositoryGeneratorBundle:Generator:ColumnTemplate.html.twig"
            association: "QueryBuilderRepositoryGeneratorBundle:Generator:AssociationTemplate.html.twig"
            bottom_repository: "QueryBuilderRepositoryGeneratorBundle:Generator:BottomRepositoryTemplate.html.twig"
    mapping:
        - 'AppBundle\Entity\Member':
            querybuilder_name: 'memberEntity' # the name of the entity used in the queryBuilder

The repository extends

You can specify a class to extends for each entity., (*6)

    repositories_extensions:
        - "AcmeBundle\Entity\Item": #the entity class
            extension_class: "\\Gedmo\\Tree\\Entity\\Repository\\MaterializedPathRepository" #the class to extends

The templates used by the generator can be set with these configurations., (*7)

    top_repository => The beginning of the repository file
    column => The template used for each column
    extra_column => A custom template of your choice
    bottom_repository => The end of the repository file

The extra_column template have the following variables:, (*8)

    'entity' => $tableName,
    'entityDql' => lcfirst($tableName),
    'column' => ucfirst($columnName),
    'columnDql' => $columnName

Use generated repositories

In your Entity Repository, extends the generated repository., (*9)

    class UserRepository extends UserRepositoryBase

Your repository has now some predefined function like "filterById", "filterInId" for all the columns., (*10)

Create queries

Example:, (*11)

    $qb = $this->createQueryBuilder('document');

    //filter on current user (where XX = YY)
   DocumentRepository::filterByUser($qb, $user);
   //filter on the extension list (where xxx IN () )
   DocumentRepository::filterInExtension($qb, $extensionList);

   //Join the tag entity
   $qb->join('document.tags', 'tag');
   //filter on the tag entity
   TagRepository::filterById($qb, $tagButton);

Regenerate files

Run the command:, (*12)

php app/console qbrg:generate

The Versions

26/06 2017

dev-master

9999999-dev

Generate filters for queryBuilder in a repository

  Sources   Download

04/04 2017

v1.0.5

1.0.5.0

Generate filters for queryBuilder in a repository

  Sources   Download

13/10 2015

v1.0.4

1.0.4.0

Generate filters for queryBuilder in a repository

  Sources   Download

15/04 2015

V1.0.3

1.0.3.0

Generate filters for queryBuilder in a repository

  Sources   Download

21/03 2015

v1.0.2

1.0.2.0

Generate filters for queryBuilder in a repository

  Sources   Download

20/03 2015

v1.0.1

1.0.1.0

Generate filters for queryBuilder in a repository

  Sources   Download

19/03 2015

v1.0.0

1.0.0.0

Generate filters for queryBuilder in a repository

  Sources   Download