Completed
Push — master ( df7035...349ca4 )
by Daniel
08:26
created

manager::add()   B

Complexity

Conditions 4
Paths 3

Size

Total Lines 25
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 15
CRAP Score 4.0039

Importance

Changes 3
Bugs 0 Features 0
Metric Value
c 3
b 0
f 0
dl 0
loc 25
ccs 15
cts 16
cp 0.9375
rs 8.5806
cc 4
eloc 12
nc 3
nop 2
crap 4.0039
1
<?php
2
/**
3
 *
4
 * @package sitemaker
5
 * @copyright (c) 2013 Daniel A. (blitze)
6
 * @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
7
 *
8
 */
9
10
namespace blitze\sitemaker\services\forum;
11
12
class manager
13
{
14
	/** @var \phpbb\auth\auth */
15
	protected $auth;
16
17
	/** @var \phpbb\cache\driver\driver_interface */
18
	protected $cache;
19
20
	/** @var \phpbb\config\config */
21
	protected $config;
22
23
	/** @var \phpbb\db\driver\driver_interface */
24
	protected $db;
25
26
	/** @var \phpbb\user */
27
	protected $user;
28
29
	/** @var \acp_forums */
30
	protected $forum;
31
32
	/** @var string */
33
	protected $phpbb_root_path;
34
35
	/** @var string */
36
	protected $php_ext;
37
38
	/**
39
	 * Constructor
40
	 *
41
	 * @param \phpbb\auth\auth						$auth				Auth object
42
	 * @param \phpbb\cache\driver\driver_interface	$cache				Cache driver interface
43
	 * @param \phpbb\config\config					$config				Config object
44
	 * @param \phpbb\db\driver\driver_interface		$db					Database object
45
	 * @param \phpbb\user							$user				User object
46
	 * @param string								$phpbb_root_path	Path to the phpbb includes directory.
47
	 * @param string								$php_ext			php file extension
48
	 */
49 2
	public function __construct(\phpbb\auth\auth $auth, \phpbb\cache\driver\driver_interface $cache, \phpbb\config\config $config, \phpbb\db\driver\driver_interface $db, \phpbb\user $user, $phpbb_root_path, $php_ext)
50
	{
51 2
		$this->auth = $auth;
52 2
		$this->cache = $cache;
53 2
		$this->config = $config;
54 2
		$this->db = $db;
55 2
		$this->user = $user;
56 2
		$this->phpbb_root_path = $phpbb_root_path;
57 2
		$this->php_ext = $php_ext;
58
59 2
		if (!class_exists('acp_forums'))
60 2
		{
61 1
			include($this->phpbb_root_path . 'includes/acp/acp_forums.' . $this->php_ext);
62 1
		}
63
64 2
		$this->user->add_lang('acp/forums');
65 2
	}
66
67
	/**
68
	 * @param array $forum_data
69
	 * @param int $forum_perm_from
70
	 * @return array
71
	 */
72 1
	public function add(array &$forum_data, $forum_perm_from = 0)
73
	{
74
		$forum_data += array(
75 1
			'parent_id' => $this->config['sitemaker_parent_forum_id'],
76
		);
77
78 1
		$errors = admin::save($forum_data);
79
80 1
		if (!sizeof($errors))
81 1
		{
82 1
			$forum_data['forum_id'] = (int) $forum_data['forum_id'];
83
84
			// Copy permissions?
85 1
			if ($forum_perm_from && $forum_perm_from != $forum_data['forum_id'])
86 1
			{
87 1
				copy_forum_permissions($forum_perm_from, array($forum_data['forum_id']), false, false);
88 1
				phpbb_cache_moderators($this->db, $this->cache, $this->auth);
89 1
			}
90
91 1
			$this->auth->acl_clear_prefetch();
92 1
			$this->cache->destroy('sql', FORUMS_TABLE);
93 1
		}
94
95 1
		return $errors;
96
	}
97
98
	/**
99
	 * @param int $forum_id
100
	 * @param string $action_posts
101
	 * @param string $action_subforums
102
	 * @param int $posts_to_id
103
	 * @param int $subforums_to_id
104
	 */
105 1
	public function remove($forum_id, $action_posts = 'delete', $action_subforums = 'delete', $posts_to_id = 0, $subforums_to_id = 0)
106
	{
107 1
		admin::remove($forum_id, $action_posts, $action_subforums, $posts_to_id, $subforums_to_id);
108 1
	}
109
}
110