forked from zfcampus/zf-doctrine-querybuilder
-
Notifications
You must be signed in to change notification settings - Fork 0
/
GreaterThanOrEquals.php
44 lines (36 loc) · 1.4 KB
/
GreaterThanOrEquals.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
<?php
/**
* @license http://opensource.org/licenses/BSD-3-Clause BSD-3-Clause
* @copyright Copyright (c) 2014 Zend Technologies USA Inc. (http://www.zend.com)
*/
namespace ZF\Doctrine\QueryBuilder\Filter\ORM;
class GreaterThanOrEquals extends AbstractFilter
{
public function filter($queryBuilder, $metadata, $option)
{
if (isset($option['where'])) {
if ($option['where'] === 'and') {
$queryType = 'andWhere';
} elseif ($option['where'] === 'or') {
$queryType = 'orWhere';
}
}
if (! isset($queryType)) {
$queryType = 'andWhere';
}
if (! isset($option['alias'])) {
$option['alias'] = 'row';
}
[$typeCastMetaData, $typeCastFieldName] = $this->getTypeCastParams($queryBuilder, $metadata, $option['field'], $option['alias']);
$fieldType = $typeCastMetaData->getTypeOfField($typeCastFieldName);
$format = isset($option['format']) ? $option['format'] : null;
$value = $this->typeCastField($typeCastMetaData, $typeCastFieldName, $option['value'], $format);
$parameter = uniqid('a');
$queryBuilder->$queryType(
$queryBuilder
->expr()
->gte($option['alias'] . '.' . $option['field'], ':' . $parameter)
);
$queryBuilder->setParameter($parameter, $value, $fieldType);
}
}