-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use oficial Doctrine Paginator and HavingNumberRange filter
- Loading branch information
1 parent
f72a402
commit 9c209cd
Showing
4 changed files
with
54 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
<?php | ||
|
||
namespace PedroTeixeira\Bundle\GridBundle\Grid\Filter\Operator; | ||
|
||
/** | ||
* HavingNumberRange | ||
*/ | ||
class HavingNumberRange extends OperatorAbstract | ||
{ | ||
/** | ||
* @param array $value | ||
* | ||
* @throws \Exception | ||
*/ | ||
public function execute($value) | ||
{ | ||
if (!is_array($value) || count($value) != 2) { | ||
throw new \Exception('Value for number range comparison should have to values'); | ||
} | ||
|
||
$queryBuilder = $this->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] | ||
); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters