Completed
Push — master ( 799b0c...788440 )
by Daniel
08:11
created

manager::add()   B

Complexity

Conditions 4
Paths 3

Size

Total Lines 23
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 15
CRAP Score 4

Importance

Changes 2
Bugs 0 Features 0
Metric Value
c 2
b 0
f 0
dl 0
loc 23
ccs 15
cts 15
cp 1
rs 8.7972
cc 4
eloc 11
nc 3
nop 2
crap 4
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 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)
52
	{
53 2
		$this->auth = $auth;
54 2
		$this->cache = $cache;
55 2
		$this->config = $config;
56 2
		$this->db = $db;
57 2
		$this->user = $user;
58 2
		$this->phpbb_root_path = $phpbb_root_path;
59 2
		$this->php_ext = $php_ext;
60
61 2
		if (!class_exists('acp_forums'))
62 2
		{
63 1
			include($this->phpbb_root_path . 'includes/acp/acp_forums.' . $this->php_ext);
64 1
		}
65
66 2
		$this->user->add_lang('acp/forums');
67 2
	}
68
69 1
	public function add(&$forum_data, $forum_perm_from = 0)
70
	{
71 1
		$forum_data['parent_id'] = $this->config['sitemaker_parent_forum_id'];
72
73 1
		$errors = admin::save($forum_data);
74
75 1
		if (!sizeof($errors))
76 1
		{
77 1
			$forum_data['forum_id'] = (int) $forum_data['forum_id'];
78
79
			// Copy permissions?
80 1
			if ($forum_perm_from && $forum_perm_from != $forum_data['forum_id'])
81 1
			{
82 1
				copy_forum_permissions($forum_perm_from, $forum_data['forum_id'], false, false);
83 1
				phpbb_cache_moderators($this->db, $this->cache, $this->auth);
84 1
			}
85
86 1
			$this->auth->acl_clear_prefetch();
87 1
			$this->cache->destroy('sql', FORUMS_TABLE);
88 1
		}
89
90 1
		return $errors;
91
	}
92
93 1
	public function remove($forum_id, $action_posts = 'delete', $action_subforums = 'delete', $posts_to_id = 0, $subforums_to_id = 0)
94
	{
95 1
		admin::remove($forum_id, $action_posts, $action_subforums, $posts_to_id, $subforums_to_id);
96 1
	}
97
}
98