1: <?php
2:
3: namespace PHPixie\Database\Driver\PDO\Query;
4:
5: abstract class Items extends \PHPixie\Database\Driver\PDO\Query
6: implements \PHPixie\Database\Type\SQL\Query\Items,
7: \PHPixie\Database\Driver\PDO\Conditions\Builder
8: {
9:
10: public function __construct($connection, $parser, $builder)
11: {
12: parent::__construct($connection, $parser, $builder);
13:
14: $this->aliases = array_merge($this->aliases, array(
15: 'and' => '_and',
16: 'or' => '_or',
17: 'xor' => '_xor',
18: 'not' => '_not',
19: ));
20: }
21:
22: public function limit($limit)
23: {
24: $this->builder->setLimit($limit);
25:
26: return $this;
27: }
28:
29: public function clearLimit()
30: {
31: $this->builder->clearValue('limit');
32:
33: return $this;
34: }
35:
36: public function getLimit()
37: {
38: return $this->builder->getValue('limit');
39: }
40:
41: public function offset($offset)
42: {
43: $this->builder->setOffset($offset);
44:
45: return $this;
46: }
47:
48: public function clearOffset()
49: {
50: $this->builder->clearValue('offset');
51:
52: return $this;
53: }
54:
55: public function getOffset()
56: {
57: return $this->builder->getValue('offset');
58: }
59:
60: public function orderAscendingBy($field)
61: {
62: $this->builder->addOrderAscendingBy($field);
63:
64: return $this;
65: }
66:
67: public function orderDescendingBy($field)
68: {
69: $this->builder->addOrderDescendingBy($field);
70:
71: return $this;
72: }
73:
74: public function clearOrderBy()
75: {
76: $this->builder->clearArray('orderBy');
77:
78: return $this;
79: }
80:
81: public function getOrderBy()
82: {
83: return $this->builder->getArray('orderBy');
84: }
85:
86: public function join($table, $alias = null, $type = 'inner')
87: {
88: $this->builder->addJoin($table, $alias, $type);
89:
90: return $this;
91: }
92:
93: public function clearJoins()
94: {
95: $this->builder->clearArray('joins');
96:
97: return $this;
98: }
99:
100: public function getJoins()
101: {
102: return $this->builder->getArray('joins');
103: }
104:
105:
106:
107:
108: protected function addContainerOperatorCondition($logic, $negate, $field, $operator, $values, $containerName = null)
109: {
110: $this->builder->addOperatorCondition($logic, $negate, $field, $operator, $values, $containerName);
111:
112: return $this;
113: }
114:
115: protected function addContainerInOperatorCondition($field, $values, $logic, $negate, $containerName = null)
116: {
117: $this->builder->addInOperatorCondition($field, $values, $logic, $negate, $containerName);
118:
119: return $this;
120: }
121:
122: protected function buildContainerCondition($logic, $negate, $args, $containerName = null)
123: {
124: $this->builder->buildCondition($logic, $negate, $args, $containerName);
125:
126: return $this;
127: }
128:
129: protected function addContainerCondition($logic, $negate, $condition, $containerName = null)
130: {
131: $this->builder->addCondition($logic, $negate, $condition, $containerName);
132:
133: return $this;
134: }
135:
136: protected function startContainerConditionGroup($logic = 'and', $negate = false, $containerName = null)
137: {
138: $this->builder->startConditionGroup($logic, $negate, $containerName);
139:
140: return $this;
141: }
142:
143: protected function endContainerConditionGroup($containerName = null)
144: {
145: $this->builder->endConditionGroup($containerName);
146:
147: return $this;
148: }
149:
150: protected function addContainerPlaceholder($logic = 'and', $negate = false, $allowEmpty = true, $containerName = null)
151: {
152: return $this->builder->addPlaceholder($logic, $negate, $allowEmpty, $containerName);
153: }
154:
155: public function buildCondition($logic, $negate, $args)
156: {
157: $this->builder->buildCondition($logic, $negate, $args);
158: return $this;
159: }
160:
161:
162: public function addCondition($logic, $negate, $condition)
163: {
164: $this->builder->addCondition($logic, $negate, $condition);
165: return $this;
166: }
167:
168: public function addOperatorCondition($logic, $negate, $field, $operator, $values)
169: {
170: return $this->addContainerOperatorCondition($logic, $negate, $field, $operator, $values);
171: }
172:
173: public function addInOperatorCondition($field, $values, $logic = 'and', $negate = false)
174: {
175: return $this->addContainerInOperatorCondition($field, $values, $logic, $negate);
176: }
177:
178: public function addWhereInOperatorCondition($field, $values, $logic = 'and', $negate = false)
179: {
180: return $this->addContainerInOperatorCondition($field, $values, $logic, $negate, 'where');
181: }
182:
183: public function startConditionGroup($logic = 'and', $negate = false)
184: {
185: return $this->startContainerConditionGroup($logic, $negate);
186: }
187:
188: public function addPlaceholder($logic = 'and', $negate = false, $allowEmpty = true)
189: {
190: return $this->addContainerPlaceholder($logic, $negate, $allowEmpty);
191: }
192:
193: protected function endOnConditionGroup()
194: {
195: $this->builder->endOnConditionGroup();
196:
197: return $this;
198: }
199:
200:
201: public function addOnCondition($logic, $negate, $condition)
202: {
203: $this->builder->addOnCondition($logic, $negate, $condition);
204:
205: return $this;
206: }
207:
208: public function addOnInOperatorCondition($field, $values, $logic = 'and', $negate = false)
209: {
210: $this->builder->addOnInOperatorCondition($field, $values, $logic, $negate);
211:
212: return $this;
213: }
214:
215: public function buildOnCondition($logic, $negate, $args)
216: {
217: $this->builder->buildOnCondition($logic, $negate, $args);
218:
219: return $this;
220: }
221:
222:
223: public function addOnOperatorCondition($logic, $negate, $field, $operator, $values)
224: {
225: $this->builder->addOnOperatorCondition($logic, $negate, $field, $operator, $values);
226:
227: return $this;
228: }
229:
230: public function addOnPlaceholder($logic = 'and', $negate = false, $allowEmpty = true)
231: {
232: return $this->builder->addOnPlaceholder($logic, $negate, $allowEmpty);
233: }
234:
235: public function startOnConditionGroup($logic = 'and', $negate = false)
236: {
237: $this->builder->startOnConditionGroup($logic, $negate);
238:
239: return $this;
240: }
241:
242: public function addWhereCondition($logic, $negate, $condition)
243: {
244: return $this->addContainerCondition($logic, $negate, $condition, 'where');
245: }
246:
247: public function buildWhereCondition($logic, $negate, $params)
248: {
249: return $this->buildContainerCondition($logic, $negate, $params, 'where');
250: }
251:
252:
253: public function getWhereContainer()
254: {
255: return $this->builder->conditionContainer('where');
256: }
257:
258: public function getWhereConditions()
259: {
260: return $this->builder->getConditions('where');
261: }
262:
263: public function addWhereOperatorCondition($logic, $negate, $field, $operator, $values)
264: {
265: return $this->addContainerOperatorCondition($logic, $negate, $field, $operator, $values, 'where');
266: }
267:
268: public function startWhereConditionGroup($logic = 'and', $negate = false)
269: {
270: return $this->startContainerConditionGroup($logic, $negate, 'where');
271: }
272:
273: public function addWherePlaceholder($logic = 'and', $negate = false, $allowEmpty = true)
274: {
275: return $this->addContainerPlaceholder($logic, $negate, $allowEmpty, 'where');
276: }
277:
278: public function where()
279: {
280: return $this->buildContainerCondition('and', false, func_get_args(), 'where');
281: }
282:
283: public function andWhere()
284: {
285: return $this->buildContainerCondition('and', false, func_get_args(), 'where');
286: }
287:
288: public function orWhere()
289: {
290: return $this->buildContainerCondition('or', false, func_get_args(), 'where');
291: }
292:
293: public function xorWhere()
294: {
295: return $this->buildContainerCondition('xor', false, func_get_args(), 'where');
296: }
297:
298: public function whereNot()
299: {
300: return $this->buildContainerCondition('and', true, func_get_args(), 'where');
301: }
302:
303: public function andWhereNot()
304: {
305: return $this->buildContainerCondition('and', true, func_get_args(), 'where');
306: }
307:
308: public function orWhereNot()
309: {
310: return $this->buildContainerCondition('or', true, func_get_args(), 'where');
311: }
312:
313: public function xorWhereNot()
314: {
315: return $this->buildContainerCondition('xor', true, func_get_args(), 'where');
316: }
317:
318: public function startWhereGroup()
319: {
320: return $this->startContainerConditionGroup('and', false, 'where');
321: }
322:
323: public function startAndWhereGroup()
324: {
325: return $this->startContainerConditionGroup('and', false, 'where');
326: }
327:
328: public function startOrWhereGroup()
329: {
330: return $this->startContainerConditionGroup('or', false, 'where');
331: }
332:
333: public function startXorWhereGroup()
334: {
335: return $this->startContainerConditionGroup('xor', false, 'where');
336: }
337:
338: public function startWhereNotGroup()
339: {
340: return $this->startContainerConditionGroup('and', true, 'where');
341: }
342:
343: public function startAndWhereNotGroup()
344: {
345: return $this->startContainerConditionGroup('and', true, 'where');
346: }
347:
348: public function startOrWhereNotGroup()
349: {
350: return $this->startContainerConditionGroup('or', true, 'where');
351: }
352:
353: public function startXorWhereNotGroup()
354: {
355: return $this->startContainerConditionGroup('xor', true, 'where');
356: }
357:
358: public function endWhereGroup()
359: {
360: return $this->endContainerConditionGroup('where');
361: }
362:
363:
364: public function _and()
365: {
366: return $this->buildContainerCondition('and', false, func_get_args());
367: }
368:
369: public function _or()
370: {
371: return $this->buildContainerCondition('or', false, func_get_args());
372: }
373:
374: public function _xor()
375: {
376: return $this->buildContainerCondition('xor', false, func_get_args());
377: }
378:
379: public function _not()
380: {
381: return $this->buildContainerCondition('and', true, func_get_args());
382: }
383:
384: public function andNot()
385: {
386: return $this->buildContainerCondition('and', true, func_get_args());
387: }
388:
389: public function orNot()
390: {
391: return $this->buildContainerCondition('or', true, func_get_args());
392: }
393:
394: public function xorNot()
395: {
396: return $this->buildContainerCondition('xor', true, func_get_args());
397: }
398:
399: public function startGroup()
400: {
401: return $this->startConditionGroup('and', false);
402: }
403:
404: public function startAndGroup()
405: {
406: return $this->startConditionGroup('and', false);
407: }
408:
409: public function startOrGroup()
410: {
411: return $this->startConditionGroup('or', false);
412: }
413:
414: public function startXorGroup()
415: {
416: return $this->startConditionGroup('xor', false);
417: }
418:
419: public function startNotGroup()
420: {
421: return $this->startConditionGroup('and', true);
422: }
423:
424: public function startAndNotGroup()
425: {
426: return $this->startConditionGroup('and', true);
427: }
428:
429: public function startOrNotGroup()
430: {
431: return $this->startConditionGroup('or', true);
432: }
433:
434: public function startXorNotGroup()
435: {
436: return $this->startConditionGroup('xor', true);
437: }
438:
439: public function endGroup()
440: {
441: return $this->endContainerConditionGroup();
442: }
443:
444:
445:
446: public function on()
447: {
448: return $this->buildOnCondition('and', false, func_get_args());
449: }
450:
451: public function andOn()
452: {
453: return $this->buildOnCondition('and', false, func_get_args());
454: }
455:
456: public function orOn()
457: {
458: return $this->buildOnCondition('or', false, func_get_args());
459: }
460:
461: public function xorOn()
462: {
463: return $this->buildOnCondition('xor', false, func_get_args());
464: }
465:
466: public function onNot()
467: {
468: return $this->buildOnCondition('and', true, func_get_args());
469: }
470:
471: public function andOnNot()
472: {
473: return $this->buildOnCondition('and', true, func_get_args());
474: }
475:
476: public function orOnNot()
477: {
478: return $this->buildOnCondition('or', true, func_get_args());
479: }
480:
481: public function xorOnNot()
482: {
483: return $this->buildOnCondition('xor', true, func_get_args());
484: }
485:
486: public function startOnGroup()
487: {
488: return $this->startOnConditionGroup('and', false);
489: }
490:
491: public function startAndOnGroup()
492: {
493: return $this->startOnConditionGroup('and', false);
494: }
495:
496: public function startOrOnGroup()
497: {
498: return $this->startOnConditionGroup('or', false);
499: }
500:
501: public function startXorOnGroup()
502: {
503: return $this->startOnConditionGroup('xor', false);
504: }
505:
506: public function startOnNotGroup()
507: {
508: return $this->startOnConditionGroup('and', true);
509: }
510:
511: public function startAndOnNotGroup()
512: {
513: return $this->startOnConditionGroup('and', true);
514: }
515:
516: public function startOrOnNotGroup()
517: {
518: return $this->startOnConditionGroup('or', true);
519: }
520:
521: public function startXorOnNotGroup()
522: {
523: return $this->startOnConditionGroup('xor', true);
524: }
525:
526: public function endOnGroup()
527: {
528: return $this->endOnConditionGroup();
529: }
530: }