Completed
Pull Request — master (#48)
by Jakub
10:59
created

ucp_controller::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 7
ccs 0
cts 7
cp 0
rs 9.4285
cc 1
eloc 5
nc 1
nop 4
crap 2
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\user */
22
	protected $user;
23
24
	/** @var \phpbb\template\template */
25
	protected $template;
26
27
	/** @var \phpbb\config\config */
28
	protected $config;
29
30
	/** @var string Custom form action */
31
	protected $u_action;
32
33
	/**
34
	 * Constructor
35
	 *
36
	 * @param \phpbb\ads\ad\manager		$manager 	Advertisement manager object
37
	 * @param \phpbb\user				$user		User object
38
	 * @param \phpbb\template\template	$template	Template object
39
	 * @param \phpbb\config\config		$config		Config object
40
	 */
41
	public function __construct(\phpbb\ads\ad\manager $manager, \phpbb\user $user, \phpbb\template\template $template, \phpbb\config\config $config)
42
	{
43
		$this->manager = $manager;
44
		$this->user = $user;
45
		$this->template = $template;
46
		$this->config = $config;
47
	}
48
49
	/**
50
	 * @param	string	$u_action	Action URL
51
	 */
52
	public function set_page_url($u_action)
53
	{
54
		$this->u_action = $u_action;
55
	}
56
57
	/**
58
	 * @return	string	Module language string
59
	 */
60
	public function get_page_title()
61
	{
62
		return $this->user->lang('UCP_PHPBB_ADS_STATS');
63
	}
64
65
	/**
66
	 * Display UCP ads module
67
	 */
68
	public function main()
69
	{
70
		$this->user->add_lang_ext('phpbb/ads', 'ucp');
71
72
		foreach ($this->manager->get_ads_by_owner($this->user->data['user_id']) as $ad)
73
		{
74
			$this->template->assign_block_vars('ads', array(
75
				'NAME'		=> $ad['ad_name'],
76
				'VIEWS'		=> $ad['ad_views'],
77
				'CLICKS'	=> $ad['ad_clicks'],
78
			));
79
		}
80
81
		$this->template->assign_vars(array(
82
			'S_VIEWS_ENABLED'	=> $this->config['phpbb_ads_enable_views'],
83
			'S_CLICKS_ENABLED'	=> $this->config['phpbb_ads_enable_clicks'],
84
		));
85
	}
86
}
87