Coder Social home page Coder Social logo

filtersorterbundle's Introduction

FilterSorterBundle

This Symfony bundle aims to provide structurized filtering and sorting with usage of the specification pattern (see doctrine-specification). It was design to use in the api applications but it could be also used with standard web apps.

Provides feature like:
  • FilterQueryManager - it collects all filter services and gives you queryBuilder with applied specifications.
  • FilterParamConverter - provide filter object by the data in query string
  • SortParamConverter - provide sort object by the data in query string

Build Status

Installation

1. Install via composer:
composer require bartlomiejbeta/filter-sorter-bundle
2. Register bundle in AppKernel:
public function registerBundles()
{
    $bundles = array(
        // ...
        new BartB\FilterSorterBundle\FilterSorterBundle(),
    );
}

Usage

I assume that you already have entities, and so one.

1. Change parent of the entities to AbstractEntitySpecificationAwareRepository:

example:

class CarRepository extends AbstractEntitySpecificationAwareRepository
{
}
2. Add specifications (example)
3. Add Collection filter (example)
4. Add Sort Enum (example)
5. Build and register your first service adapter (adapter example, register adapter example)
$carCollectionFilter = (new CarCollectionFilter())->setGearboxType('automatic');

$carSorter     = new CarSort(CarSort::FUEL_TYPE);
$sortDirection = new SortDirectionType(SortDirectionType::DESC);
		
/** @var FilterQueryManager $filterQueryManager */
$filterQueryManager = $this->filterQueryManager;
$carRepository      = $this->repostioryCar;
$sort 	            = new Sort($sortDirection, $carSorter);
$limit              = new Limit(1);

$basicRepositoryDTO = new BasicRepositoryDTO($carRepository);
$queryAttributesDTO = new QueryAttributesDTO($carCollectionFilter, $sort, $limit);

$queryBuilder = $filterQueryManager->getQueryBuilder($basicRepositoryDTO, $queryAttributesDTO);
$query        = $queryBuilder->getQuery();
$result       = $query->execute();

TODO: Upgrade example to symfony 3.4 Also I prepared full stand alone example

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.