MIOLO20
Carregando...
Procurando...
Nenhuma entrada encontrada
retrievecriteria.class
Ir para a documentação deste ficheiro.
1<?php
2
4{
5 private $havingCondition;
6 private $distinct = FALSE;
7 private $range = NULL;
8 private $columnAttributes = array();
9 private $columnAlias = array();
10 private $orderAttributes = array();
11 private $groupAttributes = array();
12
13 public function __construct($classMap, $manager)
14 {
15 parent::__construct($classMap, $manager);
16 // Create condition for the HAVING part of this criteria
17 $this->havingCondition = $this->getNewCondition();
18 }
19
20 public function getSqlStatement($forProxy = FALSE)
21 {
22 $statement = new MSQL();
23 if (count($this->columnAttributes))
24 {
25 $i = 0;
26 $columns = '';
27
28 foreach ($this->columnAttributes as $column)
29 {
30 if ($i++)
31 $columns .= ',';
32
33 $columns .= $this->getOperand($column)->getSql();
34 $columns .= ($alias = $this->columnAlias[$column]) != '' ? " as $alias" : "";
35 }
36 }
37 else
38 {
39 $classMap = $this->getClassMap();
40 $alias = $this->getAlias();
41 if ($forProxy)
42 {
43 $columns = $classMap->getSelectProxySql($alias);
44 }
45 else
46 {
47 $columns = $classMap->getSelectSql($alias);
48 }
49 }
50
51 $statement->SetColumns($columns, $this->distinct);
52
53 // Add 'FROM' clause to the select statement
54
55 if ($join = $this->getAssociationsJoin())
56 {
57 $statement->join = $join;
58 }
59 else
60 {
61 $aTables = $this->getTables();
62 $n = count($aTables['table']);
63
64 for ($i = 0; $i < $n; $i++)
65 {
66 $tables .= (($i > 0 ? ", " : "") . $aTables['table'][$i]->getName() . ' ' . $aTables['alias'][$i]);
67 }
68
69 $statement->SetTables($tables);
70 }
71
72 // Add 'WHERE' clause to the select statement
73 // $statement->SetWhere($this->getWhereSql());
74
75 if (($whereCondition = $this->whereCondition->getSql()) != '')
76 {
77 $statement->SetWhere($whereCondition);
78 }
79
80 // Add 'GROUP BY' clause to the select statement
81 if (count($this->groupAttributes))
82 {
83 $i = 0;
84 $groupby = '';
85
86 foreach ($this->groupAttributes as $group)
87 {
88 $groupby .= (($i++ > 0) ? ',' : '') . $this->getOperand($group)->getSql();
89 }
90
91 $statement->SetGroupBy($groupby);
92 }
93
94 // Add 'HAVING' clause to the select statement
95 $statement->SetHaving($this->havingCondition->getSql());
96
97 // Add 'ORDER BY' clause to the select statement
98 if (count($this->orderAttributes))
99 {
100 $i = 0;
101 $orderby = '';
102
103 foreach ($this->orderAttributes as $entry)
104 {
105 $orderby .= (($i++ > 0) ? ',' : '') . $entry->getStatement($this);
106 }
107
108 $statement->SetOrderBy($orderby);
109 }
110
111 // Add a range clause to the select statement
112 if (!is_null($this->range))
113 {
114 $statement->SetRange($this->range);
115 }
116
117 return $statement;
118 }
119
120 public function setDistinct($distinct = FALSE)
121 {
122 $this->distinct = $distinct;
123 }
124
125 public function setRange($range)
126 {
127 $this->range = $range;
128 }
129
130 public function addGroupAttribute($attribute)
131 {
132 $this->groupAttributes[] = $attribute;
133 }
134
135 public function addOrderAttribute($attribute, $ascend = TRUE)
136 {
137 $this->orderAttributes[] = new OrderEntry($attribute, $ascend);
138 }
139
140 public function addOrderEntry($orderEntry)
141 {
142 $this->orderAttributes[] = $orderEntry;
143 }
144
145 public function addColumnAttribute($attribute, $alias = '')
146 {
147 if ($attribute == '*')
148 {
150 for ($i = 0; $i < $classMap->getSize(); $i++)
151 {
152 $am = $classMap->getAttributeMap($i);
153 $this->addColumnAttribute($am->getName());
154 }
155 }
156 else
157 {
158 $this->columnAttributes[] = $attribute;
159 $this->columnAlias[$attribute] = $alias;
160 }
161 }
162
163 public function addHavingCriteria($op1, $operator, $op2)
164 {
165 $this->havingCondition->addCriteria($this->getCriteria($op1, $operator, $op2));
166 }
167
168 public function addOrHavingCriteria($op1, $operator, $op2)
169 {
170 $this->havingCondition->addOrCriteria($this->getCriteria($op1, $operator, $op2));
171 }
172
173 public function addJoinCriteria($criteria)
174 {
175 $this->havingCondition->addCondition($criteria->havingCondition);
176 $this->columnAttributes = array_merge($this->columnAttributes, $criteria->columnAttributes);
177 $this->orderAttributes = array_merge($this->orderAttributes, $criteria->orderAttributes);
178 $this->groupAttributes = array_merge($this->groupAttributes, $criteria->groupAttributes);
179 $this->aliasTable = array_merge($this->aliasTable, $criteria->aliasTable);
180 parent::addJoinCriteria($criteria);
181 }
182
183 public function retrieveAsQuery($parameters = null)
184 {
185 return $this->manager->processCriteriaAsQuery($this, $parameters);
186 }
187
188 public function retrieveAsCursor($parameters = null)
189 {
190 return $this->manager->processCriteriaAsCursor($this, $parameters);
191 }
192
193 public function retrieveAsProxyQuery($parameters = null)
194 {
195 return $this->manager->processCriteriaAsProxyQuery($this, $parameters);
196 }
197
198 public function retrieveAsProxyCursor($parameters = null)
199 {
200 return $this->manager->processCriteriaAsProxyCursor($this, $parameters);
201 }
202}
203?>
Definição msql.class:8
getCriteria($op1, $operator='', $op2=NULL)
addOrHavingCriteria($op1, $operator, $op2)
__construct($classMap, $manager)
addHavingCriteria($op1, $operator, $op2)
setDistinct($distinct=FALSE)
retrieveAsQuery($parameters=null)
addGroupAttribute($attribute)
addOrderAttribute($attribute, $ascend=TRUE)
retrieveAsProxyQuery($parameters=null)
getSqlStatement($forProxy=FALSE)
addColumnAttribute($attribute, $alias='')
retrieveAsProxyCursor($parameters=null)
addOrderEntry($orderEntry)
retrieveAsCursor($parameters=null)