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

ucp_controller   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 71
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 1
dl 0
loc 71
ccs 25
cts 25
cp 1
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 7 1
A get_page_title() 0 4 1
A main() 0 18 2
A set_page_url() 0 4 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\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 5
	public function __construct(\phpbb\ads\ad\manager $manager, \phpbb\user $user, \phpbb\template\template $template, \phpbb\config\config $config)
42
	{
43 5
		$this->manager = $manager;
44 5
		$this->user = $user;
45 5
		$this->template = $template;
46 5
		$this->config = $config;
47 5
	}
48
49
	/**
50
	 * @param	string	$u_action	Action URL
51
	 */
52 5
	public function set_page_url($u_action)
53
	{
54 5
		$this->u_action = $u_action;
55 5
	}
56
57
	/**
58
	 * @return	string	Module language string
59
	 */
60 1
	public function get_page_title()
61
	{
62 1
		return $this->user->lang('UCP_PHPBB_ADS_STATS');
63
	}
64
65
	/**
66
	 * Display UCP ads module
67
	 */
68 4
	public function main()
69
	{
70 4
		$this->user->add_lang_ext('phpbb/ads', 'ucp');
71
72 4
		foreach ($this->manager->get_ads_by_owner($this->user->data['user_id']) as $ad)
73
		{
74 1
			$this->template->assign_block_vars('ads', array(
75 1
				'NAME'		=> $ad['ad_name'],
76 1
				'VIEWS'		=> $ad['ad_views'],
77 1
				'CLICKS'	=> $ad['ad_clicks'],
78 1
			));
79 4
		}
80
81 4
		$this->template->assign_vars(array(
82 4
			'S_VIEWS_ENABLED'	=> $this->config['phpbb_ads_enable_views'],
83 4
			'S_CLICKS_ENABLED'	=> $this->config['phpbb_ads_enable_clicks'],
84 4
		));
85 4
	}
86
}
87