permission_helper   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 71
Duplicated Lines 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 3
eloc 26
c 2
b 0
f 0
dl 0
loc 71
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A set_ideas_forum_permissions() 0 34 2
1
<?php
2
/**
3
 *
4
 * Ideas extension for 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
 */
10
11
namespace phpbb\ideas\factory;
12
13
class permission_helper
14
{
15
	/**
16
	 * @var \phpbb\db\driver\driver_interface
17
	 */
18
	protected $db;
19
20
	/**
21
	 * @var string
22
	 */
23
	protected $phpbb_root_path;
24
25
	/**
26
	 * @var string
27
	 */
28
	protected $php_ext;
29
30
	/**
31
	 * Constructor
32
	 *
33
	 * @param \phpbb\db\driver\driver_interface $db              Database object
34
	 * @param string                            $phpbb_root_path phpBB root path
35
	 * @param string                            $php_ext         php_ext
36
	 * @access public
37
	 */
38
	public function __construct(\phpbb\db\driver\driver_interface $db, $phpbb_root_path, $php_ext)
39
	{
40
		$this->db = $db;
41
		$this->phpbb_root_path = $phpbb_root_path;
42
		$this->php_ext = $php_ext;
43
	}
44
45
	/**
46
	 * Set the best permissions for an Ideas forum.
47
	 *
48
	 * @param int $forum_id A forum id
49
	 */
50
	public function set_ideas_forum_permissions($forum_id)
51
	{
52
		if (!class_exists('auth_admin'))
53
		{
54
			include $this->phpbb_root_path . 'includes/acp/auth.' . $this->php_ext;
55
		}
56
		$auth_admin = new \auth_admin();
57
58
		// Get the REGISTERED usergroup ID
59
		$sql = 'SELECT group_id
60
			FROM ' . GROUPS_TABLE . "
61
			WHERE group_name = '" . $this->db->sql_escape('REGISTERED') . "'";
62
		$result = $this->db->sql_query($sql);
63
		$group_id = (int) $this->db->sql_fetchfield('group_id');
64
		$this->db->sql_freeresult($result);
65
66
		// Get 'f_' local REGISTERED users group permissions array for the ideas forum
67
		// Default undefined permissions to ACL_NO
68
		$hold_ary = $auth_admin->get_mask('set', false, $group_id, $forum_id, 'f_', 'local', ACL_NO);
69
		$auth_settings = $hold_ary[$group_id][$forum_id];
70
71
		// Set 'Can start new topics' permissions to 'Yes' for the ideas forum
72
		$auth_settings['f_post'] = ACL_YES;
73
74
		// Can not post announcement or stickies, polls, use topic icons or lock own topic
75
		$auth_settings['f_announce'] = ACL_NEVER;
76
		$auth_settings['f_announce_global'] = ACL_NEVER;
77
		$auth_settings['f_sticky'] = ACL_NEVER;
78
		$auth_settings['f_poll'] = ACL_NEVER;
79
		$auth_settings['f_icons'] = ACL_NEVER;
80
		$auth_settings['f_user_lock'] = ACL_NEVER;
81
82
		// Update the registered usergroup permissions for selected Ideas forum...
83
		$auth_admin->acl_set('group', $forum_id, $group_id, $auth_settings);
84
	}
85
}
86