1: <?php
2:
3: namespace PHPixie\ORM\Conditions\Builder;
4:
5: class Proxy implements \PHPixie\ORM\Conditions\Builder
6: {
7: protected $builder;
8: protected $aliases = array(
9: 'and' => '_and',
10: 'or' => '_or',
11: 'xor' => '_xor',
12: 'not' => '_not',
13: );
14:
15: public function __construct($builder)
16: {
17: $this->builder = $builder;
18: }
19:
20: public function __call($method, $params)
21: {
22: if(!array_key_exists($method, $this->aliases))
23: throw new \PHPixie\ORM\Exception\Builder("Method $method does not exist.");
24:
25: return call_user_func_array(array($this, $this->aliases[$method]), $params);
26: }
27:
28: public function addCondition($logic, $negate, $condition)
29: {
30: $this->builder->addCondition($logic, $negate, $condition);
31: return $this;
32: }
33:
34: public function buildCondition($logic, $negate, $args)
35: {
36: $this->builder->buildCondition($logic, $negate, $args);
37: return $this;
38: }
39:
40: public function addWhereCondition($logic, $negate, $condition)
41: {
42: $this->builder->addWhereCondition($logic, $negate, $condition);
43: return $this;
44: }
45:
46: public function buildWhereCondition($logic, $negate, $args)
47: {
48: $this->builder->buildWhereCondition($logic, $negate, $args);
49: return $this;
50: }
51:
52: public function addOperatorCondition($logic, $negate, $field, $operator, $values)
53: {
54: $this->builder->addOperatorCondition($logic, $negate, $field, $operator, $values);
55: return $this;
56: }
57:
58: public function addInCondition($logic, $negate, $items, $relationship = null)
59: {
60: $this->builder->addInCondition($logic, $negate, $items, $relationship);
61: return $this;
62: }
63:
64: public function startConditionGroup($logic = 'and', $negate = false)
65: {
66: $this->builder->startConditionGroup($logic, $negate);
67: return $this;
68: }
69:
70: public function endGroup()
71: {
72: $this->builder->endGroup();
73: return $this;
74: }
75:
76: public function addPlaceholder($logic = 'and', $negate = false, $allowEmpty = true)
77: {
78: $this->builder->addPlaceholder($logic, $negate, $allowEmpty);
79: return $this;
80: }
81:
82: public function addWhereOperatorCondition($logic, $negate, $field, $operator, $values)
83: {
84: $this->builder->addWhereOperatorCondition($logic, $negate, $field, $operator, $values);
85: return $this;
86: }
87:
88: public function addWherePlaceholder($logic = 'and', $negate = false, $allowEmpty = true)
89: {
90: $this->builder->addWherePlaceholder($logic, $negate, $allowEmpty);
91: return $this;
92: }
93:
94: public function startWhereConditionGroup($logic = 'and', $negate = false)
95: {
96: $this->builder->startWhereConditionGroup($logic, $negate);
97: return $this;
98: }
99:
100: public function endWhereGroup()
101: {
102: $this->builder->endWhereGroup();
103: return $this;
104: }
105:
106: public function addRelatedToCondition($logic, $negate, $relationship, $items = null)
107: {
108: $this->builder->addRelatedToCondition($logic, $negate, $relationship, $items);
109: return $this;
110: }
111:
112: public function startRelatedToConditionGroup($relationship, $logic = 'and', $negate = false)
113: {
114: $this->builder->startRelatedToConditionGroup($relationship, $logic, $negate);
115: return $this;
116: }
117:
118:
119:
120: public function _and()
121: {
122: return $this->buildCondition('and', false, func_get_args());
123: }
124:
125: public function _or()
126: {
127: return $this->buildCondition('or', false, func_get_args());
128: }
129:
130: public function _xor()
131: {
132: return $this->buildCondition('xor', false, func_get_args());
133: }
134:
135: public function _not()
136: {
137: return $this->buildCondition('and', true, func_get_args());
138: }
139:
140: public function andNot()
141: {
142: return $this->buildCondition('and', true, func_get_args());
143: }
144:
145: public function orNot()
146: {
147: return $this->buildCondition('or', true, func_get_args());
148: }
149:
150: public function xorNot()
151: {
152: return $this->buildCondition('xor', true, func_get_args());
153: }
154:
155: public function startGroup()
156: {
157: return $this->startConditionGroup('and', false);
158: }
159:
160: public function startAndGroup()
161: {
162: return $this->startConditionGroup('and', false);
163: }
164:
165: public function startOrGroup()
166: {
167: return $this->startConditionGroup('or', false);
168: }
169:
170: public function startXorGroup()
171: {
172: return $this->startConditionGroup('xor', false);
173: }
174:
175: public function startNotGroup()
176: {
177: return $this->startConditionGroup('and', true);
178: }
179:
180: public function startAndNotGroup()
181: {
182: return $this->startConditionGroup('and', true);
183: }
184:
185: public function startOrNotGroup()
186: {
187: return $this->startConditionGroup('or', true);
188: }
189:
190: public function startXorNotGroup()
191: {
192: return $this->startConditionGroup('xor', true);
193: }
194: public function where()
195: {
196: return $this->buildCondition('and', false, func_get_args());
197: }
198:
199: public function andWhere()
200: {
201: return $this->buildCondition('and', false, func_get_args());
202: }
203:
204: public function orWhere()
205: {
206: return $this->buildCondition('or', false, func_get_args());
207: }
208:
209: public function xorWhere()
210: {
211: return $this->buildCondition('xor', false, func_get_args());
212: }
213:
214: public function whereNot()
215: {
216: return $this->buildCondition('and', true, func_get_args());
217: }
218:
219: public function andWhereNot()
220: {
221: return $this->buildCondition('and', true, func_get_args());
222: }
223:
224: public function orWhereNot()
225: {
226: return $this->buildCondition('or', true, func_get_args());
227: }
228:
229: public function xorWhereNot()
230: {
231: return $this->buildCondition('xor', true, func_get_args());
232: }
233:
234: public function startWhereGroup()
235: {
236: return $this->startWhereConditionGroup('and', false);
237: }
238:
239: public function startAndWhereGroup()
240: {
241: return $this->startWhereConditionGroup('and', false);
242: }
243:
244: public function startOrWhereGroup()
245: {
246: return $this->startWhereConditionGroup('or', false);
247: }
248:
249: public function startXorWhereGroup()
250: {
251: return $this->startWhereConditionGroup('xor', false);
252: }
253:
254: public function startWhereNotGroup()
255: {
256: return $this->startWhereConditionGroup('and', true);
257: }
258:
259: public function startAndWhereNotGroup()
260: {
261: return $this->startWhereConditionGroup('and', true);
262: }
263:
264: public function startOrWhereNotGroup()
265: {
266: return $this->startWhereConditionGroup('or', true);
267: }
268:
269: public function startXorWhereNotGroup()
270: {
271: return $this->startWhereConditionGroup('xor', true);
272: }
273:
274: public function in($items)
275: {
276: return $this->addInCondition('and', false, $items);
277: }
278:
279: public function andIn($items)
280: {
281: return $this->addInCondition('and', false, $items);
282: }
283:
284: public function orIn($items)
285: {
286: return $this->addInCondition('or', false, $items);
287: }
288:
289: public function xorIn($items)
290: {
291: return $this->addInCondition('xor', false, $items);
292: }
293:
294: public function notIn($items)
295: {
296: return $this->addInCondition('and', true, $items);
297: }
298:
299: public function andNotIn($items)
300: {
301: return $this->addInCondition('and', true, $items);
302: }
303:
304: public function orNotIn($items)
305: {
306: return $this->addInCondition('or', true, $items);
307: }
308:
309: public function xorNotIn($items)
310: {
311: return $this->addInCondition('xor', true, $items);
312: }
313:
314:
315: public function relatedTo($relationship, $items = null)
316: {
317: return $this->addRelatedToCondition('and', false, $relationship, $items);
318: }
319:
320: public function andRelatedTo($relationship, $items = null)
321: {
322: return $this->addRelatedToCondition('and', false, $relationship, $items);
323: }
324:
325: public function orRelatedTo($relationship, $items = null)
326: {
327: return $this->addRelatedToCondition('or', false, $relationship, $items);
328: }
329:
330: public function xorRelatedTo($relationship, $items = null)
331: {
332: return $this->addRelatedToCondition('xor', false, $relationship, $items);
333: }
334:
335: public function notRelatedTo($relationship, $items = null)
336: {
337: return $this->addRelatedToCondition('and', true, $relationship, $items);
338: }
339:
340: public function andNotRelatedTo($relationship, $items = null)
341: {
342: return $this->addRelatedToCondition('and', true, $relationship, $items);
343: }
344:
345: public function orNotRelatedTo($relationship, $items = null)
346: {
347: return $this->addRelatedToCondition('or', true, $relationship, $items);
348: }
349:
350: public function xorNotrelatedTo($relationship, $items = null)
351: {
352: return $this->addRelatedToCondition('xor', true, $relationship, $items);
353: }
354:
355:
356: public function startRelatedToGroup($relationship)
357: {
358: return $this->startRelatedToConditionGroup($relationship, 'and', false);
359: }
360:
361: public function startAndRelatedToGroup($relationship)
362: {
363: return $this->startRelatedToConditionGroup($relationship, 'and', false);
364: }
365:
366: public function startOrRelatedToGroup($relationship)
367: {
368: return $this->startRelatedToConditionGroup($relationship, 'or', false);
369: }
370:
371: public function startXorRelatedToGroup($relationship)
372: {
373: return $this->startRelatedToConditionGroup($relationship, 'xor', false);
374: }
375:
376: public function startNotRelatedToGroup($relationship)
377: {
378: return $this->startRelatedToConditionGroup($relationship, 'and', true);
379: }
380:
381: public function startAndNotRelatedToGroup($relationship)
382: {
383: return $this->startRelatedToConditionGroup($relationship, 'and', true);
384: }
385:
386: public function startOrNotRelatedToGroup($relationship)
387: {
388: return $this->startRelatedToConditionGroup($relationship, 'or', true);
389: }
390:
391: public function startXorNotRelatedToGroup($relationship)
392: {
393: return $this->startRelatedToConditionGroup($relationship, 'xor', true);
394: }
395: }