1 | <?php |
||
18 | class manager |
||
19 | { |
||
20 | /** @var \phpbb\cache\service */ |
||
21 | protected $cache; |
||
22 | |||
23 | /** @var \board3\portal\controller\helper */ |
||
24 | protected $controller_helper; |
||
25 | |||
26 | /** @var \board3\portal\portal\columns */ |
||
27 | protected $portal_columns; |
||
28 | |||
29 | /** @var \board3\portal\includes\helper */ |
||
30 | protected $portal_helper; |
||
31 | |||
32 | /** @var \board3\portal\portal\modules\constraints_handler */ |
||
33 | protected $constraints_handler; |
||
34 | |||
35 | /** @var \board3\portal\portal\modules\database_handler */ |
||
36 | protected $database_handler; |
||
37 | |||
38 | /** @var \phpbb\db\driver\driver_interface */ |
||
39 | protected $db; |
||
40 | |||
41 | /** @var \phpbb\request\request_interface */ |
||
42 | protected $request; |
||
43 | |||
44 | /** @var \phpbb\user */ |
||
45 | protected $user; |
||
46 | |||
47 | /** @var \board3\portal\modules\module_interface */ |
||
48 | protected $module; |
||
49 | |||
50 | /** @var string u_action of acp module */ |
||
51 | protected $u_action; |
||
52 | |||
53 | /** @var string class of acp module */ |
||
54 | protected $acp_class; |
||
55 | |||
56 | /** |
||
57 | * Constructor for modules manager |
||
58 | * |
||
59 | * @param \phpbb\cache\service $cache phpBB cache |
||
60 | * @param \phpbb\db\driver\driver_interface $db Database driver |
||
61 | * @param \board3\portal\controller\helper $controller_helper Board3 Portal controller helper |
||
62 | * @param \board3\portal\portal\columns $portal_columns Portal columns helper |
||
63 | * @param \board3\portal\includes\helper $portal_helper Portal helper |
||
64 | * @param \board3\portal\portal\modules\constraints_handler $constraints_handler Modules constraints handler |
||
65 | * @param \board3\portal\portal\modules\database_handler $database_handler Modules database handler |
||
66 | * @param \phpbb\request\request_interface $request phpBB request |
||
67 | * @param \phpbb\user $user phpBB user |
||
68 | */ |
||
69 | 43 | public function __construct($cache, driver_interface $db, \board3\portal\controller\helper $controller_helper, columns $portal_columns, helper $portal_helper, constraints_handler $constraints_handler, database_handler $database_handler, request_interface $request, $user) |
|
70 | { |
||
71 | 43 | $this->cache = $cache; |
|
72 | 43 | $this->db = $db; |
|
73 | 43 | $this->controller_helper = $controller_helper; |
|
74 | 43 | $this->portal_columns = $portal_columns; |
|
75 | 43 | $this->portal_helper = $portal_helper; |
|
76 | 43 | $this->constraints_handler = $constraints_handler; |
|
77 | 43 | $this->database_handler = $database_handler; |
|
78 | 43 | $this->request = $request; |
|
79 | 43 | $this->user = $user; |
|
80 | 43 | } |
|
81 | |||
82 | /** |
||
83 | * Set u_action for module |
||
84 | * |
||
85 | * @param string $u_action u_action for module |
||
86 | * |
||
87 | * @return \board3\portal\portal\modules\manager This class |
||
88 | */ |
||
89 | 7 | public function set_u_action($u_action) |
|
96 | |||
97 | /** |
||
98 | * Set acp module class |
||
99 | * |
||
100 | * @param string $acp_class ACP module class |
||
101 | * |
||
102 | * @return \board3\portal\portal\modules\manager This class |
||
103 | */ |
||
104 | 7 | public function set_acp_class($acp_class) |
|
110 | |||
111 | /** |
||
112 | * Get module object |
||
113 | * |
||
114 | * @param string $class_name Module class name |
||
115 | * @return null |
||
116 | */ |
||
117 | 14 | protected function get_module($class_name) |
|
132 | |||
133 | /** |
||
134 | * Handle ajax request. |
||
135 | * Method will return supplied data if request is an ajax request |
||
136 | * |
||
137 | * @param array $data Data to send |
||
138 | * |
||
139 | * @return null |
||
140 | */ |
||
141 | 11 | public function handle_ajax_request($data) |
|
149 | |||
150 | /** |
||
151 | * Reset module settings to default options |
||
152 | * |
||
153 | * @param int $id ID of the acp_portal module |
||
154 | * @param string|int $mode Mode of the acp_portal module |
||
155 | * @param int $module_id ID of the module that should be reset |
||
156 | * @param array $module_data Array containing the module's database row |
||
157 | */ |
||
158 | 1 | public function reset_module($id, $mode, $module_id, $module_data) |
|
197 | |||
198 | /** |
||
199 | * Get module_data required for moving it |
||
200 | * |
||
201 | * @param int $module_id ID of the module that should be moved |
||
202 | * @return array|null Module_data or empty if not successful |
||
203 | */ |
||
204 | 18 | public function get_move_module_data($module_id) |
|
208 | |||
209 | /** |
||
210 | * Handle output after moving module |
||
211 | * |
||
212 | * @param bool $success Whether moving module was successful |
||
213 | * @param bool $is_row Whether the module move was inside a row |
||
214 | * @return void |
||
215 | */ |
||
216 | 14 | public function handle_after_move($success = true, $is_row = false) |
|
230 | |||
231 | /** |
||
232 | * Get the module order to the last module in the column |
||
233 | * |
||
234 | * @param int $module_column Module column to check |
||
235 | * @return int Module order of the last module in the column |
||
236 | */ |
||
237 | 5 | public function get_last_module_order($module_column) |
|
253 | |||
254 | /** |
||
255 | * Move module vertically |
||
256 | * |
||
257 | * @param int $module_id Module ID |
||
258 | * @param int $direction Direction of move, either -1 for up or 1 for down |
||
259 | */ |
||
260 | 2 | public function move_module_vertical($module_id, $direction) |
|
274 | |||
275 | /** |
||
276 | * Move module horizontally |
||
277 | * |
||
278 | * @param int $module_id ID of the module that should be moved |
||
279 | * @param int $direction The direction to move the module |
||
280 | * |
||
281 | * @return null |
||
282 | */ |
||
283 | 12 | public function move_module_horizontal($module_id, $direction) |
|
296 | |||
297 | /** |
||
298 | * Get the horizontal move action (columns to move) |
||
299 | * |
||
300 | * @param array $module_data Array containing the module data |
||
301 | * @param int $direction Direction to move; 1 for right, -1 for left |
||
302 | * |
||
303 | * @return int|null Move action if module can be moved, calls |
||
304 | * handle_after_move() if it can't be moved |
||
305 | */ |
||
306 | 11 | public function get_horizontal_move_action($module_data, $direction) |
|
322 | |||
323 | /** |
||
324 | * Delete module |
||
325 | * |
||
326 | * @param int|string $id Module ID of the acp_portal module |
||
327 | * @param string $mode Mode of the acp_portal module |
||
328 | * @param string $action Current action of the acp_portal module |
||
329 | * @param int $module_id ID of the module that should be deleted |
||
330 | */ |
||
331 | 1 | public function module_delete($id, $mode, $action, $module_id) |
|
332 | { |
||
333 | 1 | $module_data = $this->get_move_module_data($module_id); |
|
334 | |||
335 | 1 | if ($module_data !== false) |
|
336 | 1 | { |
|
337 | 1 | $module_classname = $this->request->variable('module_classname', ''); |
|
338 | |||
339 | 1 | $this->get_module($module_data['module_classname']); |
|
340 | |||
341 | 1 | if (confirm_box(true)) |
|
342 | 1 | { |
|
343 | 1 | $this->module->uninstall($module_data['module_id'], $this->db); |
|
344 | |||
345 | 1 | $sql = 'DELETE FROM ' . PORTAL_MODULES_TABLE . ' |
|
346 | 1 | WHERE module_id = ' . (int) $module_id; |
|
347 | 1 | $this->db->sql_query($sql); |
|
348 | |||
349 | 1 | $sql = 'UPDATE ' . PORTAL_MODULES_TABLE . ' |
|
350 | SET module_order = module_order - 1 |
||
351 | 1 | WHERE module_column = ' . (int) $module_data['module_column'] . ' |
|
352 | 1 | AND module_order > ' . (int) $module_data['module_order']; |
|
353 | 1 | $this->db->sql_query($sql); |
|
354 | |||
355 | 1 | $this->cache->purge(); // make sure we don't get errors after re-adding a module |
|
356 | |||
357 | // Handle ajax request |
||
358 | 1 | $this->handle_ajax_request(array( |
|
359 | 1 | 'success' => true, |
|
360 | 1 | 'MESSAGE_TITLE' => $this->user->lang['INFORMATION'], |
|
361 | 1 | 'MESSAGE_TEXT' => $this->user->lang['SUCCESS_DELETE'], |
|
362 | 1 | )); |
|
363 | |||
364 | 1 | trigger_error($this->user->lang['SUCCESS_DELETE'] . adm_back_link($this->u_action)); |
|
365 | 1 | } |
|
366 | else |
||
367 | { |
||
368 | 1 | if ($this->module->get_language()) |
|
369 | 1 | { |
|
370 | 1 | $this->controller_helper->load_module_language($this->module); |
|
371 | 1 | } |
|
372 | 1 | $confirm_text = (isset($this->user->lang[$module_data['module_name']])) ? sprintf($this->user->lang['DELETE_MODULE_CONFIRM'], $this->user->lang[$module_data['module_name']]) : sprintf($this->user->lang['DELETE_MODULE_CONFIRM'], utf8_normalize_nfc($module_data['module_name'])); |
|
373 | 1 | confirm_box(false, $confirm_text, build_hidden_fields(array( |
|
374 | 1 | 'i' => $id, |
|
375 | 1 | 'mode' => $mode, |
|
376 | 1 | 'action' => $action, |
|
377 | 1 | 'module_id' => $module_id, |
|
378 | 1 | 'module_classname' => $module_classname, |
|
379 | 1 | ))); |
|
380 | } |
||
381 | 1 | } |
|
382 | |||
383 | 1 | $this->cache->destroy('sql', PORTAL_MODULES_TABLE); |
|
384 | 1 | } |
|
385 | |||
386 | /** |
||
387 | * Get link to module settings with specified ID and portal_module mode |
||
388 | * |
||
389 | * @param string $mode portal_module mode |
||
390 | * @param int $module_id Module ID |
||
391 | * |
||
392 | * @return string Link to module settings |
||
393 | */ |
||
394 | 4 | public function get_module_link($mode, $module_id) |
|
398 | } |
||
399 |
If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:
If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.