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

manager::delete_prefix()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 3
rs 10
cc 1
eloc 1
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
use phpbb\db\driver\driver_interface;
14
15
class manager implements manager_interface
16
{
17
	/**
18
	 * @var driver_interface Database object
19
	 */
20
	protected $db;
21
22
	/**
23
	 * @var string Topic prefixes data table name
24
	 */
25
	protected $prefixes_table;
26
27
	/**
28
	 * Listener constructor
29
	 *
30
	 * @param driver_interface $db             Database object
31
	 * @param string           $prefixes_table Topic prefixes data table name
32
	 */
33
	public function __construct(driver_interface $db, $prefixes_table)
34
	{
35
		$this->db = $db;
36
		$this->prefixes_table = $prefixes_table;
37
	}
38
39
	/**
40
	 * @inheritdoc
41
	 */
42
	public function get_prefix($id)
43
	{
44
		$sql = 'SELECT prefix_id, prefix_tag, prefix_enabled 
45
			FROM ' . $this->prefixes_table . ' 
46
			WHERE prefix_id = ' . (int) $id;
47
		$result = $this->db->sql_query_limit($sql, 1);
48
		$row = $this->db->sql_fetchrow($result);
49
		$this->db->sql_freeresult($result);
50
51
		return $row;
52
	}
53
54
	/**
55
	 * @inheritdoc
56
	 */
57
	public function get_prefixes($forum_id = 0)
58
	{
59
		$prefixes = [];
60
61
		$sql = 'SELECT prefix_id, prefix_tag, prefix_enabled 
62
			FROM ' . $this->prefixes_table .
63
			($forum_id ? ' WHERE forum_id = ' . (int) $forum_id : '') . '
64
			ORDER BY prefix_id';
65
		$result = $this->db->sql_query($sql, 3600);
66
		while ($row = $this->db->sql_fetchrow($result))
67
		{
68
			$prefixes[$row['prefix_id']] = $row;
69
		}
70
		$this->db->sql_freeresult($result);
71
72
		return $prefixes;
73
	}
74
75
	/**
76
	 * @inheritdoc
77
	 */
78
	public function get_active_prefixes($forum_id = 0)
79
	{
80
		return array_filter($this->get_prefixes($forum_id), [$this, 'is_enabled']);
81
	}
82
83
	/**
84
	 * @inheritdoc
85
	 */
86
	public function add_prefix($tag, $forum_id)
87
	{
88
	}
89
90
	/**
91
	 * @inheritdoc
92
	 */
93
	public function delete_prefix($id)
94
	{
95
	}
96
97
	/**
98
	 * @inheritdoc
99
	 */
100
	public function is_enabled(array $row)
101
	{
102
		return $row['prefix_enabled'];
103
	}
104
105
	/**
106
	 * @inheritdoc
107
	 */
108
	public function prepend_prefix($prefix, $subject)
109
	{
110
		if ($prefix && strpos($subject, $prefix) !== 0)
111
		{
112
			$subject = $prefix . ' ' . $subject;
113
		}
114
115
		return $subject;
116
	}
117
}
118