admin_controller::__construct()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 23
Code Lines 16

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 19
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 16
c 1
b 0
f 0
nc 2
nop 12
dl 0
loc 23
rs 9.7333
ccs 19
cts 19
cp 1
crap 2

How to fix   Many Parameters   

Many Parameters

Methods with many parameters are not only hard to understand, but their parameters also often become inconsistent when you need more, or different data.

There are several approaches to avoid long parameter lists:

1
<?php
2
/**
3
 *
4
 * Advertisement management. An extension for the phpBB Forum Software package.
5
 *
6
 * @copyright (c) 2017 phpBB Limited <https://www.phpbb.com>
7
 * @license GNU General Public License, version 2 (GPL-2.0)
8
 *
9
 */
10
11
namespace phpbb\ads\controller;
12
13
use phpbb\ads\ext;
14
15
/**
16
* Admin controller
17
*/
18
class admin_controller
19
{
20
	/** @var array Form data */
21
	protected $data = array();
22
23
	/** @var \phpbb\template\template */
0 ignored issues
show
Bug introduced by
The type phpbb\template\template was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
24
	protected $template;
25
26
	/** @var \phpbb\language\language */
0 ignored issues
show
Bug introduced by
The type phpbb\language\language was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
27
	protected $language;
28
29
	/** @var \phpbb\request\request */
0 ignored issues
show
Bug introduced by
The type phpbb\request\request was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
30
	protected $request;
31
32
	/** @var \phpbb\ads\ad\manager */
33
	protected $manager;
34
35
	/** @var \phpbb\config\db_text */
0 ignored issues
show
Bug introduced by
The type phpbb\config\db_text was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
36
	protected $config_text;
37
38
	/** @var \phpbb\config\config */
0 ignored issues
show
Bug introduced by
The type phpbb\config\config was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
39
	protected $config;
40
41
	/** @var \phpbb\ads\controller\admin_input */
42
	protected $input;
43
44
	/** @var \phpbb\ads\controller\helper */
45
	protected $helper;
46
47
	/** @var \phpbb\ads\analyser\manager */
48
	protected $analyser;
49
50
	/** @var \phpbb\controller\helper */
0 ignored issues
show
Bug introduced by
The type phpbb\controller\helper was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
51
	protected $controller_helper;
52
53
	/** @var string Custom form action */
54
	protected $u_action;
55
56
	/** @var \auth_admin Auth admin */
0 ignored issues
show
Bug introduced by
The type auth_admin was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
57
	protected $auth_admin;
58
59
	/**
60
	 * Constructor
61
	 *
62
	 * @param \phpbb\template\template          $template          Template object
63
	 * @param \phpbb\language\language          $language          Language object
64
	 * @param \phpbb\request\request            $request           Request object
65
	 * @param \phpbb\ads\ad\manager             $manager           Advertisement manager object
66
	 * @param \phpbb\config\db_text             $config_text       Config text object
67
	 * @param \phpbb\config\config              $config            Config object
68
	 * @param \phpbb\ads\controller\admin_input $input             Admin input object
69
	 * @param \phpbb\ads\controller\helper      $helper            Helper object
70
	 * @param \phpbb\ads\analyser\manager       $analyser          Ad code analyser object
71
	 * @param \phpbb\controller\helper          $controller_helper Controller helper object
72
	 * @param string                            $root_path         phpBB root path
73
	 * @param string                            $php_ext           PHP extension
74
	 */
75 37
	public function __construct(\phpbb\template\template $template, \phpbb\language\language $language, \phpbb\request\request $request, \phpbb\ads\ad\manager $manager, \phpbb\config\db_text $config_text, \phpbb\config\config $config, \phpbb\ads\controller\admin_input $input, \phpbb\ads\controller\helper $helper, \phpbb\ads\analyser\manager $analyser, \phpbb\controller\helper $controller_helper, $root_path, $php_ext)
76
	{
77 37
		$this->template = $template;
78 37
		$this->language = $language;
79 37
		$this->request = $request;
80 37
		$this->manager = $manager;
81 37
		$this->config_text = $config_text;
82 37
		$this->config = $config;
83 37
		$this->input = $input;
84 37
		$this->helper = $helper;
85 37
		$this->analyser = $analyser;
86 37
		$this->controller_helper = $controller_helper;
87
88 37
		$this->language->add_lang('posting'); // Used by banner_upload() file errors
89 37
		$this->language->add_lang('acp', 'phpbb/ads');
90
91 37
		$this->template->assign_var('S_PHPBB_ADS', true);
92
93 37
		if (!class_exists('auth_admin'))
94 37
		{
95 1
			include($root_path . 'includes/acp/auth.' . $php_ext);
96 1
		}
97 37
		$this->auth_admin = new \auth_admin();
98 37
	}
99
100
	/**
101
	 * Set page url
102
	 *
103
	 * @param	string	$u_action	Custom form action
104
	 * @return	void
105
	 */
106 31
	public function set_page_url($u_action)
107
	{
108 31
		$this->u_action = $u_action;
109 31
	}
110
111
	/**
112
	 * Process user request for settings mode
113
	 *
114
	 * @return	void
115
	 */
116 1
	public function mode_settings()
117
	{
118 1
		if ($this->request->is_set_post('submit'))
119
		{
120
			// Validate form key
121
			if (check_form_key('phpbb_ads'))
0 ignored issues
show
Bug introduced by
The function check_form_key was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

121
			if (/** @scrutinizer ignore-call */ check_form_key('phpbb_ads'))
Loading history...
122
			{
123
				$this->config->set('phpbb_ads_adblocker_message', $this->request->variable('adblocker_message', 0));
124
				$this->config->set('phpbb_ads_enable_views', $this->request->variable('enable_views', 0));
125
				$this->config->set('phpbb_ads_enable_clicks', $this->request->variable('enable_clicks', 0));
126 3
127
				$this->success('ACP_AD_SETTINGS_SAVED');
128 3
			}
129 3
130
			$this->error('FORM_INVALID');
131 2
		}
132 2
133 1
		$this->template->assign_vars(array(
134 1
			'U_ACTION'          => $this->u_action,
135 1
			'AD_BLOCK_MODES'	=> ext::AD_BLOCK_MODES,
136
			'AD_BLOCK_CONFIG'	=> $this->config['phpbb_ads_adblocker_message'],
137 1
			'ENABLE_VIEWS'      => $this->config['phpbb_ads_enable_views'],
138
			'ENABLE_CLICKS'     => $this->config['phpbb_ads_enable_clicks'],
139
		));
140 1
	}
141
142
	/**
143 1
	 * Process user request for manage mode
144 1
	 *
145 1
	 * @return	void
146 1
	 */
147 1
	public function mode_manage()
148 1
	{
149 1
		// Trigger specific action
150
		$action = $this->request->variable('action', '');
151
		if (in_array($action, array('add', 'edit', 'enable', 'disable', 'delete')))
152
		{
153
			$this->{'action_' . $action}();
154
		}
155
		else
156 33
		{
157
			// Otherwise default to this
158
			$this->list_ads();
159 33
		}
160 33
	}
161 33
162 31
	/**
163 16
	 * Add an advertisement
164
	 *
165
	 * @return	void
166
	 */
167 2
	protected function action_add()
168
	{
169 18
		$action = $this->get_submitted_action();
170
		if ($action !== false)
171
		{
172
			$this->data = $this->input->get_form_data();
173
			$this->{$action}();
174
			$this->helper->assign_data($this->data, $this->input->get_errors());
175
		}
176 21
		else
177
		{
178 8
			$this->helper->assign_locations();
179 8
			$this->helper->assign_groups();
180 8
		}
181 7
182 7
		// Set output vars for display in the template
183 5
		$this->template->assign_vars(array(
184 5
			'S_ADD_AD'				=> true,
185
			'U_BACK'				=> $this->u_action,
186
			'U_ACTION'				=> "{$this->u_action}&amp;action=add",
187 1
			'PICKER_DATE_FORMAT'	=> ext::DATE_FORMAT,
188 1
			'U_FIND_USERNAME'		=> $this->helper->get_find_username_link(),
189
			'U_ENABLE_VISUAL_DEMO'	=> $this->controller_helper->route('phpbb_ads_visual_demo', array('action' => 'enable')),
190
		));
191
	}
192 6
193 6
	/**
194 6
	 * Edit an advertisement
195 6
	 *
196 6
	 * @return	void
197 21
	 */
198 6
	protected function action_edit()
199 6
	{
200 6
		$ad_id = $this->request->variable('id', 0);
201
		$action = $this->get_submitted_action();
202
		if ($action !== false)
203
		{
204
			$this->data = $this->input->get_form_data();
205
			$this->{$action}();
206
		}
207 8
		else
208
		{
209 8
			$this->data = $this->manager->get_ad($ad_id);
210 8
			if (empty($this->data))
211 8
			{
212 8
				$this->error('ACP_AD_DOES_NOT_EXIST');
213 6
			}
214 6
			// Load ad template locations
215 3
			$this->data['ad_locations'] = $this->manager->get_ad_locations($ad_id);
216
		}
217
218 2
		// Set output vars for display in the template
219 2
		$this->template->assign_vars(array(
220 2
			'S_EDIT_AD'				=> true,
221 1
			'EDIT_ID'				=> $ad_id,
222
			'U_BACK'				=> $this->u_action,
223
			'U_ACTION'				=> "{$this->u_action}&amp;action=edit&amp;id=$ad_id",
224 1
			'PICKER_DATE_FORMAT'	=> ext::DATE_FORMAT,
225
			'U_FIND_USERNAME'		=> $this->helper->get_find_username_link(),
226
			'U_ENABLE_VISUAL_DEMO'	=> $this->controller_helper->route('phpbb_ads_visual_demo', array('action' => 'enable')),
227
		));
228 4
		$this->helper->assign_data($this->data, $this->input->get_errors());
229 4
	}
230 4
231 4
	/**
232 4
	 * Enable an advertisement
233 4
	 *
234 4
	 * @return	void
235 4
	 */
236 4
	protected function action_enable()
237 4
	{
238 4
		$this->ad_enable(true);
239
	}
240
241
	/**
242
	 * Disable an advertisement
243
	 *
244
	 * @return	void
245 4
	 */
246
	protected function action_disable()
247 4
	{
248 1
		$this->ad_enable(false);
249
	}
250
251
	/**
252
	 * Delete an advertisement
253
	 *
254
	 * @return	void
255 4
	 */
256
	protected function action_delete()
257 4
	{
258 1
		$ad_id = $this->request->variable('id', 0);
259
		if ($ad_id)
260
		{
261
			if (confirm_box(true))
0 ignored issues
show
Bug introduced by
The function confirm_box was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

261
			if (/** @scrutinizer ignore-call */ confirm_box(true))
Loading history...
262
			{
263
				// Get ad data so that we can log ad name
264
				$ad_data = $this->manager->get_ad($ad_id);
265 4
266
				// Delete ad and it's template locations
267 4
				$this->manager->delete_ad_locations($ad_id);
268
				$success = $this->manager->delete_ad($ad_id);
269 4
270 4
				$this->toggle_permission($ad_data['ad_owner']);
271 4
272
				// Only notify user on error or if not ajax
273 3
				if (!$success)
274
				{
275
					$this->error('ACP_AD_DELETE_ERRORED');
276 3
				}
277 3
				else
278
				{
279 3
					$this->helper->log('DELETE', $ad_data['ad_name']);
280
281
					if (!$this->request->is_ajax())
282 3
					{
283 3
						$this->success('ACP_AD_DELETE_SUCCESS');
284 1
					}
285
				}
286
			}
287
			else
288 2
			{
289
				confirm_box(false, $this->language->lang('CONFIRM_OPERATION'), build_hidden_fields(array(
0 ignored issues
show
Bug introduced by
The function build_hidden_fields was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

289
				confirm_box(false, $this->language->lang('CONFIRM_OPERATION'), /** @scrutinizer ignore-call */ build_hidden_fields(array(
Loading history...
290 2
					'id'     => $ad_id,
291 2
					'i'      => $this->request->variable('i', ''),
292 2
					'mode'   => $this->request->variable('mode', ''),
293
					'action' => 'delete',
294
				)));
295
296
				// When you don't confirm deleting ad
297
				$this->list_ads();
298 1
			}
299 1
		}
300 1
	}
301 1
302 1
	/**
303 1
	 * Display the list of all ads
304
	 *
305
	 * @return	void
306 1
	 */
307
	protected function list_ads()
308 1
	{
309 1
		foreach ($this->manager->get_all_ads() as $row)
310
		{
311
			$ad_enabled = (int) $row['ad_enabled'];
312
			$ad_expired = $this->helper->is_expired($row);
313
314
			if ($ad_expired && $ad_enabled)
315
			{
316 2
				$ad_enabled = 0;
317
				$this->manager->update_ad($row['ad_id'], array('ad_enabled' => 0));
318 2
			}
319
320 1
			$this->template->assign_block_vars($ad_expired ? 'expired' : 'ads', array(
321 1
				'NAME'         => $row['ad_name'],
322
				'PRIORITY'     => $row['ad_priority'],
323 1
				'START_DATE'   => $row['ad_start_date'],
324 1
				'END_DATE'     => $row['ad_end_date'],
325 1
				'VIEWS'        => $row['ad_views'],
326 1
				'CLICKS'       => $row['ad_clicks'],
327 1
				'VIEWS_LIMIT'  => $row['ad_views_limit'],
328
				'CLICKS_LIMIT' => $row['ad_clicks_limit'],
329 1
				'S_EXPIRED'    => $ad_expired,
330 1
				'S_ENABLED'    => $ad_enabled,
331 1
				'U_ENABLE'     => $this->u_action . '&amp;action=' . ($ad_enabled ? 'disable' : 'enable') . '&amp;id=' . $row['ad_id'],
332 1
				'U_EDIT'       => $this->u_action . '&amp;action=edit&amp;id=' . $row['ad_id'],
333 1
				'U_DELETE'     => $this->u_action . '&amp;action=delete&amp;id=' . $row['ad_id'],
334 1
			));
335 1
		}
336 1
337 1
		// Set output vars for display in the template
338 1
		$this->template->assign_vars(array(
339 1
			'U_ACTION_ADD'     => $this->u_action . '&amp;action=add',
340 1
			'S_VIEWS_ENABLED'  => $this->config['phpbb_ads_enable_views'],
341 1
			'S_CLICKS_ENABLED' => $this->config['phpbb_ads_enable_clicks'],
342 1
		));
343 1
	}
344 2
345
	/**
346
	 * Get what action user wants to do with the form.
347 2
	 * Possible options are:
348 2
	 *  - preview ad code
349 2
	 *  - upload banner to display in an ad code
350 2
	 *  - analyse ad code
351 2
	 *  - submit form (either add or edit an ad)
352 2
	 *
353
	 * @return	string|false	Action name or false when no action was submitted
354
	 */
355
	protected function get_submitted_action()
356
	{
357
		$actions = array('preview', 'upload_banner', 'analyse_ad_code', 'submit_add', 'submit_edit');
358
		foreach ($actions as $action)
359
		{
360
			if ($this->request->is_set_post($action))
361
			{
362
				return $action;
363
			}
364 16
		}
365
366 16
		return false;
367 16
	}
368
369 16
	/**
370 16
	 * Enable/disable an advertisement
371 13
	 *
372
	 * @param	bool	$enable	Enable or disable the advertisement?
373 14
	 * @return	void
374
	 */
375 3
	protected function ad_enable($enable)
376
	{
377
		$ad_id = $this->request->variable('id', 0);
378
379
		$success = $this->manager->update_ad($ad_id, array(
380
			'ad_enabled' => (int) $enable,
381
		));
382
383
		// If AJAX was used, show user a result message
384 6
		if ($this->request->is_ajax())
385
		{
386 6
			$json_response = new \phpbb\json_response;
0 ignored issues
show
Bug introduced by
The type phpbb\json_response was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
387
			$json_response->send(array(
388 6
				'text'  => $this->language->lang($enable ? 'ENABLED' : 'DISABLED'),
389 6
				'title' => $this->language->lang('AD_ENABLE_TITLE', (int) $enable),
390 6
			));
391
		}
392
393 6
		// Otherwise, show traditional infobox
394 6
		if ($success)
395 2
		{
396 2
			$this->success($enable ? 'ACP_AD_ENABLE_SUCCESS' : 'ACP_AD_DISABLE_SUCCESS');
397 2
		}
398 2
		else
399 2
		{
400
			$this->error($enable ? 'ACP_AD_ENABLE_ERRORED' : 'ACP_AD_DISABLE_ERRORED');
401
		}
402
	}
403
404 4
	/**
405 2
	 * Submit action "preview".
406
	 * Prepare advertisement preview.
407
	 *
408
	 * @return	void
409 2
	 */
410
	protected function preview()
411
	{
412
		$this->template->assign_var('PREVIEW', htmlspecialchars_decode($this->data['ad_code'], ENT_COMPAT));
413
	}
414
415
	/**
416
	 * Submit action "upload_banner".
417
	 * Upload banner and append it to the ad code.
418
	 *
419 2
	 * @return	void
420
	 */
421 2
	protected function upload_banner()
422 2
	{
423
		$this->data['ad_code'] = $this->input->banner_upload($this->data['ad_code']);
424
	}
425
426
	/**
427
	 * Submit action "analyse_ad_code".
428
	 * Upload banner and append it to the ad code.
429
	 *
430 1
	 * @return	void
431
	 */
432 1
	protected function analyse_ad_code()
433 1
	{
434
		$this->analyser->run($this->data['ad_code']);
435
	}
436
437
	/**
438
	 * Submit action "submit_add".
439
	 * Add new ad.
440
	 *
441 1
	 * @return	void
442
	 */
443 1
	protected function submit_add()
444 1
	{
445
		if (!$this->input->has_errors())
446
		{
447
			$ad_id = $this->manager->insert_ad($this->data);
448
			$this->toggle_permission($this->data['ad_owner']);
449
			$this->manager->insert_ad_locations($ad_id, $this->data['ad_locations']);
450
451
			$this->helper->log('ADD', $this->data['ad_name']);
452 4
453
			$this->success('ACP_AD_ADD_SUCCESS');
454 4
		}
455 4
	}
456 2
457 2
	/**
458 2
	 * Submit action "submit_edit".
459
	 * Edit ad.
460 2
	 *
461
	 * @return	void
462 2
	 */
463
	protected function submit_edit()
464 2
	{
465
		$ad_id = $this->request->variable('id', 0);
466
		if ($ad_id && !$this->input->has_errors())
467
		{
468
			$old_data = $this->manager->get_ad($ad_id);
469
			$success = $this->manager->update_ad($ad_id, $this->data);
470
			if ($success)
471
			{
472 5
				// Only update permissions when update was successful
473
				$this->toggle_permission($old_data['ad_owner']);
474 5
				$this->toggle_permission($this->data['ad_owner']);
475 5
476 5
				// Only insert new ad locations to DB when ad exists
477 3
				$this->manager->delete_ad_locations($ad_id);
478 3
				$this->manager->insert_ad_locations($ad_id, $this->data['ad_locations']);
479
480 3
				$this->helper->log('EDIT', $this->data['ad_name']);
481
482 2
				$this->success('ACP_AD_EDIT_SUCCESS');
483 2
			}
484
485
			$this->error('ACP_AD_DOES_NOT_EXIST');
486 2
		}
487 2
	}
488
489 2
	/**
490
	 * Print success message.
491 2
	 *
492
	 * @param	string	$msg	Message lang key
493
	 */
494 1
	protected function success($msg)
495
	{
496 2
		trigger_error($this->language->lang($msg) . adm_back_link($this->u_action));
0 ignored issues
show
Bug introduced by
The function adm_back_link was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

496
		trigger_error($this->language->lang($msg) . /** @scrutinizer ignore-call */ adm_back_link($this->u_action));
Loading history...
497
	}
498
499
	/**
500
	 * Print error message.
501
	 *
502
	 * @param	string	$msg	Message lang key
503 9
	 */
504
	protected function error($msg)
505 9
	{
506
		trigger_error($this->language->lang($msg) . adm_back_link($this->u_action), E_USER_WARNING);
0 ignored issues
show
Bug introduced by
The function adm_back_link was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

506
		trigger_error($this->language->lang($msg) . /** @scrutinizer ignore-call */ adm_back_link($this->u_action), E_USER_WARNING);
Loading history...
507
	}
508
509
	/**
510
	 * Try to remove or add permission to see UCP module.
511
	 * Permission is only removed when user has no more ads.
512
	 * Permission is only added when user has at least one ad.
513 6
	 *
514
	 * @param	int	$user_id	User ID to try to remove permission
515 6
	 *
516
	 * @return	void
517
	 */
518
	protected function toggle_permission($user_id)
519
	{
520
		if ($user_id)
521
		{
522
			$has_ads = count($this->manager->get_ads_by_owner($user_id)) !== 0;
523
524
			$this->auth_admin->acl_set('user', 0, $user_id, array('u_phpbb_ads' => (int) $has_ads));
525
		}
526
	}
527
}
528