Completed
Push — master ( 9866a1...02e5e5 )
by Daniel
08:18
created

manager::__construct()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 17
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 12
CRAP Score 2.0116

Importance

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