[CLEANUP] Extbase persistence classes
[Packages/TYPO3.CMS.git] / typo3 / sysext / extbase / Classes / Persistence / Generic / Qom / Comparison.php
1 <?php
2 namespace TYPO3\CMS\Extbase\Persistence\Generic\Qom;
3
4 /***************************************************************
5 * Copyright notice
6 *
7 * (c) 2010-2013 Extbase Team (http://forge.typo3.org/projects/typo3v4-mvc)
8 * Extbase is a backport of TYPO3 Flow. All credits go to the TYPO3 Flow team.
9 * All rights reserved
10 *
11 * This script is part of the TYPO3 project. The TYPO3 project is
12 * free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License as published by
14 * the Free Software Foundation; either version 2 of the License, or
15 * (at your option) any later version.
16 *
17 * The GNU General Public License can be found at
18 * http://www.gnu.org/copyleft/gpl.html.
19 * A copy is found in the text file GPL.txt and important notices to the license
20 * from the author is found in LICENSE.txt distributed with these scripts.
21 *
22 *
23 * This script is distributed in the hope that it will be useful,
24 * but WITHOUT ANY WARRANTY; without even the implied warranty of
25 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
26 * GNU General Public License for more details.
27 *
28 * This copyright notice MUST APPEAR in all copies of the script!
29 ***************************************************************/
30 use TYPO3\CMS\Extbase\Persistence\QueryInterface;
31
32 /**
33 * Filters node-tuples based on the outcome of a binary operation.
34 *
35 * For any comparison, operand2 always evaluates to a scalar value. In contrast,
36 * operand1 may evaluate to an array of values (for example, the value of a multi-valued
37 * property), in which case the comparison is separately performed for each element
38 * of the array, and the Comparison constraint is satisfied as a whole if the
39 * comparison against any element of the array is satisfied.
40 *
41 * If operand1 and operand2 evaluate to values of different property types, the
42 * value of operand2 is converted to the property type of the value of operand1.
43 * If the type conversion fails, the query is invalid.
44 *
45 * If operator is not supported for the property type of operand1, the query is invalid.
46 *
47 * If operand1 evaluates to null (for example, if the operand evaluates the value
48 * of a property which does not exist), the constraint is not satisfied.
49 *
50 * The OPERATOR_EQUAL_TO operator is satisfied only if the value of operand1
51 * equals the value of operand2.
52 *
53 * The OPERATOR_NOT_EQUAL_TO operator is satisfied unless the value of
54 * operand1 equals the value of operand2.
55 *
56 * The OPERATOR_LESSS_THAN operator is satisfied only if the value of
57 * operand1 is ordered before the value of operand2.
58 *
59 * The OPERATOR_LESS_THAN_OR_EQUAL_TO operator is satisfied unless the value
60 * of operand1 is ordered after the value of operand2.
61 *
62 * The OPERATOR_GREATER_THAN operator is satisfied only if the value of
63 * operand1 is ordered after the value of operand2.
64 *
65 * The OPERATOR_GREATER_THAN_OR_EQUAL_TO operator is satisfied unless the
66 * value of operand1 is ordered before the value of operand2.
67 *
68 * The OPERATOR_LIKE operator is satisfied only if the value of operand1
69 * matches the pattern specified by the value of operand2, where in the pattern:
70 * the character "%" matches zero or more characters, and
71 * the character "_" (underscore) matches exactly one character, and
72 * the string "\x" matches the character "x", and
73 * all other characters match themselves.
74 */
75 class Comparison implements ComparisonInterface {
76
77 /**
78 * @var PropertyValueInterface
79 */
80 protected $operand1;
81
82 /**
83 * @var integer
84 */
85 protected $operator;
86
87 /**
88 * @var mixed
89 */
90 protected $operand2;
91
92 /**
93 * @var string
94 */
95 protected $parameterIdentifier;
96
97 /**
98 * Constructs this Comparison instance
99 *
100 * @param PropertyValueInterface $operand1
101 * @param integer $operator one of QueryInterface::OPERATOR_*
102 * @param mixed $operand2
103 */
104 public function __construct(PropertyValueInterface $operand1, $operator, $operand2) {
105 $this->operand1 = $operand1;
106 $this->operator = $operator;
107 $this->operand2 = $operand2;
108 }
109
110 /**
111 * Gets the first operand.
112 *
113 * @return PropertyValueInterface the operand; non-null
114 */
115 public function getOperand1() {
116 return $this->operand1;
117 }
118
119 /**
120 * Gets the operator.
121 *
122 * @return string One of QueryInterface::OPERATOR_*
123 */
124 public function getOperator() {
125 $operator = $this->operator;
126
127 if ($this->getOperand2() === NULL) {
128 if ($operator === QueryInterface::OPERATOR_EQUAL_TO) {
129 $operator = QueryInterface::OPERATOR_EQUAL_TO_NULL;
130 } elseif ($operator === QueryInterface::OPERATOR_NOT_EQUAL_TO) {
131 $operator = QueryInterface::OPERATOR_NOT_EQUAL_TO_NULL;
132 }
133 }
134
135 return $operator;
136 }
137
138 /**
139 * Gets the second operand.
140 *
141 * @return mixed the operand; non-null
142 */
143 public function getOperand2() {
144 return $this->operand2;
145 }
146
147 /**
148 * @param string $parameterIdentifier
149 * @return void
150 */
151 public function setParameterIdentifier($parameterIdentifier) {
152 $this->parameterIdentifier = $parameterIdentifier;
153 }
154
155 /**
156 * @return string
157 */
158 public function getParameterIdentifier() {
159 return $this->parameterIdentifier;
160 }
161
162 /**
163 * Fills an array with the names of all bound variables in the constraints
164 *
165 * @param array &$boundVariables
166 * @return void
167 */
168 public function collectBoundVariableNames(&$boundVariables) {
169 }
170 }