d814b630c3771fe5acc80181e1819618bb3a8cbf
[Packages/TYPO3.CMS.git] / typo3 / sysext / extbase / Classes / Persistence / QOM / QueryObjectModelFactory.php
1 <?php
2 /***************************************************************
3 * Copyright notice
4 *
5 * (c) 2009 Jochen Rau <jochen.rau@typoplanet.de>
6 * All rights reserved
7 *
8 * This class is a backport of the corresponding class of FLOW3.
9 * All credits go to the v5 team.
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 *
20 * This script is distributed in the hope that it will be useful,
21 * but WITHOUT ANY WARRANTY; without even the implied warranty of
22 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 * GNU General Public License for more details.
24 *
25 * This copyright notice MUST APPEAR in all copies of the script!
26 ***************************************************************/
27
28 /**
29 * The Query Object Model Factory
30 *
31 * @package Extbase
32 * @subpackage Persistence\QOM
33 * @version $Id$
34 * @scope prototype
35 */
36 class Tx_Extbase_Persistence_QOM_QueryObjectModelFactory implements Tx_Extbase_Persistence_QOM_QueryObjectModelFactoryInterface {
37 // SK: Needs to be cleaned up (methods might need to be removed, and comments fixed)
38 /**
39 * @var Tx_Extbase_Persistence_Storage_BackendInterface
40 */
41 protected $storageBackend;
42
43 /**
44 * Constructs the Component Factory
45 *
46 * @param Tx_Extbase_Persistence_Storage_BackendInterfasce $storageBackend
47 * @param Tx_Extbase_Persistence_Mapper_DataMapper $dataMapper
48 */
49 public function __construct(Tx_Extbase_Persistence_Storage_BackendInterface $storageBackend) {
50 $this->storageBackend = $storageBackend;
51 }
52
53 /**
54 * Creates a query with one or more selectors.
55 * If source is a selector, that selector is the default selector of the
56 * query. Otherwise the query does not have a default selector.
57 *
58 * If the query is invalid, this method throws an InvalidQueryException.
59 * See the individual QOM factory methods for the validity criteria of each
60 * query element.
61 *
62 * @param mixed $source the Selector or the node-tuple Source; non-null
63 * @param Tx_Extbase_Persistence_QOM_ConstraintInterface $constraint the constraint, or null if none
64 * @param array $orderings zero or more orderings; null is equivalent to a zero-length array
65 * @param array $columns the columns; null is equivalent to a zero-length array
66 * @return Tx_Extbase_Persistence_QOM_QueryObjectModelInterface the query; non-null
67 * @throws \F3\PHPCR\Query\InvalidQueryException if a particular validity test is possible on this method, the implemention chooses to perform that test and the parameters given fail that test. See the individual QOM factory methods for the validity criteria of each query element.
68 * @throws Tx_Extbase_Persistence_Exception_RepositoryException if another error occurs.
69 */
70 public function createQuery(Tx_Extbase_Persistence_QOM_SourceInterface $selectorOrSource, $constraint, array $orderings, array $columns) {
71 $query = new Tx_Extbase_Persistence_QOM_QueryObjectModel($selectorOrSource, $constraint, $orderings, $columns);
72 $query->injectStorageBackend($this->storageBackend);
73 return $query;
74 }
75
76 /**
77 * Selects a subset of the nodes in the repository based on node type.
78 *
79 * @param string $nodeTypeName the name of the required node type; non-null
80 * @param string $selectorName the selector name; optional
81 * @return Tx_Extbase_Persistence_QOM_SelectorInterface the selector
82 * @throws \F3\PHPCR\Query\InvalidQueryException if the query is invalid
83 * @throws Tx_Extbase_Persistence_Exception_RepositoryException if the operation otherwise fails
84 */
85 public function selector($nodeTypeName, $selectorName = '') {
86 if ($selectorName === '') {
87 $selectorName = $nodeTypeName;
88 }
89 return t3lib_div::makeInstance('Tx_Extbase_Persistence_QOM_Selector', $selectorName, $nodeTypeName);
90 }
91
92 /**
93 * Sets a statement as constraint. This is not part of the JCR 2.0 Specification!
94 *
95 * @param string $statement The statement
96 * @param object $language The language of the statement. Must be a supported languanguage defined as Tx_Extbase_Persistence_QOM_QueryObjectModelInterface::JCR_* or Tx_Extbase_Persistence_QOM_QueryObjectModelInterface::TYPO3_* or
97 * @return Tx_Extbase_Persistence_QOM_StatementInterface
98 */
99 public function statement($statement, $boundVariables, $language) {
100 return t3lib_div::makeInstance('Tx_Extbase_Persistence_QOM_Statement', $statement, $boundVariables, $language);
101 }
102
103 /**
104 * Performs a join between two node-tuple sources.
105 *
106 * @param Tx_Extbase_Persistence_QOM_SourceInterface $left the left node-tuple source; non-null
107 * @param Tx_Extbase_Persistence_QOM_SourceInterface $right the right node-tuple source; non-null
108 * @param string $joinType one of QueryObjectModelConstants.JCR_JOIN_TYPE_*
109 * @param Tx_Extbase_Persistence_QOM_JoinConditionInterface $join Condition the join condition; non-null
110 * @return Tx_Extbase_Persistence_QOM_JoinInterface the join; non-null
111 * @throws \F3\PHPCR\Query\InvalidQueryException if the query is invalid
112 * @throws Tx_Extbase_Persistence_Exception_RepositoryException if the operation otherwise fails
113 */
114 public function join(Tx_Extbase_Persistence_QOM_SourceInterface $left, Tx_Extbase_Persistence_QOM_SourceInterface $right, $joinType, Tx_Extbase_Persistence_QOM_JoinConditionInterface $joinCondition) {
115 return t3lib_div::makeInstance('Tx_Extbase_Persistence_QOM_Join', $left, $right, $joinType, $joinCondition);
116 }
117
118 /**
119 * Tests whether the value of a property in a first selector is equal to the value of a property in a second selector.
120 *
121 * @param string $selector1Name the name of the first selector; non-null
122 * @param string $property1Name the property name in the first selector; non-null
123 * @param string $selector2Name the name of the second selector; non-null
124 * @param string $property2Name the property name in the second selector; non-null
125 * @return Tx_Extbase_Persistence_QOM_EquiJoinConditionInterface the constraint; non-null
126 * @throws \F3\PHPCR\Query\InvalidQueryException if the query is invalid
127 * @throws Tx_Extbase_Persistence_Exception_RepositoryException if the operation otherwise fails
128 */
129 public function equiJoinCondition($selector1Name, $property1Name, $selector2Name, $property2Name) {
130 return t3lib_div::makeInstance('Tx_Extbase_Persistence_QOM_EquiJoinCondition', $selector1Name, $property1Name, $selector2Name, $property2Name);
131 }
132
133 /**
134 * Performs a logical conjunction of two other constraints.
135 *
136 * @param Tx_Extbase_Persistence_QOM_ConstraintInterface $constraint1 the first constraint; non-null
137 * @param Tx_Extbase_Persistence_QOM_ConstraintInterface $constraint2 the second constraint; non-null
138 * @return Tx_Extbase_Persistence_QOM_AndInterface the And constraint; non-null
139 * @throws \F3\PHPCR\Query\InvalidQueryException if the query is invalid
140 * @throws Tx_Extbase_Persistence_Exception_RepositoryException if the operation otherwise fails
141 */
142 public function _and(Tx_Extbase_Persistence_QOM_ConstraintInterface $constraint1, Tx_Extbase_Persistence_QOM_ConstraintInterface $constraint2) {
143 return t3lib_div::makeInstance('Tx_Extbase_Persistence_QOM_LogicalAnd', $constraint1, $constraint2);
144 }
145
146 /**
147 * Performs a logical disjunction of two other constraints.
148 *
149 * @param Tx_Extbase_Persistence_QOM_ConstraintInterface $constraint1 the first constraint; non-null
150 * @param Tx_Extbase_Persistence_QOM_ConstraintInterface $constraint2 the second constraint; non-null
151 * @return Tx_Extbase_Persistence_QOM_OrInterface the Or constraint; non-null
152 * @throws \F3\PHPCR\Query\InvalidQueryException if the query is invalid
153 * @throws Tx_Extbase_Persistence_Exception_RepositoryException if the operation otherwise fails
154 */
155 public function _or(Tx_Extbase_Persistence_QOM_ConstraintInterface $constraint1, Tx_Extbase_Persistence_QOM_ConstraintInterface $constraint2) {
156 return t3lib_div::makeInstance('Tx_Extbase_Persistence_QOM_LogicalOr', $constraint1, $constraint2);
157 }
158
159 /**
160 * Performs a logical negation of another constraint.
161 *
162 * @param Tx_Extbase_Persistence_QOM_ConstraintInterface $constraint the constraint to be negated; non-null
163 * @return Tx_Extbase_Persistence_QOM_NotInterface the Not constraint; non-null
164 * @throws \F3\PHPCR\Query\InvalidQueryException if the query is invalid
165 * @throws Tx_Extbase_Persistence_Exception_RepositoryException if the operation otherwise fails
166 */
167 public function not(Tx_Extbase_Persistence_QOM_ConstraintInterface $constraint) {
168 return t3lib_div::makeInstance('Tx_Extbase_Persistence_QOM_LogicalNot', $constraint);
169 }
170
171 /**
172 * Filters node-tuples based on the outcome of a binary operation.
173 *
174 * @param Tx_Extbase_Persistence_QOM_DynamicOperandInterface $operand1 the first operand; non-null
175 * @param string $operator the operator; one of QueryObjectModelConstants.JCR_OPERATOR_*
176 * @param Tx_Extbase_Persistence_QOM_StaticOperandInterface $operand2 the second operand; non-null
177 * @return Tx_Extbase_Persistence_QOM_ComparisonInterface the constraint; non-null
178 * @throws \F3\PHPCR\Query\InvalidQueryException if the query is invalid
179 * @throws Tx_Extbase_Persistence_Exception_RepositoryException if the operation otherwise fails
180 */
181 public function comparison(Tx_Extbase_Persistence_QOM_DynamicOperandInterface $operand1, $operator, $operand2) {
182 return t3lib_div::makeInstance('Tx_Extbase_Persistence_QOM_Comparison', $operand1, $operator, $operand2);
183 }
184
185 /**
186 * Evaluates to the value (or values, if multi-valued) of a property in the specified or default selector.
187 *
188 * @param string $propertyName the property name; non-null
189 * @param string $selectorName the selector name; non-null
190 * @return Tx_Extbase_Persistence_QOM_PropertyValueInterface the operand; non-null
191 * @throws \F3\PHPCR\Query\InvalidQueryException if the query is invalid
192 * @throws Tx_Extbase_Persistence_Exception_RepositoryException if the operation otherwise fails
193 */
194 public function propertyValue($propertyName, $selectorName = '') {
195 return t3lib_div::makeInstance('Tx_Extbase_Persistence_QOM_PropertyValue', $propertyName, $selectorName);
196 }
197
198 /**
199 * Evaluates to the lower-case string value (or values, if multi-valued) of an operand.
200 *
201 * @param Tx_Extbase_Persistence_QOM_DynamicOperandInterface $operand the operand whose value is converted to a lower-case string; non-null
202 * @return Tx_Extbase_Persistence_QOM_LowerCaseInterface the operand; non-null
203 * @throws \F3\PHPCR\Query\InvalidQueryException if the query is invalid
204 * @throws Tx_Extbase_Persistence_Exception_RepositoryException if the operation otherwise fails
205 */
206 public function lowerCase(Tx_Extbase_Persistence_QOM_DynamicOperandInterface $operand) {
207 return t3lib_div::makeInstance('Tx_Extbase_Persistence_QOM_LowerCase', $operand);
208 }
209
210 /**
211 * Evaluates to the upper-case string value (or values, if multi-valued) of an operand.
212 *
213 * @param Tx_Extbase_Persistence_QOM_DynamicOperandInterface $operand the operand whose value is converted to a upper-case string; non-null
214 * @return Tx_Extbase_Persistence_QOM_UpperCaseInterface the operand; non-null
215 * @throws \F3\PHPCR\Query\InvalidQueryException if the query is invalid
216 * @throws Tx_Extbase_Persistence_Exception_RepositoryException if the operation otherwise fails
217 */
218 public function upperCase(Tx_Extbase_Persistence_QOM_DynamicOperandInterface $operand) {
219 return t3lib_div::makeInstance('Tx_Extbase_Persistence_QOM_UpperCase', $operand);
220 }
221
222 /**
223 * Orders by the value of the specified operand, in ascending order.
224 *
225 * The query is invalid if $operand does not evaluate to a scalar value.
226 *
227 * @param Tx_Extbase_Persistence_QOM_DynamicOperandInterface $operand the operand by which to order; non-null
228 * @return Tx_Extbase_Persistence_QOM_OrderingInterface the ordering
229 * @throws \F3\PHPCR\Query\InvalidQueryException if the query is invalid
230 * @throws Tx_Extbase_Persistence_Exception_RepositoryException if the operation otherwise fails
231 */
232 public function ascending(Tx_Extbase_Persistence_QOM_DynamicOperandInterface $operand) {
233 return t3lib_div::makeInstance('Tx_Extbase_Persistence_QOM_Ordering', $operand, Tx_Extbase_Persistence_QOM_QueryObjectModelConstantsInterface::JCR_ORDER_ASCENDING);
234 }
235
236 /**
237 * Orders by the value of the specified operand, in descending order.
238 *
239 * The query is invalid if $operand does not evaluate to a scalar value.
240 *
241 * @param Tx_Extbase_Persistence_QOM_DynamicOperandInterface $operand the operand by which to order; non-null
242 * @return Tx_Extbase_Persistence_QOM_OrderingInterface the ordering
243 * @throws \F3\PHPCR\Query\InvalidQueryException if the query is invalid
244 * @throws Tx_Extbase_Persistence_Exception_RepositoryException if the operation otherwise fails
245 */
246 public function descending(Tx_Extbase_Persistence_QOM_DynamicOperandInterface $operand) {
247 return t3lib_div::makeInstance('Tx_Extbase_Persistence_QOM_Ordering', $operand, Tx_Extbase_Persistence_QOM_QueryObjectModelConstantsInterface::JCR_ORDER_DESCENDING);
248 }
249
250 /**
251 * Evaluates to the value of a bind variable.
252 *
253 * @param string $bindVariableName the bind variable name; non-null
254 * @return Tx_Extbase_Persistence_QOM_BindVariableValueInterface the operand; non-null
255 * @throws \F3\PHPCR\Query\InvalidQueryException if the query is invalid
256 * @throws Tx_Extbase_Persistence_Exception_RepositoryException if the operation otherwise fails
257 */
258 public function bindVariable($bindVariableName) {
259 return t3lib_div::makeInstance('Tx_Extbase_Persistence_QOM_BindVariableValue', $bindVariableName);
260 }
261
262 }
263 ?>