Completed
Push — develop ( c767cb...92ad0e )
by Daniel
10:06
created

manager::add()   A

Complexity

Conditions 4
Paths 3

Size

Total Lines 21
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 14
CRAP Score 4

Importance

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