1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* @link https://www.yiiframework.com/ |
4
|
|
|
* @copyright Copyright (c) 2008 Yii Software LLC |
5
|
|
|
* @license https://www.yiiframework.com/license/ |
6
|
|
|
*/ |
7
|
|
|
|
8
|
|
|
namespace yii\db\conditions; |
9
|
|
|
|
10
|
|
|
use yii\db\ExpressionBuilderInterface; |
11
|
|
|
use yii\db\ExpressionBuilderTrait; |
12
|
|
|
use yii\db\ExpressionInterface; |
13
|
|
|
|
14
|
|
|
/** |
15
|
|
|
* Class BetweenConditionBuilder builds objects of [[BetweenCondition]] |
16
|
|
|
* |
17
|
|
|
* @author Dmytro Naumenko <[email protected]> |
18
|
|
|
* @since 2.0.14 |
19
|
|
|
*/ |
20
|
|
|
class BetweenConditionBuilder implements ExpressionBuilderInterface |
21
|
|
|
{ |
22
|
|
|
use ExpressionBuilderTrait; |
23
|
|
|
|
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* Method builds the raw SQL from the $expression that will not be additionally |
27
|
|
|
* escaped or quoted. |
28
|
|
|
* |
29
|
|
|
* @param ExpressionInterface|BetweenCondition $expression the expression to be built. |
30
|
|
|
* @param array $params the binding parameters. |
31
|
|
|
* @return string the raw SQL that will not be additionally escaped or quoted. |
32
|
|
|
*/ |
33
|
|
|
public function build(ExpressionInterface $expression, array &$params = []) |
34
|
|
|
{ |
35
|
|
|
$operator = $expression->getOperator(); |
|
|
|
|
36
|
|
|
$column = $expression->getColumn(); |
|
|
|
|
37
|
|
|
|
38
|
|
|
if (strpos($column, '(') === false) { |
39
|
|
|
$column = $this->queryBuilder->db->quoteColumnName($column); |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
$phName1 = $this->createPlaceholder($expression->getIntervalStart(), $params); |
|
|
|
|
43
|
|
|
$phName2 = $this->createPlaceholder($expression->getIntervalEnd(), $params); |
|
|
|
|
44
|
|
|
|
45
|
|
|
return "$column $operator $phName1 AND $phName2"; |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
/** |
49
|
|
|
* Attaches $value to $params array and returns placeholder. |
50
|
|
|
* |
51
|
|
|
* @param mixed $value |
52
|
|
|
* @param array $params passed by reference |
53
|
|
|
* @return string |
54
|
|
|
*/ |
55
|
|
|
protected function createPlaceholder($value, &$params) |
56
|
|
|
{ |
57
|
|
|
if ($value instanceof ExpressionInterface) { |
58
|
|
|
return $this->queryBuilder->buildExpression($value, $params); |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
return $this->queryBuilder->bindParam($value, $params); |
62
|
|
|
} |
63
|
|
|
} |
64
|
|
|
|