From 9c209cdb02a3fa0b7bf438f938f26ac2489c45a5 Mon Sep 17 00:00:00 2001 From: Pedro Teixeira Date: Mon, 18 Aug 2014 18:18:50 +0200 Subject: [PATCH] Use oficial Doctrine Paginator and HavingNumberRange filter --- Grid/Filter/Operator/HavingNumberRange.php | 49 ++++++++++++++++++++++ Grid/GridAbstract.php | 4 +- README.md | 5 +-- composer.json | 3 +- 4 files changed, 54 insertions(+), 7 deletions(-) create mode 100644 Grid/Filter/Operator/HavingNumberRange.php diff --git a/Grid/Filter/Operator/HavingNumberRange.php b/Grid/Filter/Operator/HavingNumberRange.php new file mode 100644 index 0000000..40fea37 --- /dev/null +++ b/Grid/Filter/Operator/HavingNumberRange.php @@ -0,0 +1,49 @@ +getQueryBuilder(); + + if (!empty($value[0])) { + $queryBuilder->andHaving( + $queryBuilder->expr()->gte( + $this->getIndex(), + ":{$this->getIndexClean()}_1" + ) + ) + ->setParameter( + ":{$this->getIndexClean()}_1", + (float) $value[0] + ); + } + + if (!empty($value[1])) { + $queryBuilder->andHaving( + $queryBuilder->expr()->lte( + $this->getIndex(), + ":{$this->getIndexClean()}_2" + ) + ) + ->setParameter( + ":{$this->getIndexClean()}_2", + (float) $value[1] + ); + } + } +} \ No newline at end of file diff --git a/Grid/GridAbstract.php b/Grid/GridAbstract.php index ee44de4..8591284 100644 --- a/Grid/GridAbstract.php +++ b/Grid/GridAbstract.php @@ -5,7 +5,7 @@ use Doctrine\ORM\Query; use Doctrine\ORM\QueryBuilder; -use DoctrineExtensions\Paginate\Paginate; +use Doctrine\ORM\Tools\Pagination\Paginator; use Symfony\Component\HttpFoundation\Response; @@ -325,7 +325,7 @@ public function getData() // Don't process grid for export if (!$this->isExport()) { - $totalCount = Paginate::count($this->getQueryBuilder()->getQuery()); + $totalCount = count(new Paginator($this->getQueryBuilder()->getQuery())); $totalPages = ceil($totalCount / $limit); $totalPages = ($totalPages <= 0 ? 1 : $totalPages); diff --git a/README.md b/README.md index ebe5b7c..44cc65b 100644 --- a/README.md +++ b/README.md @@ -7,10 +7,9 @@ pedro-teixeira/grid-bundle Requirements ------------ -1. [Doctrine Extensions](https://github.com/beberlei/DoctrineExtensions) -2. [Twitter Bootstrap](http://twitter.github.com/bootstrap/) (not mandatory) +1. [Twitter Bootstrap](http://twitter.github.com/bootstrap/) (not mandatory) * If you choose to don't use Twitter Bootstrap, it'll be necessary to create your own style. -3. [jQuery Bootstrap Datepicker](http://www.eyecon.ro/bootstrap-datepicker/) (not mandatory) +2. [jQuery Bootstrap Datepicker](http://www.eyecon.ro/bootstrap-datepicker/) (not mandatory) * If you choose to don't use Bootstrap Datepicker, please disable the datepicker as default in the configuration, "use_datepicker". diff --git a/composer.json b/composer.json index 1346517..8db0d56 100644 --- a/composer.json +++ b/composer.json @@ -15,8 +15,7 @@ "require":{ "php":">=5.3.2", "symfony/framework-bundle":"~2", - "doctrine/orm":"~2", - "beberlei/DoctrineExtensions":"@dev" + "doctrine/orm":"~2.2" }, "autoload":{ "psr-0":{