jacoz / doctrine-query-builder-from-request
This package is abandoned and no longer maintained.
No replacement package was suggested.
Transform a request to a doctrine query
dev-master
2018-01-29 11:21 UTC
Requires
- php: >=5.4.0
- doctrine/orm: ~2.2,>=2.2.3
- symfony/http-foundation: ~2.6
Requires (Dev)
- phpunit/phpunit: ~4.7
This package is not auto-updated.
Last update: 2018-12-29 20:43:24 UTC
README
An handy query system :)
Requirements:
- PHP >= 5.4
- Symfony HTTP Foundation > 2.6
- Doctrine ORM > 2.2.3
Installation:
With Composer:
{ "require": { "jacoz/doctrine-query-builder-from-request": "dev-master" } }
Parameters:
Parameter | Type | Valid values | Description | Default value |
---|---|---|---|---|
count |
boolean |
true , false |
Specifies if the query should return the number of elements or a set of records | false |
select |
array |
- | A list of fields to select | * |
params |
object |
- | A key-value object of search parameters | {} |
boolStrategy |
string |
AND , OR |
Specifies the default bool strategy | AND |
joins |
object |
- | A key-value object of relationship(s) and alias | null |
sorting |
object |
- | A key-value object of field and direction | null |
limit |
integer |
Number | Max number of results | null |
offset |
integer |
Number | Starting offset | null |
Usage:
Your controller could be something like:
<?php namespace Acme\MainBundle\Controller; use Jacoz\Doctrine\ORM\QueryBuilderFromRequest\QueryBuilder; use Symfony\Bundle\FrameworkBundle\Controller\Controller; use Symfony\Component\HttpFoundation\JsonResponse; use Symfony\Component\HttpFoundation\Request; class DefaultController extends Controller { public function indexAction(Request $request) { $repository = $this->getDoctrine()->getManager()->getRepository('AcmeMainBundle:Person'); $qb = new QueryBuilder($repository, $request); $results = $qb->getResult(); return new JsonResponse($results); } }
Query example:
{ "boolStrategy": "OR", "count": false, "select": [ "id", "name", ["c.name", "city"] ], "params": { "c.id": [ 1, 2 ], "height": "> 175", "birthday": { "type": "date", "from": "1980-01-01", "to": "1989-12-31" }, "salary": { "type": "numeric", "from": 50000, "to": 70000 }, "x": { "type": "instance_of", "class": "Acme\\DemoBundle\\Entity\\Employee" } }, "joins": { "city": "c" }, "sorting": { "c.name": "ASC", "name": "ASC" }, "limit": 100, "offset": 0 }