1 | <?php |
||
16 | abstract class SearchHelperBase |
||
17 | { |
||
18 | /** @var PdoDatabase */ |
||
19 | protected $database; |
||
20 | /** @var array */ |
||
21 | protected $parameterList = array(); |
||
22 | /** @var null|int */ |
||
23 | private $limit = null; |
||
24 | /** @var null|int */ |
||
25 | private $offset = null; |
||
26 | private $orderBy = null; |
||
27 | /** |
||
28 | * @var string The where clause. |
||
29 | * |
||
30 | * (the 1=1 condition will be optimised out of the query by the query planner, and simplifies our code here). Note |
||
31 | * that we use positional parameters instead of named parameters because we don't know many times different options |
||
32 | * will be called (looking at excluding() here, but there's the option for others). |
||
33 | */ |
||
34 | protected $whereClause = ' WHERE 1 = 1'; |
||
35 | /** @var string */ |
||
36 | protected $table; |
||
37 | protected $joinClause = ''; |
||
38 | private $targetClass; |
||
39 | |||
40 | /** |
||
41 | * SearchHelperBase constructor. |
||
42 | * |
||
43 | * @param PdoDatabase $database |
||
44 | * @param string $table |
||
45 | * @param $targetClass |
||
46 | * @param null|string $order Order by clause, excluding ORDER BY. |
||
47 | */ |
||
48 | protected function __construct(PdoDatabase $database, $table, $targetClass, $order = null) |
||
55 | |||
56 | /** |
||
57 | * Finalises the database query, and executes it, returning a set of objects. |
||
58 | * |
||
59 | * @return DataObject[] |
||
60 | */ |
||
61 | public function fetch() |
||
73 | |||
74 | /** |
||
75 | * Finalises the database query, and executes it, returning only the requested column. |
||
76 | * |
||
77 | * @param string $column The required column |
||
78 | * @return array |
||
79 | */ |
||
80 | public function fetchColumn($column){ |
||
85 | |||
86 | /** |
||
87 | * @param int $count Returns the record count of the result set |
||
88 | * |
||
89 | * @return $this |
||
90 | */ |
||
91 | public function getRecordCount(&$count) |
||
104 | |||
105 | /** |
||
106 | * Limits the results |
||
107 | * |
||
108 | * @param integer $limit |
||
109 | * @param integer|null $offset |
||
110 | * |
||
111 | * @return $this |
||
112 | * |
||
113 | */ |
||
114 | public function limit($limit, $offset = null) |
||
121 | |||
122 | private function applyLimit() |
||
137 | |||
138 | private function applyOrder() |
||
146 | |||
147 | /** |
||
148 | * @param $column |
||
149 | * |
||
150 | * @return PDOStatement |
||
151 | */ |
||
152 | private function getData($column = '*') |
||
163 | |||
164 | /** |
||
165 | * @param $column |
||
166 | * |
||
167 | * @return string |
||
168 | */ |
||
169 | protected function buildQuery($column) |
||
176 | |||
177 | public function inIds($idList) { |
||
181 | |||
182 | protected function inClause($column, $values) { |
||
196 | } |
||
197 |