1 | <?php |
||
12 | class query_builder |
||
13 | { |
||
14 | /** @var \phpbb\auth\auth */ |
||
15 | protected $auth; |
||
16 | |||
17 | /** @var \phpbb\config\config */ |
||
18 | protected $config; |
||
19 | |||
20 | /** @var \phpbb\content_visibility */ |
||
21 | protected $content_visibility; |
||
22 | |||
23 | /** @var \phpbb\db\driver\driver_interface */ |
||
24 | protected $db; |
||
25 | |||
26 | /** @var \phpbb\user */ |
||
27 | protected $user; |
||
28 | |||
29 | /** @var array */ |
||
30 | protected $store; |
||
31 | |||
32 | /** @var array */ |
||
33 | protected $ex_fid_ary; |
||
34 | |||
35 | /** @var integer */ |
||
36 | protected $cache_time; |
||
37 | |||
38 | /** |
||
39 | * Constructor |
||
40 | * |
||
41 | * @param \phpbb\auth\auth $auth Auth object |
||
42 | * @param \phpbb\config\config $config Config object |
||
43 | * @param \phpbb\content_visibility $content_visibility Content visibility |
||
44 | * @param \phpbb\db\driver\driver_interface $db Database connection |
||
45 | * @param \phpbb\user $user User object |
||
46 | * @param integer $cache_time Cache results for 3 hours by default |
||
47 | */ |
||
48 | 31 | public function __construct(\phpbb\auth\auth $auth, \phpbb\config\config $config, \phpbb\content_visibility $content_visibility, \phpbb\db\driver\driver_interface $db, \phpbb\user $user, $cache_time) |
|
59 | |||
60 | /** |
||
61 | * Begin query |
||
62 | * |
||
63 | * @param bool $track_topics |
||
64 | * @param bool $add_forum_data |
||
65 | * @return $this |
||
66 | */ |
||
67 | 22 | public function query($track_topics = true, $add_forum_data = true) |
|
88 | |||
89 | /** |
||
90 | * Fetch Forum by id(s) |
||
91 | * |
||
92 | * @param $forum_id |
||
93 | * @return $this |
||
94 | */ |
||
95 | 17 | public function fetch_forum($forum_id) |
|
101 | |||
102 | /** |
||
103 | * Fetch Topic by id(s) |
||
104 | * |
||
105 | * @param mixed $topic_id Limit by topic id: single id or array of topic ids |
||
106 | * @return $this |
||
107 | */ |
||
108 | 11 | public function fetch_topic($topic_id) |
|
114 | |||
115 | /** |
||
116 | * Fetch Topic by Poster id(s) |
||
117 | * |
||
118 | * @param mixed $user_id User id of topic poster: single id or array of user ids |
||
119 | * @return $this |
||
120 | */ |
||
121 | 3 | public function fetch_topic_poster($user_id) |
|
127 | |||
128 | /** |
||
129 | * Fetch by Topic Type |
||
130 | * |
||
131 | * @param array $topic_type |
||
132 | * @return $this |
||
133 | */ |
||
134 | 17 | public function fetch_topic_type(array $topic_type) |
|
143 | |||
144 | /** |
||
145 | * Fetch Topic Watch info |
||
146 | * |
||
147 | * @param $type |
||
148 | * @return $this |
||
149 | */ |
||
150 | public function fetch_watch_status($type = 'topic') |
||
174 | |||
175 | /** |
||
176 | * Fetch Topic Bookmark Info |
||
177 | * |
||
178 | * @return $this |
||
179 | */ |
||
180 | public function fetch_bookmark_status() |
||
193 | |||
194 | /** |
||
195 | * Fetch Topic Tracking Info |
||
196 | * |
||
197 | * @return $this |
||
198 | */ |
||
199 | 7 | public function fetch_tracking_info() |
|
219 | |||
220 | /** |
||
221 | * Fetch by Date Range |
||
222 | * |
||
223 | * @param int $unix_start_time |
||
224 | * @param int $unix_stop_time |
||
225 | * @param string $mode |
||
226 | * @return $this |
||
227 | */ |
||
228 | 14 | public function fetch_date_range($unix_start_time, $unix_stop_time, $mode = 'topic') |
|
237 | |||
238 | /** |
||
239 | * Fetch by Custom Query |
||
240 | * |
||
241 | * @param array $sql_array Array of elements to merge into query |
||
242 | * array( |
||
243 | * 'SELECT' => array('p.*'), |
||
244 | * 'WHERE' => array('p.post_id = 2'), |
||
245 | * ) |
||
246 | * @param array $overwrite_keys Array of query keys to overwrite with yours instead of merging |
||
247 | * e.g array('SELECT') will overwrite the 'SELECT' key with whatever is provided in $sql_array |
||
248 | * @return $this |
||
249 | */ |
||
250 | 8 | public function fetch_custom(array $sql_array, $overwrite_keys = array()) |
|
261 | |||
262 | /** |
||
263 | * Set Sorting Order |
||
264 | * |
||
265 | * @param string $sort_key The sorting key e.g. t.topic_time |
||
266 | * @param string $sort_dir Sort direction: ASC/DESC |
||
267 | * @return $this |
||
268 | */ |
||
269 | 13 | public function set_sorting($sort_key, $sort_dir = 'DESC') |
|
275 | |||
276 | /** |
||
277 | * Build the query |
||
278 | * |
||
279 | * @param bool|true $check_visibility Should we only return data from forums the user is allowed to see? |
||
280 | * @param bool|true $enable_caching Should the query be cached where possible? |
||
281 | * @param bool|true $exclude_hidden_forums Leave out hidden forums? |
||
282 | * @return $this |
||
283 | */ |
||
284 | 22 | public function build($check_visibility = true, $enable_caching = true, $exclude_hidden_forums = true) |
|
299 | |||
300 | /** |
||
301 | * Get the query array |
||
302 | * |
||
303 | * @return array The sql array that can be used with sql_build_query |
||
304 | */ |
||
305 | 8 | public function get_sql_array() |
|
309 | |||
310 | /** |
||
311 | * @param bool $enable_caching |
||
312 | * @return void |
||
313 | */ |
||
314 | 22 | protected function _set_cache_time($enable_caching) |
|
321 | |||
322 | /** |
||
323 | * @param int $column_id |
||
324 | * @param string $column |
||
325 | * @return void |
||
326 | */ |
||
327 | 17 | private function _fetch($column_id, $column) |
|
334 | |||
335 | /** |
||
336 | * @param bool $check_visibility |
||
337 | * @return void |
||
338 | */ |
||
339 | 22 | private function _set_topic_visibility($check_visibility) |
|
347 | |||
348 | /** |
||
349 | * @param bool $exclude_hidden_forums |
||
350 | * @return void |
||
351 | */ |
||
352 | 22 | private function _set_forum_table($exclude_hidden_forums) |
|
365 | |||
366 | /** |
||
367 | * Reset data |
||
368 | * @return void |
||
369 | */ |
||
370 | 22 | private function _reset() |
|
381 | } |
||
382 |