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
|
|
|
use Symfony\Component\DependencyInjection\ContainerInterface; |
14
|
|
|
|
15
|
|
|
/** |
16
|
|
|
* Admin controller |
17
|
|
|
*/ |
18
|
|
|
class admin_controller |
19
|
|
|
{ |
20
|
|
|
/** @var \phpbb\db\driver\driver_interface */ |
21
|
|
|
protected $db; |
22
|
|
|
|
23
|
|
|
/** @var \phpbb\template\template */ |
24
|
|
|
protected $template; |
25
|
|
|
|
26
|
|
|
/** @var \phpbb\user */ |
27
|
|
|
protected $user; |
28
|
|
|
|
29
|
|
|
/** @var \phpbb\request\request */ |
30
|
|
|
protected $request; |
31
|
|
|
|
32
|
|
|
/** @var string ads_table */ |
33
|
|
|
protected $ads_table; |
34
|
|
|
|
35
|
|
|
/** @var string Custom form action */ |
36
|
|
|
protected $u_action; |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* Constructor |
40
|
|
|
* |
41
|
|
|
* @param \phpbb\db\driver\driver_interface $db DB driver interface |
42
|
|
|
* @param \phpbb\template\template $template Template object |
43
|
|
|
* @param \phpbb\user $user User object |
44
|
|
|
* @param \phpbb\request\request $request Request object |
45
|
|
|
* @param string $ads_table Ads table |
46
|
|
|
* @access public |
47
|
|
|
*/ |
48
|
|
|
public function __construct(\phpbb\db\driver\driver_interface $db, \phpbb\template\template $template, \phpbb\user $user, \phpbb\request\request $request, $ads_table) |
49
|
|
|
{ |
50
|
|
|
$this->db = $db; |
51
|
|
|
$this->template = $template; |
52
|
|
|
$this->user = $user; |
53
|
|
|
$this->request = $request; |
54
|
|
|
$this->ads_table = $ads_table; |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
/** |
58
|
|
|
* Set page url |
59
|
|
|
* |
60
|
|
|
* @param string $u_action Custom form action |
61
|
|
|
* @return void |
62
|
|
|
* @access public |
63
|
|
|
*/ |
64
|
|
|
public function set_page_url($u_action) |
65
|
|
|
{ |
66
|
|
|
$this->u_action = $u_action; |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
/** |
70
|
|
|
* Get geric ACP page title for Ads module |
71
|
|
|
* |
72
|
|
|
* @return string Language string for Ads ACP module |
73
|
|
|
* @access public |
74
|
|
|
*/ |
75
|
|
|
public function get_page_title() |
76
|
|
|
{ |
77
|
|
|
return $this->user->lang('ACP_ADMANAGEMENT_TITLE'); |
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
/** |
81
|
|
|
* Get action |
82
|
|
|
* |
83
|
|
|
* @return string Language string for Ads ACP module |
84
|
|
|
* @access public |
85
|
|
|
*/ |
86
|
|
|
public function get_action() |
87
|
|
|
{ |
88
|
|
|
return $this->request->variable('action', ''); |
89
|
|
|
} |
90
|
|
|
|
91
|
|
|
/** |
92
|
|
|
* Display the ads |
93
|
|
|
* |
94
|
|
|
* @return void |
95
|
|
|
* @access public |
96
|
|
|
*/ |
97
|
|
|
public function list_ads() |
98
|
|
|
{ |
99
|
|
|
$sql = 'SELECT ad_id, ad_name, ad_enabled |
100
|
|
|
FROM ' . $this->ads_table; |
101
|
|
|
$result = $this->db->sql_query($sql); |
102
|
|
|
while ($row = $this->db->sql_fetchrow($result)) |
103
|
|
|
{ |
104
|
|
|
$ad_enabled = (bool) $row['ad_enabled']; |
105
|
|
|
|
106
|
|
|
$this->template->assign_block_vars('ads', [ |
107
|
|
|
'NAME' => $row['ad_name'], |
108
|
|
|
'ENABLED' => $ad_enabled, |
109
|
|
|
'U_ENABLE' => $this->u_action . '&action=' . ($ad_enabled ? 'disable' : 'enable') . '&id=' . $row['ad_id'], // TODO: ACP method |
110
|
|
|
'U_PREVIEW' => '', // TODO: frontend logic |
111
|
|
|
'U_EDIT' => $this->u_action . '&action=edit&id=' . $row['ad_id'], // TODO: ACP method |
112
|
|
|
'U_DELETE' => $this->u_action . '&action=delete&id=' . $row['ad_id'], // TODO: ACP method |
113
|
|
|
]); |
114
|
|
|
} |
115
|
|
|
$this->db->sql_freeresult($result); |
116
|
|
|
|
117
|
|
|
// Set output vars for display in the template |
118
|
|
|
$this->template->assign_vars(array( |
119
|
|
|
'U_ACTION' => $this->u_action, |
120
|
|
|
'U_ADD_AD' => $this->u_action . '&action=add', |
121
|
|
|
)); |
122
|
|
|
} |
123
|
|
|
} |