Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 162 |
|
0.00% |
0 / 2 |
CRAP | |
0.00% |
0 / 1 |
| team | |
0.00% |
0 / 162 |
|
0.00% |
0 / 2 |
1722 | |
0.00% |
0 / 1 |
| __construct | |
0.00% |
0 / 16 |
|
0.00% |
0 / 1 |
2 | |||
| handle | |
0.00% |
0 / 146 |
|
0.00% |
0 / 1 |
1640 | |||
| 1 | <?php |
| 2 | /** |
| 3 | * |
| 4 | * This file is part of the phpBB Forum Software package. |
| 5 | * |
| 6 | * @copyright (c) phpBB Limited <https://www.phpbb.com> |
| 7 | * @license GNU General Public License, version 2 (GPL-2.0) |
| 8 | * |
| 9 | * For full copyright and license information, please see |
| 10 | * the docs/CREDITS.txt file. |
| 11 | * |
| 12 | */ |
| 13 | |
| 14 | namespace phpbb\members\controller; |
| 15 | |
| 16 | use phpbb\auth\auth; |
| 17 | use phpbb\config\config; |
| 18 | use phpbb\db\driver\driver_interface; |
| 19 | use phpbb\event\dispatcher; |
| 20 | use phpbb\exception\http_exception; |
| 21 | use phpbb\group\helper as group_helper; |
| 22 | use phpbb\controller\helper; |
| 23 | use phpbb\language\language; |
| 24 | use phpbb\template\template; |
| 25 | use phpbb\user; |
| 26 | use Symfony\Component\HttpFoundation\Response; |
| 27 | |
| 28 | class team |
| 29 | { |
| 30 | /** |
| 31 | * @var auth |
| 32 | */ |
| 33 | protected $auth; |
| 34 | |
| 35 | /** |
| 36 | * @var config |
| 37 | */ |
| 38 | protected $config; |
| 39 | |
| 40 | /** |
| 41 | * @var driver_interface |
| 42 | */ |
| 43 | protected $db; |
| 44 | |
| 45 | /** |
| 46 | * @var dispatcher |
| 47 | */ |
| 48 | protected $dispatcher; |
| 49 | |
| 50 | /** |
| 51 | * @var group_helper |
| 52 | */ |
| 53 | protected $group_helper; |
| 54 | |
| 55 | /** |
| 56 | * @var helper |
| 57 | */ |
| 58 | protected $helper; |
| 59 | |
| 60 | /** |
| 61 | * @var language |
| 62 | */ |
| 63 | protected $language; |
| 64 | |
| 65 | /** |
| 66 | * @var template |
| 67 | */ |
| 68 | protected $template; |
| 69 | |
| 70 | /** |
| 71 | * @var user |
| 72 | */ |
| 73 | protected $user; |
| 74 | |
| 75 | /** |
| 76 | * @var string |
| 77 | */ |
| 78 | protected $phpbb_root_path; |
| 79 | |
| 80 | /** |
| 81 | * @var string |
| 82 | */ |
| 83 | protected $php_ext; |
| 84 | |
| 85 | /** |
| 86 | * @var string |
| 87 | */ |
| 88 | protected $forums_table; |
| 89 | |
| 90 | /** |
| 91 | * @var string |
| 92 | */ |
| 93 | protected $groups_table; |
| 94 | |
| 95 | /** |
| 96 | * @var string |
| 97 | */ |
| 98 | protected $teampage_table; |
| 99 | |
| 100 | /** |
| 101 | * @var string |
| 102 | */ |
| 103 | protected $user_group_table; |
| 104 | |
| 105 | /** |
| 106 | * @var string |
| 107 | */ |
| 108 | protected $users_table; |
| 109 | |
| 110 | |
| 111 | /** |
| 112 | * Constructor |
| 113 | * |
| 114 | * @param auth $auth Authentication service |
| 115 | * @param config $config Configuration |
| 116 | * @param driver_interface $db Database driver |
| 117 | * @param dispatcher $dispatcher Event dispatcher |
| 118 | * @param group_helper $group_helper Group helper |
| 119 | * @param helper $helper Controller helper |
| 120 | * @param language $language Language service |
| 121 | * @param template $template Template service |
| 122 | * @param user $user User object |
| 123 | * @param string $phpbb_root_path Path to phpBB root |
| 124 | * @param string $phpEx PHP file extension |
| 125 | * @param string $forums_table Table name for forums |
| 126 | * @param string $groups_table Table name for groups |
| 127 | * @param string $teampage_table Table name for teampage |
| 128 | * @param string $user_group_table Table name for user_group |
| 129 | * @param string $users_table Table name for users |
| 130 | */ |
| 131 | public function __construct(auth $auth, config $config, driver_interface $db, dispatcher $dispatcher, group_helper $group_helper, helper $helper, language $language, template $template, user $user, string $phpbb_root_path, string $phpEx, string $forums_table, string $groups_table, string $teampage_table, string $user_group_table, string $users_table) |
| 132 | { |
| 133 | $this->auth = $auth; |
| 134 | $this->config = $config; |
| 135 | $this->db = $db; |
| 136 | $this->dispatcher = $dispatcher; |
| 137 | $this->group_helper = $group_helper; |
| 138 | $this->helper = $helper; |
| 139 | $this->language = $language; |
| 140 | $this->template = $template; |
| 141 | $this->user = $user; |
| 142 | $this->phpbb_root_path = $phpbb_root_path; |
| 143 | $this->php_ext = $phpEx; |
| 144 | $this->forums_table = $forums_table; |
| 145 | $this->groups_table = $groups_table; |
| 146 | $this->teampage_table = $teampage_table; |
| 147 | $this->user_group_table = $user_group_table; |
| 148 | $this->users_table = $users_table; |
| 149 | } |
| 150 | |
| 151 | /** |
| 152 | * Controller for /team route |
| 153 | * |
| 154 | * @return Response a Symfony response object |
| 155 | */ |
| 156 | public function handle() : Response |
| 157 | { |
| 158 | // Display a listing of board admins, moderators |
| 159 | if (!function_exists('user_get_id_name')) |
| 160 | { |
| 161 | include($this->phpbb_root_path . 'includes/functions_user.' . $this->php_ext); |
| 162 | } |
| 163 | if (!function_exists('phpbb_get_user_rank')) |
| 164 | { |
| 165 | include($this->phpbb_root_path . 'includes/functions_display.' . $this->php_ext); |
| 166 | } |
| 167 | |
| 168 | // Load language strings |
| 169 | $this->language->add_lang('memberlist'); |
| 170 | |
| 171 | // Can this user view profiles/memberlist? |
| 172 | if (!$this->auth->acl_gets('u_viewprofile', 'a_user', 'a_useradd', 'a_userdel')) |
| 173 | { |
| 174 | if ($this->user->data['user_id'] != ANONYMOUS) |
| 175 | { |
| 176 | throw new http_exception(403, 'NO_VIEW_USERS'); |
| 177 | } |
| 178 | |
| 179 | login_box('', $this->language->lang('LOGIN_EXPLAIN_TEAM')); |
| 180 | } |
| 181 | |
| 182 | $sql = 'SELECT * |
| 183 | FROM ' . $this->teampage_table . ' |
| 184 | ORDER BY teampage_position ASC'; |
| 185 | $result = $this->db->sql_query($sql, 3600); |
| 186 | $teampage_data = $this->db->sql_fetchrowset($result); |
| 187 | $this->db->sql_freeresult($result); |
| 188 | |
| 189 | $sql_ary = [ |
| 190 | 'SELECT' => 'g.group_id, g.group_name, g.group_colour, g.group_type, ug.user_id as ug_user_id, t.teampage_id', |
| 191 | |
| 192 | 'FROM' => [$this->groups_table => 'g'], |
| 193 | |
| 194 | 'LEFT_JOIN' => [ |
| 195 | [ |
| 196 | 'FROM' => [$this->teampage_table => 't'], |
| 197 | 'ON' => 't.group_id = g.group_id', |
| 198 | ], |
| 199 | [ |
| 200 | 'FROM' => [$this->user_group_table => 'ug'], |
| 201 | 'ON' => 'ug.group_id = g.group_id AND ug.user_pending = 0 AND ug.user_id = ' . (int) $this->user->data['user_id'], |
| 202 | ], |
| 203 | ], |
| 204 | ]; |
| 205 | |
| 206 | $result = $this->db->sql_query($this->db->sql_build_query('SELECT', $sql_ary)); |
| 207 | |
| 208 | $group_ids = $groups_ary = []; |
| 209 | while ($row = $this->db->sql_fetchrow($result)) |
| 210 | { |
| 211 | if ($row['group_type'] == GROUP_HIDDEN && !$this->auth->acl_gets('a_group', 'a_groupadd', 'a_groupdel') && $row['ug_user_id'] != $this->user->data['user_id']) |
| 212 | { |
| 213 | $row['group_name'] = $this->language->lang('GROUP_UNDISCLOSED'); |
| 214 | $row['u_group'] = ''; |
| 215 | } |
| 216 | else |
| 217 | { |
| 218 | $row['group_name'] = $this->group_helper->get_name($row['group_name']); |
| 219 | $row['u_group'] = append_sid("{$this->phpbb_root_path}memberlist.{$this->php_ext}", 'mode=group&g=' . $row['group_id']); |
| 220 | } |
| 221 | |
| 222 | if ($row['teampage_id']) |
| 223 | { |
| 224 | // Only put groups into the array we want to display. |
| 225 | // We are fetching all groups, to ensure we got all data for default groups. |
| 226 | $group_ids[] = (int) $row['group_id']; |
| 227 | } |
| 228 | $groups_ary[(int) $row['group_id']] = $row; |
| 229 | } |
| 230 | $this->db->sql_freeresult($result); |
| 231 | |
| 232 | $sql_ary = [ |
| 233 | 'SELECT' => 'u.user_id, u.group_id as default_group, u.username, u.username_clean, u.user_colour, u.user_type, u.user_rank, u.user_posts, u.user_allow_pm, g.group_id', |
| 234 | |
| 235 | 'FROM' => [ |
| 236 | $this->user_group_table => 'ug', |
| 237 | ], |
| 238 | |
| 239 | 'LEFT_JOIN' => [ |
| 240 | [ |
| 241 | 'FROM' => [$this->users_table => 'u'], |
| 242 | 'ON' => 'ug.user_id = u.user_id', |
| 243 | ], |
| 244 | [ |
| 245 | 'FROM' => [$this->groups_table => 'g'], |
| 246 | 'ON' => 'ug.group_id = g.group_id', |
| 247 | ], |
| 248 | ], |
| 249 | |
| 250 | 'WHERE' => $this->db->sql_in_set('g.group_id', $group_ids, false, true) . ' AND ug.user_pending = 0', |
| 251 | |
| 252 | 'ORDER_BY' => 'u.username_clean ASC', |
| 253 | ]; |
| 254 | |
| 255 | /** |
| 256 | * Modify the query used to get the users for the team page |
| 257 | * |
| 258 | * @event core.memberlist_team_modify_query |
| 259 | * @var array sql_ary Array containing the query |
| 260 | * @var array group_ids Array of group ids |
| 261 | * @var array teampage_data The teampage data |
| 262 | * @since 3.1.3-RC1 |
| 263 | */ |
| 264 | $vars = ['sql_ary', 'group_ids', 'teampage_data']; |
| 265 | extract($this->dispatcher->trigger_event('core.memberlist_team_modify_query', compact($vars))); |
| 266 | |
| 267 | $result = $this->db->sql_query($this->db->sql_build_query('SELECT', $sql_ary)); |
| 268 | |
| 269 | $user_ary = $user_ids = $group_users = []; |
| 270 | while ($row = $this->db->sql_fetchrow($result)) |
| 271 | { |
| 272 | $row['forums'] = ''; |
| 273 | $row['forums_ary'] = []; |
| 274 | $user_ary[(int) $row['user_id']] = $row; |
| 275 | $user_ids[] = (int) $row['user_id']; |
| 276 | $group_users[(int) $row['group_id']][] = (int) $row['user_id']; |
| 277 | } |
| 278 | $this->db->sql_freeresult($result); |
| 279 | |
| 280 | $user_ids = array_unique($user_ids); |
| 281 | |
| 282 | if (!empty($user_ids) && $this->config['teampage_forums']) |
| 283 | { |
| 284 | $this->template->assign_var('S_DISPLAY_MODERATOR_FORUMS', true); |
| 285 | // Get all moderators |
| 286 | $perm_ary = $this->auth->acl_get_list($user_ids, ['m_'], false); |
| 287 | |
| 288 | foreach ($perm_ary as $forum_id => $forum_ary) |
| 289 | { |
| 290 | foreach ($forum_ary as $id_ary) |
| 291 | { |
| 292 | foreach ($id_ary as $id) |
| 293 | { |
| 294 | if (!$forum_id) |
| 295 | { |
| 296 | $user_ary[$id]['forums'] = $this->language->lang('ALL_FORUMS'); |
| 297 | } |
| 298 | else |
| 299 | { |
| 300 | $user_ary[$id]['forums_ary'][] = $forum_id; |
| 301 | } |
| 302 | } |
| 303 | } |
| 304 | } |
| 305 | |
| 306 | $sql = 'SELECT forum_id, forum_name |
| 307 | FROM ' . $this->forums_table; |
| 308 | $result = $this->db->sql_query($sql); |
| 309 | |
| 310 | $forums = []; |
| 311 | while ($row = $this->db->sql_fetchrow($result)) |
| 312 | { |
| 313 | $forums[$row['forum_id']] = $row['forum_name']; |
| 314 | } |
| 315 | $this->db->sql_freeresult($result); |
| 316 | |
| 317 | foreach ($user_ary as $user_id => $user_data) |
| 318 | { |
| 319 | if (!$user_data['forums']) |
| 320 | { |
| 321 | foreach ($user_data['forums_ary'] as $forum_id) |
| 322 | { |
| 323 | $user_ary[$user_id]['forums_options'] = true; |
| 324 | if (isset($forums[$forum_id])) |
| 325 | { |
| 326 | if ($this->auth->acl_get('f_list', $forum_id)) |
| 327 | { |
| 328 | $user_ary[$user_id]['forums'] .= '<option value="">' . $forums[$forum_id] . '</option>'; |
| 329 | } |
| 330 | } |
| 331 | } |
| 332 | } |
| 333 | } |
| 334 | } |
| 335 | |
| 336 | foreach ($teampage_data as $team_data) |
| 337 | { |
| 338 | // If this team entry has no group, it's a category |
| 339 | if (!$team_data['group_id']) |
| 340 | { |
| 341 | $this->template->assign_block_vars('group', [ |
| 342 | 'GROUP_NAME' => $team_data['teampage_name'], |
| 343 | ]); |
| 344 | |
| 345 | continue; |
| 346 | } |
| 347 | |
| 348 | $group_data = $groups_ary[(int) $team_data['group_id']]; |
| 349 | $group_id = (int) $team_data['group_id']; |
| 350 | |
| 351 | if (!$team_data['teampage_parent']) |
| 352 | { |
| 353 | // If the group does not have a parent category, we display the groupname as category |
| 354 | $this->template->assign_block_vars('group', [ |
| 355 | 'GROUP_NAME' => $group_data['group_name'], |
| 356 | 'GROUP_COLOR' => $group_data['group_colour'], |
| 357 | 'U_GROUP' => $group_data['u_group'], |
| 358 | ]); |
| 359 | } |
| 360 | |
| 361 | // Display group members. |
| 362 | if (!empty($group_users[$group_id])) |
| 363 | { |
| 364 | foreach ($group_users[$group_id] as $user_id) |
| 365 | { |
| 366 | if (isset($user_ary[$user_id])) |
| 367 | { |
| 368 | $row = $user_ary[$user_id]; |
| 369 | if ($this->config['teampage_memberships'] == 1 && ($group_id != $groups_ary[$row['default_group']]['group_id']) && $groups_ary[$row['default_group']]['teampage_id']) |
| 370 | { |
| 371 | // Display users in their primary group, instead of the first group, when it is displayed on the teampage. |
| 372 | continue; |
| 373 | } |
| 374 | |
| 375 | $user_rank_data = phpbb_get_user_rank($row, (($row['user_id'] == ANONYMOUS) ? false : $row['user_posts'])); |
| 376 | |
| 377 | $template_vars = [ |
| 378 | 'USER_ID' => $row['user_id'], |
| 379 | 'FORUMS' => $row['forums'], |
| 380 | 'FORUM_OPTIONS' => (isset($row['forums_options'])) ? true : false, |
| 381 | 'RANK_TITLE' => $user_rank_data['title'], |
| 382 | |
| 383 | 'GROUP_NAME' => $groups_ary[$row['default_group']]['group_name'], |
| 384 | 'GROUP_COLOR' => $groups_ary[$row['default_group']]['group_colour'], |
| 385 | 'U_GROUP' => $groups_ary[$row['default_group']]['u_group'], |
| 386 | |
| 387 | 'RANK_IMG' => $user_rank_data['img'], |
| 388 | 'RANK_IMG_SRC' => $user_rank_data['img_src'], |
| 389 | |
| 390 | 'S_INACTIVE' => $row['user_type'] == USER_INACTIVE, |
| 391 | |
| 392 | 'U_PM' => ($this->config['allow_privmsg'] && $this->auth->acl_get('u_sendpm') && ($row['user_allow_pm'] || $this->auth->acl_gets('a_', 'm_') || $this->auth->acl_getf_global('m_'))) ? append_sid("{$this->phpbb_root_path}ucp.{$this->php_ext}", 'i=pm&mode=compose&u=' . $row['user_id']) : '', |
| 393 | |
| 394 | 'USERNAME_FULL' => get_username_string('full', $row['user_id'], $row['username'], $row['user_colour']), |
| 395 | 'USERNAME' => get_username_string('username', $row['user_id'], $row['username'], $row['user_colour']), |
| 396 | 'USER_COLOR' => get_username_string('colour', $row['user_id'], $row['username'], $row['user_colour']), |
| 397 | 'U_VIEW_PROFILE' => get_username_string('profile', $row['user_id'], $row['username'], $row['user_colour']), |
| 398 | ]; |
| 399 | |
| 400 | /** |
| 401 | * Modify the template vars for displaying the user in the groups on the teampage |
| 402 | * |
| 403 | * @event core.memberlist_team_modify_template_vars |
| 404 | * @var array template_vars Array containing the query |
| 405 | * @var array row Array containing the action user row |
| 406 | * @var array groups_ary Array of groups with all users that should be displayed |
| 407 | * @since 3.1.3-RC1 |
| 408 | */ |
| 409 | $vars = ['template_vars', 'row', 'groups_ary']; |
| 410 | extract($this->dispatcher->trigger_event('core.memberlist_team_modify_template_vars', compact($vars))); |
| 411 | |
| 412 | $this->template->assign_block_vars('group.user', $template_vars); |
| 413 | |
| 414 | if ($this->config['teampage_memberships'] != 2) |
| 415 | { |
| 416 | unset($user_ary[$user_id]); |
| 417 | } |
| 418 | } |
| 419 | } |
| 420 | } |
| 421 | } |
| 422 | |
| 423 | $this->template->assign_vars([ |
| 424 | 'PM_IMG' => $this->user->img('icon_contact_pm', $this->language->lang('SEND_PRIVATE_MESSAGE')), |
| 425 | ]); |
| 426 | |
| 427 | // Breadcrumbs |
| 428 | $this->template->assign_block_vars('navlinks', [ |
| 429 | 'BREADCRUMB_NAME' => $this->language->lang('THE_TEAM'), |
| 430 | 'U_BREADCRUMB' => $this->helper->route('phpbb_members_team'), |
| 431 | ]); |
| 432 | |
| 433 | make_jumpbox(append_sid("{$this->phpbb_root_path}viewforum.{$this->php_ext}")); |
| 434 | |
| 435 | // Render |
| 436 | return $this->helper->render('memberlist_team.html', $this->language->lang('THE_TEAM')); |
| 437 | } |
| 438 | |
| 439 | } |