Completed
Push — master ( 03c5d4...7f0f9f )
by
unknown
01:43 queued 11s
created

permission_helper::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

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