1: <?php
2:
3: namespace PHPixie\Database\Type\SQL\Query\Implementation;
4:
5: abstract class Builder extends \PHPixie\Database\Query\Implementation\Builder
6: {
7: protected $joins = array();
8:
9: public function addFields($args)
10: {
11: $this->addKeyValuesToArray('fields', $args, false, false);
12: }
13:
14: public function setTable($table, $alias)
15: {
16: $this->setValue('table', array(
17: 'table' => $table,
18: 'alias' => $alias
19: ));
20: }
21:
22: public function addJoin($table, $alias, $type)
23: {
24: $this->addToArray('joins', array(
25: 'container' => $this->conditions->container('=*'),
26: 'table' => $table,
27: 'alias' => $alias,
28: 'type' => $type
29: ));
30: }
31:
32: public function addGroupBy($args)
33: {
34: $this->addValuesToArray('groupBy', $args);
35: }
36:
37: public function addUnion($query, $all)
38: {
39: $this->addToArray('unions', array('query' => $query, 'all' => $all));
40: }
41:
42: public function addIncrement($args)
43: {
44: $this->addKeyValuesToArray('increment', $args, true, true, true);
45: }
46:
47: public function setBatchData($columns, $rows)
48: {
49: $this->setValue('batchData', array('columns' => $columns, 'rows' => $rows));
50: }
51:
52: public function addInOperatorCondition($field, $values, $logic, $negate, $containerName)
53: {
54: $this->conditionContainer($containerName)->addInOperatorCondition($field, $values, $logic, $negate);
55: }
56:
57: protected function lastOnContainer()
58: {
59: $joins = $this->getArray('joins');
60: $this->assert(!empty($joins), "Cannot add join conditions as no joins have been added to the query.");
61: $join = end($joins);
62: $container = $join['container'];
63: $this->defaultContainer = $container;
64:
65: return $container;
66: }
67:
68: public function addOnCondition($logic, $negate, $condition)
69: {
70: $this->lastOnContainer()->addCondition($logic, $negate, $condition);
71: }
72:
73: public function buildOnCondition($logic, $negate, $args)
74: {
75: $this->lastOnContainer()->buildCondition($logic, $negate, $args);
76: }
77:
78: public function startOnConditionGroup($logic, $negate)
79: {
80: $this->lastOnContainer()->startConditionGroup($logic, $negate);
81: }
82:
83: public function endOnConditionGroup()
84: {
85: $this->lastOnContainer()->endGroup();
86: }
87:
88: public function addOnOperatorCondition($logic, $negate, $field, $operator, $values)
89: {
90: $this->lastOnContainer()->addOperatorCondition($logic, $negate, $field, $operator, $values);
91: }
92:
93: public function addOnInOperatorCondition($field, $values, $logic, $negate)
94: {
95: $this->lastOnContainer()->addInOperatorCondition($field, $values, $logic, $negate);
96: }
97:
98: public function addOnPlaceholder($logic = 'and', $negate = false, $allowEmpty = true)
99: {
100: $this->lastOnContainer()->addPlaceholder($logic, $negate, $allowEmpty);
101: }
102:
103:
104:
105: }
106: