-
-
Notifications
You must be signed in to change notification settings - Fork 53
/
Copy pathqueue.php
191 lines (164 loc) · 5.03 KB
/
queue.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
<?php
/**
*
* This file is part of the phpBB Customisation Database package.
*
* @copyright (c) phpBB Limited <https://www.phpbb.com>
* @license GNU General Public License, version 2 (GPL-2.0)
*
* For full copyright and license information, please see
* the docs/CREDITS.txt file.
*
*/
namespace phpbb\titania\controller\manage\queue;
use phpbb\titania\contribution\type\collection as type_collection;
use phpbb\titania\ext;
class queue extends \phpbb\titania\controller\manage\base
{
/** @var \phpbb\titania\subscriptions */
protected $subscriptions;
protected $type;
/**
* Constructor
*
* @param \phpbb\auth\auth $auth
* @param \phpbb\config\config $config
* @param \phpbb\db\driver\driver_interface $db
* @param \phpbb\template\template $template
* @param \phpbb\user $user
* @param \phpbb\titania\cache\service $cache
* @param \phpbb\titania\controller\helper $helper
* @param type_collection $types
* @param \phpbb\request\request_interface $request
* @param \phpbb\titania\config\config $ext_config
* @param \phpbb\titania\display $display
* @param \phpbb\titania\subscriptions $subscriptions
*/
public function __construct(\phpbb\auth\auth $auth, \phpbb\config\config $config, \phpbb\db\driver\driver_interface $db, \phpbb\template\template $template, \phpbb\user $user, \phpbb\titania\cache\service $cache, \phpbb\titania\controller\helper $helper, type_collection $types, \phpbb\request\request_interface $request, \phpbb\titania\config\config $ext_config, \phpbb\titania\display $display, \phpbb\titania\subscriptions $subscriptions)
{
parent::__construct($auth, $config, $db, $template, $user, $cache, $helper, $types, $request, $ext_config, $display);
$this->subscriptions = $subscriptions;
}
/**
* Display queue.
*
* @return \Symfony\Component\HttpFoundation\Response
*/
public function display_queue($queue_type)
{
$this->set_type($this->types->type_from_url($queue_type));
if (!$this->type->acl_get('view'))
{
return $this->helper->needs_auth();
}
$tag = $this->request->variable('tag', 0);
// Subscriptions
if (!$tag)
{
$this->subscriptions->handle_subscriptions(
ext::TITANIA_QUEUE,
$this->type->id,
$this->helper->get_current_url(),
'SUBSCRIBE_QUEUE'
);
}
else
{
$this->subscriptions->handle_subscriptions(
ext::TITANIA_QUEUE_TAG,
$tag,
$this->helper->get_current_url(),
'SUBSCRIBE_CATEGORY'
);
}
\queue_overlord::display_queue($this->type->id, $tag);
\queue_overlord::display_categories($this->type->id, $tag);
$this->display->assign_global_vars();
$this->generate_navigation('queue');
// Add to Breadcrumbs
$this->display->generate_breadcrumbs(array(
// This is where the type gets displayed
$this->type->lang['lang'] => $this->get_queue_url($this->type->id),
));
return $this->helper->render('manage/queue.html', 'VALIDATION_QUEUE');
}
/**
* List all available queues. If user has access to only one queue, he will be
* redirected to it.
*
* @return \Symfony\Component\HttpFoundation\Response
*/
public function list_queues()
{
// We need to select the queue if they only have one that they can access, else display the list
$authed_types = $this->types->find_authed('view');
if (empty($authed_types))
{
return $this->helper->needs_auth();
}
else if (sizeof($authed_types) == 1)
{
// Redirect the user to the only queue that he has access to.
redirect($this->get_queue_url($authed_types[0]));
}
$counts = $this->get_item_counts($authed_types);
foreach ($authed_types as $queue_type)
{
$this->template->assign_block_vars('categories', array(
'U_VIEW_CATEGORY' => $this->get_queue_url($queue_type),
'CATEGORY_NAME' => $this->types->get($queue_type)->lang['langs'],
'CATEGORY_CONTRIBS' => $counts[$queue_type],
));
}
$this->template->assign_vars(array(
'S_QUEUE_LIST' => true,
));
$this->display->assign_global_vars();
$this->generate_navigation('queue');
return $this->helper->render('manage/queue.html', 'VALIDATION_QUEUE');
}
/**
* Set queue contribution type object.
*
* @param int $type Contrib type id.
* @return null
*/
protected function set_type($type)
{
$this->type = $this->types->get($type);
}
/**
* Get queue item counts.
*
* @param array $types Types to fetch counts for.
* @return array
*/
protected function get_item_counts($types)
{
$counts = array_fill_keys($types, 0);
$sql = 'SELECT queue_type, COUNT(queue_id) AS cnt
FROM ' . TITANIA_QUEUE_TABLE . '
WHERE queue_status > 0
AND ' . $this->db->sql_in_set('queue_type', $types) . '
GROUP BY queue_type';
$result = $this->db->sql_query($sql);
while ($row = $this->db->sql_fetchrow($result))
{
$counts[$row['queue_type']] = (int) $row['cnt'];
}
$this->db->sql_freeresult($result);
return $counts;
}
/**
* Get URL for a queue type.
*
* @param int $type Contrib type id.
* @return string
*/
protected function get_queue_url($type)
{
return $this->helper->route('phpbb.titania.queue.type', array(
'queue_type' => $this->types->get($type)->url,
));
}
}