Bitrix-D7  20.5.0
main/lib/orm/query/filter/condition.php
См. документацию.
1 <?php
2 /**
3  * Bitrix Framework
4  * @package bitrix
5  * @subpackage main
6  * @copyright 2001-2017 Bitrix
7  */
8 
13 
14 /**
15  * Single condition handler.
16  *
17  * @package bitrix
18  * @subpackage main
19  */
20 class Condition
21 {
22  /** @var string|Field|null */
23  protected $column;
24 
25  /** @var string */
26  protected $operator;
27 
28  /** @var mixed */
29  protected $value;
30 
31  /**
32  * QueryFilterCondition constructor.
33  *
34  * @param string|Field|null $column
35  * @param string $operator
36  * @param mixed $value
37  */
38  public function __construct($column, $operator, $value)
39  {
40  $this->column = $column;
41  $this->operator = $operator;
42  $this->value = $value;
43  }
44 
45  /**
46  * @return string|Field
47  */
48  public function getColumn()
49  {
50  return $this->column;
51  }
52 
53  /**
54  * @param string|Field|null $column
55  */
56  public function setColumn($column)
57  {
58  $this->column = $column;
59  }
60 
61  /**
62  * @return string
63  */
64  public function getOperator()
65  {
66  return $this->operator;
67  }
68 
69  /**
70  * @param string $operator
71  */
72  public function setOperator($operator)
73  {
74  $this->operator = $operator;
75  }
76 
77  /**
78  * @return mixed|ColumnExpression
79  */
80  public function getValue()
81  {
82  return $this->value;
83  }
84 
85  /**
86  * @param mixed $value
87  */
88  public function setValue($value)
89  {
90  $this->value = $value;
91  }
92 
93  /**
94  * Returns value as a set of atomic (composite) values.
95  *
96  * In classic condition there is only one value v1.
97  * In whereIn there is an array [v1, v2, v3, ...].
98  * In whereBetween there are two values v1, v2.
99  * etc.
100  *
101  * This method returns array of all the values regardless the operator.
102  *
103  * @return array
104  */
105  public function getAtomicValues()
106  {
107  if ($this->hasMultiValues())
108  {
109  return $this->value;
110  }
111 
112  return array($this->value);
113  }
114 
115  /**
116  * Checks for multi-values (array for IN etc.)
117  *
118  * @return bool
119  */
120  public function hasMultiValues()
121  {
122  return in_array($this->operator, array('in', 'between'), true) && is_array($this->value);
123  }
124 
125  /**
126  * @return string|Field|null
127  */
128  public function getDefinition()
129  {
130  return $this->getColumn();
131  }
132 
133  /**
134  * @param string|Field|null $definition
135  */
136  public function setDefinition($definition)
137  {
138  $this->setColumn($definition);
139  }
140 
141  public function __clone()
142  {
143  // clone value if there any filter expressions
144  $newValues = array();
145 
146  foreach ($this->getAtomicValues() as $atomicValue)
147  {
148  $newValues[] = ($atomicValue instanceof FilterExpression) ? clone $atomicValue : $atomicValue;
149  }
150 
151  $this->value = $this->hasMultiValues() ? $newValues : $newValues[0];
152 
153  // clone field
154  if ($this->column instanceof Field)
155  {
156  $this->column = clone $this->column;
157  }
158  }
159 }
__construct($column, $operator, $value)
QueryFilterCondition constructor.
hasMultiValues()
Checks for multi-values (array for IN etc.)
getAtomicValues()
Returns value as a set of atomic (composite) values.