Passed
Branch master (d4fa65)
by Matt
15:12 queued 12:46
created

ucp_controller::get_page_title()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 3
rs 10
ccs 2
cts 2
cp 1
crap 1
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
/**
14
 * Front controller
15
 */
16
class ucp_controller
17
{
18
	/** @var \phpbb\ads\ad\manager */
19
	protected $manager;
20
21
	/** @var \phpbb\ads\controller\helper */
22
	protected $helper;
23
24
	/** @var \phpbb\user */
0 ignored issues
show
Bug introduced by
The type phpbb\user 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...
25
	protected $user;
26
27
	/** @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...
28
	protected $language;
29
30
	/** @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...
31
	protected $template;
32
33
	/** @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...
34
	protected $config;
35
36
	/** @var string Custom form action */
37
	protected $u_action;
38
39
	/**
40
	 * Constructor
41
	 *
42
	 * @param \phpbb\ads\ad\manager					$manager 	Advertisement manager object
43
	 * @param \phpbb\ads\controller\helper			$helper		Helper object
44
	 * @param \phpbb\user							$user		User object
45
	 * @param \phpbb\language\language				$language	Language object
46
	 * @param \phpbb\template\template				$template	Template object
47
	 * @param \phpbb\config\config					$config		Config object
48
	 */
49 5
	public function __construct(\phpbb\ads\ad\manager $manager, \phpbb\ads\controller\helper $helper, \phpbb\user $user, \phpbb\language\language $language, \phpbb\template\template $template, \phpbb\config\config $config)
50
	{
51 5
		$this->manager = $manager;
52 5
		$this->helper = $helper;
53 5
		$this->user = $user;
54 5
		$this->language = $language;
55 5
		$this->template = $template;
56 5
		$this->config = $config;
57 5
	}
58
59
	/**
60
	 * @param	string	$u_action	Action URL
61
	 */
62 5
	public function set_page_url($u_action)
63
	{
64 5
		$this->u_action = $u_action;
65 5
	}
66
67
	/**
68
	 * @return	string	Module language string
69
	 */
70 1
	public function get_page_title()
71
	{
72 1
		return $this->language->lang('UCP_PHPBB_ADS_STATS');
73
	}
74
75
	/**
76
	 * Display UCP ads module
77
	 */
78 4
	public function main()
79
	{
80 4
		$this->language->add_lang('ucp', 'phpbb/ads');
81
82 4
		foreach ($this->manager->get_ads_by_owner($this->user->data['user_id']) as $ad)
83
		{
84 1
			$ad_enabled = (int) $ad['ad_enabled'];
85 1
			$ad_expired = $this->helper->is_expired($ad);
86
87 1
			if ($ad_expired && $ad_enabled)
88 1
			{
89
				$ad_enabled = 0;
90
				$this->manager->update_ad($ad['ad_id'], array('ad_enabled' => 0));
91
			}
92
93 1
			$this->template->assign_block_vars($ad_expired ? 'expired' : 'ads', array(
94 1
				'NAME'			=> $ad['ad_name'],
95 1
				'START_DATE'	=> $ad['ad_start_date'],
96 1
				'END_DATE'		=> $ad['ad_end_date'],
97 1
				'VIEWS'			=> $ad['ad_views'],
98 1
				'VIEWS_LIMIT'	=> $ad['ad_views_limit'],
99 1
				'CLICKS'		=> $ad['ad_clicks'],
100 1
				'CLICKS_LIMIT'	=> $ad['ad_clicks_limit'],
101 1
				'S_ENABLED'		=> $ad_enabled,
102 1
			));
103 4
		}
104
105 4
		$this->template->assign_vars(array(
106 4
			'S_VIEWS_ENABLED'	=> $this->config['phpbb_ads_enable_views'],
107 4
			'S_CLICKS_ENABLED'	=> $this->config['phpbb_ads_enable_clicks'],
108 4
		));
109 4
	}
110
}
111