1 | <?php |
||
13 | class QueryParameters |
||
14 | { |
||
15 | /** |
||
16 | * The where clause string of the query parameters. |
||
17 | * |
||
18 | * @var string |
||
19 | */ |
||
20 | private $whereClause; |
||
21 | |||
22 | /** |
||
23 | * The string used for conjuctions. |
||
24 | * This could either be 'AND' and or an 'OR' operator. |
||
25 | * |
||
26 | * @var string |
||
27 | */ |
||
28 | private $conjunction = ''; |
||
29 | |||
30 | /** |
||
31 | * Data that will be bound when a query is executed with this object. |
||
32 | * |
||
33 | * @var array |
||
34 | */ |
||
35 | private $boundData = []; |
||
36 | |||
37 | /** |
||
38 | * This flag is set to true whenever there is bound data prepared. |
||
39 | * |
||
40 | * @var bool |
||
41 | */ |
||
42 | private $preparedBoundData = false; |
||
43 | |||
44 | /** |
||
45 | * A list of fields that have arrays bound to them. |
||
46 | * |
||
47 | * @var array |
||
48 | */ |
||
49 | private $boundArrays = []; |
||
50 | |||
51 | /** |
||
52 | * A list of fields that should be returned for the query. |
||
53 | * |
||
54 | * @var array |
||
55 | */ |
||
56 | private $fields = []; |
||
57 | |||
58 | /** |
||
59 | * The database table to be queried. |
||
60 | * |
||
61 | * @var null|string |
||
62 | */ |
||
63 | private $table; |
||
64 | |||
65 | /** |
||
66 | * When this flag is set, only the first item in the query is returned. |
||
67 | * It essentially forces a limit of 1. |
||
68 | * |
||
69 | * @var bool |
||
70 | */ |
||
71 | private $firstOnly = false; |
||
72 | |||
73 | /** |
||
74 | * The number of records to return after the query. |
||
75 | * |
||
76 | * @var int |
||
77 | */ |
||
78 | private $limit; |
||
79 | |||
80 | /** |
||
81 | * The number of items to skip in the query. |
||
82 | * |
||
83 | * @var int |
||
84 | */ |
||
85 | private $offset; |
||
86 | |||
87 | /** |
||
88 | * Holds a list of sorted fields, sort order and the order by which they should all be sorted. |
||
89 | * |
||
90 | * @var array |
||
91 | */ |
||
92 | private $sorts = []; |
||
93 | |||
94 | /** |
||
95 | * QueryParameters constructor |
||
96 | * |
||
97 | * @param string $table The name of the table |
||
98 | */ |
||
99 | 32 | public function __construct($table = null) |
|
103 | |||
104 | /** |
||
105 | * Get the comma seperated list of fields for the query. |
||
106 | * In cases where no fields have been specifid, the wildcard * is returned. |
||
107 | * |
||
108 | * @return string |
||
109 | */ |
||
110 | 24 | public function getFields() |
|
120 | |||
121 | /** |
||
122 | * Set an array of fields that this query should return. |
||
123 | * |
||
124 | * @param array $fields |
||
125 | * @return $this |
||
126 | */ |
||
127 | 12 | public function setFields(array $fields) |
|
132 | |||
133 | /** |
||
134 | * Get the table for this query. |
||
135 | * |
||
136 | * @return null|string |
||
137 | */ |
||
138 | 32 | public function getTable() |
|
142 | |||
143 | /** |
||
144 | * Set the table for this query. |
||
145 | * |
||
146 | * @param $table |
||
147 | * @return $this For chaining |
||
148 | */ |
||
149 | 12 | public function setTable($table) |
|
154 | |||
155 | /** |
||
156 | * Gets the limit clause of the query. |
||
157 | * |
||
158 | * @return null|string |
||
159 | */ |
||
160 | 24 | public function getLimit() |
|
164 | |||
165 | 24 | public function getOffset() |
|
169 | |||
170 | 32 | public function getWhereClause() |
|
185 | |||
186 | 32 | public function getBoundData() |
|
202 | |||
203 | 4 | public function setBoundData($field, $value) |
|
219 | |||
220 | 24 | public function getSorts() |
|
224 | |||
225 | 24 | public function addFilter($field, $values = null) |
|
244 | |||
245 | 6 | public function setFilter($filter, $values) |
|
253 | |||
254 | /** |
||
255 | * @param boolean $firstOnly |
||
256 | * @return $this |
||
257 | */ |
||
258 | 24 | public function setFirstOnly($firstOnly) |
|
263 | |||
264 | 24 | public function getFirstOnly() |
|
268 | |||
269 | public function setLimit($numItems) |
||
273 | |||
274 | public function setOffset($offset) |
||
278 | |||
279 | /** |
||
280 | * @param string $field |
||
281 | * @param string $direction |
||
282 | */ |
||
283 | public function addSort($field, $direction = 'ASC') |
||
287 | |||
288 | } |
||
289 |
Our type inference engine in quite powerful, but sometimes the code does not provide enough clues to go by. In these cases we request you to add a
@return
annotation as described here.