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 | * @return $this |
||
65 | */ |
||
66 | 22 | public function query($track_topics = true, $add_forum_data = true) |
|
87 | |||
88 | /** |
||
89 | * Fetch Forum by id(s) |
||
90 | * |
||
91 | * @param $forum_id |
||
92 | * @return $this |
||
93 | */ |
||
94 | 17 | public function fetch_forum($forum_id) |
|
100 | |||
101 | /** |
||
102 | * Fetch Topic by id(s) |
||
103 | * |
||
104 | * @param mixed $topic_id Limit by topic id: single id or array of topic ids |
||
105 | * @return $this |
||
106 | */ |
||
107 | 11 | public function fetch_topic($topic_id) |
|
113 | |||
114 | /** |
||
115 | * Fetch Topic by Poster id(s) |
||
116 | * |
||
117 | * @param mixed $user_id User id of topic poster: single id or array of user ids |
||
118 | * @return $this |
||
119 | */ |
||
120 | 3 | public function fetch_topic_poster($user_id) |
|
126 | |||
127 | /** |
||
128 | * Fetch by Topic Type |
||
129 | * |
||
130 | * @param array $topic_type |
||
131 | * @return $this |
||
132 | */ |
||
133 | 17 | public function fetch_topic_type(array $topic_type) |
|
142 | |||
143 | /** |
||
144 | * Fetch Topic Watch info |
||
145 | * |
||
146 | * @param $type |
||
147 | * @return $this |
||
148 | */ |
||
149 | public function fetch_watch_status($type = 'topic') |
||
173 | |||
174 | /** |
||
175 | * Fetch Topic Bookmark Info |
||
176 | * |
||
177 | * @return $this |
||
178 | */ |
||
179 | public function fetch_bookmark_status() |
||
192 | |||
193 | /** |
||
194 | * Fetch Topic Tracking Info |
||
195 | * |
||
196 | * @return $this |
||
197 | */ |
||
198 | 7 | public function fetch_tracking_info() |
|
218 | |||
219 | /** |
||
220 | * Fetch by Date Range |
||
221 | * |
||
222 | * @param int $unix_start_time |
||
223 | * @param int $unix_stop_time |
||
224 | * @param string $mode |
||
225 | * @return $this |
||
226 | */ |
||
227 | 14 | public function fetch_date_range($unix_start_time, $unix_stop_time, $mode = 'topic') |
|
236 | |||
237 | /** |
||
238 | * Fetch by Custom Query |
||
239 | * |
||
240 | * @param array $sql_array Array of elements to merge into query |
||
241 | * array( |
||
242 | * 'SELECT' => array('p.*'), |
||
243 | * 'WHERE' => array('p.post_id = 2'), |
||
244 | * ) |
||
245 | * @param array $overwrite_keys Array of query keys to overwrite with yours instead of merging |
||
246 | * e.g array('SELECT') will overwrite the 'SELECT' key with whatever is provided in $sql_array |
||
247 | * @return $this |
||
248 | */ |
||
249 | 8 | public function fetch_custom(array $sql_array, $overwrite_keys = array()) |
|
260 | |||
261 | /** |
||
262 | * Set Sorting Order |
||
263 | * |
||
264 | * @param string $sort_key The sorting key e.g. t.topic_time |
||
265 | * @param string $sort_dir Sort direction: ASC/DESC |
||
266 | * @return $this |
||
267 | */ |
||
268 | 13 | public function set_sorting($sort_key, $sort_dir = 'DESC') |
|
274 | |||
275 | /** |
||
276 | * Build the query |
||
277 | * |
||
278 | * @param bool|true $check_visibility Should we only return data from forums the user is allowed to see? |
||
279 | * @param bool|true $enable_caching Should the query be cached where possible? |
||
280 | * @param bool|true $exclude_hidden_forums Leave out hidden forums? |
||
281 | * @return $this |
||
282 | */ |
||
283 | 22 | public function build($check_visibility = true, $enable_caching = true, $exclude_hidden_forums = true) |
|
308 | |||
309 | /** |
||
310 | * Get the query array |
||
311 | * |
||
312 | * @return array The sql array that can be used with sql_build_query |
||
313 | */ |
||
314 | 8 | public function get_sql_array() |
|
318 | |||
319 | /** |
||
320 | * @param bool $enable_caching |
||
321 | */ |
||
322 | 22 | protected function _set_cache_time($enable_caching) |
|
329 | |||
330 | /** |
||
331 | * @param int $column_id |
||
332 | * @param string $column |
||
333 | */ |
||
334 | 17 | private function _fetch($column_id, $column) |
|
341 | |||
342 | /** |
||
343 | * @param bool $check_visibility |
||
344 | */ |
||
345 | 22 | private function _set_topic_visibility($check_visibility) |
|
353 | |||
354 | /** |
||
355 | * Reset data |
||
356 | */ |
||
357 | 22 | private function _reset() |
|
368 | } |
||
369 |