Completed
Pull Request — master (#2)
by Jakub
05:07
created

admin_controller   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 117
Duplicated Lines 0 %

Coupling/Cohesion

Components 3
Dependencies 0

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 8
c 0
b 0
f 0
lcom 3
cbo 0
dl 0
loc 117
ccs 0
cts 47
cp 0
rs 10

6 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 8 1
A set_page_url() 0 4 1
A load_lang() 0 4 1
A get_page_title() 0 4 1
A get_action() 0 4 1
B list_ads() 0 26 3
1
<?php
2
/**
3
*
4
* Pages extension for the phpBB Forum Software package.
5
*
6
* @copyright (c) 2014 phpBB Limited <https://www.phpbb.com>
7
* @license GNU General Public License, version 2 (GPL-2.0)
8
*
9
*/
10
11
namespace phpbb\admanagement\controller;
12
13
/**
14
* Admin controller
15
*/
16
class admin_controller
17
{
18
	/** @var \phpbb\db\driver\driver_interface */
19
	protected $db;
20
21
	/** @var \phpbb\template\template */
22
	protected $template;
23
24
	/** @var \phpbb\user */
25
	protected $user;
26
27
	/** @var \phpbb\request\request */
28
	protected $request;
29
30
	/** @var string ads_table */
31
	protected $ads_table;
32
33
	/** @var string Custom form action */
34
	protected $u_action;
35
36
	/**
37
	* Constructor
38
	*
39
	* @param \phpbb\db\driver\driver_interface	$db			DB driver interface
40
	* @param \phpbb\template\template			$template	Template object
41
	* @param \phpbb\user						$user		User object
42
	* @param \phpbb\request\request				$request	Request object
43
	* @param string								$ads_table	Ads table
44
	* @access public
45
	*/
46
	public function __construct(\phpbb\db\driver\driver_interface $db, \phpbb\template\template $template, \phpbb\user $user, \phpbb\request\request $request, $ads_table)
47
	{
48
		$this->db = $db;
49
		$this->template = $template;
50
		$this->user = $user;
51
		$this->request = $request;
52
		$this->ads_table = $ads_table;
53
	}
54
55
	/**
56
	* Set page url
57
	*
58
	* @param string $u_action Custom form action
59
	* @return void
60
	* @access public
61
	*/
62
	public function set_page_url($u_action)
63
	{
64
		$this->u_action = $u_action;
65
	}
66
67
	/**
68
	* Load module-specific language
69
	*
70
	* @return void
71
	* @access public
72
	*/
73
	public function load_lang()
74
	{
75
		$this->user->add_lang_ext('phpbb/admanagement', 'acp');
76
	}
77
78
	/**
79
	* Get geric ACP page title for Ads module
80
	*
81
	* @return string	Language string for Ads ACP module
82
	* @access public
83
	*/
84
	public function get_page_title()
85
	{
86
		return $this->user->lang('ACP_ADMANAGEMENT_TITLE');
87
	}
88
89
	/**
90
	* Get action
91
	*
92
	* @return string	Language string for Ads ACP module
93
	* @access public
94
	*/
95
	public function get_action()
96
	{
97
		return $this->request->variable('action', '');
98
	}
99
100
	/**
101
	* Display the ads
102
	*
103
	* @return void
104
	* @access public
105
	*/
106
	public function list_ads()
107
	{
108
		$sql = 'SELECT ad_id, ad_name, ad_enabled
109
			FROM ' . $this->ads_table;
110
		$result = $this->db->sql_query($sql);
111
		while ($row = $this->db->sql_fetchrow($result))
112
		{
113
			$ad_enabled = (bool) $row['ad_enabled'];
114
115
			$this->template->assign_block_vars('ads', [
116
				'NAME'		=> $row['ad_name'],
117
				'S_ENABLED'	=> $ad_enabled,
118
				'U_ENABLE'	=> $this->u_action . '&amp;action=' . ($ad_enabled ? 'disable' : 'enable') . '&amp;id=' . $row['ad_id'], // TODO: ACP method
119
				'U_PREVIEW'	=> '', // TODO: frontend logic
120
				'U_EDIT'	=> $this->u_action . '&amp;action=edit&amp;id=' . $row['ad_id'], // TODO: ACP method
121
				'U_DELETE'	=> $this->u_action . '&amp;action=delete&amp;id=' . $row['ad_id'], // TODO: ACP method
122
			]);
123
		}
124
		$this->db->sql_freeresult($result);
125
126
		// Set output vars for display in the template
127
		$this->template->assign_vars(array(
128
			'U_ACTION'	=> $this->u_action,
129
			'U_ADD_AD'	=> $this->u_action . '&amp;action=add',
130
		));
131
	}
132
}
133