Completed
Pull Request — master (#3)
by Matt
02:41
created

manager::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 1
Metric Value
c 2
b 0
f 1
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 1
1
<?php
2
/**
3
 *
4
 * Topic Prefixes extension for the phpBB Forum Software package.
5
 *
6
 * @copyright (c) 2016 phpBB Limited <https://www.phpbb.com>
7
 * @license GNU General Public License, version 2 (GPL-2.0)
8
 *
9
 */
10
11
namespace phpbb\topicprefixes\prefixes;
12
13
class manager implements manager_interface
14
{
15
	/**
16
	 * @var \phpbb\topicprefixes\prefixes\nestedset_prefixes
17
	 */
18
	protected $nestedset;
19
20
	/**
21
	 * Listener constructor
22
	 *
23
	 * @param \phpbb\topicprefixes\prefixes\nestedset_prefixes $nestedset
24
	 */
25
	public function __construct(\phpbb\topicprefixes\prefixes\nestedset_prefixes $nestedset)
26
	{
27
		$this->nestedset = $nestedset;
28
	}
29
30
	/**
31
	 * @inheritdoc
32
	 */
33
	public function get_prefix($id)
34
	{
35
		$prefix = $this->nestedset->get_subtree_data($id);
36
37
		return sizeof($prefix) ? $prefix[$id] : false;
38
	}
39
40
	/**
41
	 * @inheritdoc
42
	 */
43
	public function get_prefixes($forum_id = 0)
44
	{
45
		if ($forum_id)
46
		{
47
			$this->nestedset->set_forum_id($forum_id);
48
		}
49
50
		return $this->nestedset->get_all_tree_data();
51
	}
52
53
	/**
54
	 * @inheritdoc
55
	 */
56
	public function get_active_prefixes($forum_id = 0)
57
	{
58
		return array_filter($this->get_prefixes($forum_id), [$this, 'is_enabled']);
59
	}
60
61
	/**
62
	 * @inheritdoc
63
	 */
64
	public function add_prefix($tag, $forum_id)
65
	{
66
	}
67
68
	/**
69
	 * @inheritdoc
70
	 */
71
	public function delete_prefix($id)
72
	{
73
	}
74
75
	/**
76
	 * @inheritdoc
77
	 */
78
	public function is_enabled(array $row)
79
	{
80
		return $row['prefix_enabled'];
81
	}
82
83
	/**
84
	 * @inheritdoc
85
	 */
86
	public function prepend_prefix($prefix, $subject)
87
	{
88
		if ($prefix && strpos($subject, $prefix) !== 0)
89
		{
90
			$subject = $prefix . ' ' . $subject;
91
		}
92
93
		return $subject;
94
	}
95
}
96