Passed
Pull Request — master (#132)
by Matt
01:21
created

base::get_status_from_id()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 1
dl 0
loc 3
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
1
<?php
2
/**
3
 *
4
 * Ideas extension for the phpBB Forum Software package.
5
 *
6
 * @copyright (c) phpBB Limited <https://www.phpbb.com>
7
 * @license GNU General Public License, version 2 (GPL-2.0)
8
 *
9
 */
10
11
namespace phpbb\ideas\factory;
12
13
use phpbb\auth\auth;
14
use phpbb\config\config;
15
use phpbb\db\driver\driver_interface;
16
use phpbb\ideas\ext;
17
use phpbb\language\language;
18
use phpbb\user;
19
20
/**
21
 * Base ideas class
22
 */
23
class base
24
{
25
	/** @var auth */
26
	protected $auth;
27
28
	/* @var config */
29
	protected $config;
30
31
	/* @var driver_interface */
32
	protected $db;
33
34
	/** @var language */
35
	protected $language;
36
37
	/* @var user */
38
	protected $user;
39
40
	/** @var string */
41
	protected $table_ideas;
42
43
	/** @var string */
44
	protected $table_votes;
45
46
	/** @var string */
47
	protected $table_topics;
48
49
	/** @var string */
50
	protected $php_ext;
51
52
	/**
53
	 * Constructor
54
	 *
55
	 * @param auth             $auth
56
	 * @param config           $config
57
	 * @param driver_interface $db
58
	 * @param language         $language
59
	 * @param user             $user
60
	 * @param string           $table_ideas
61
	 * @param string           $table_votes
62
	 * @param string           $table_topics
63
	 * @param string           $phpEx
64
	 */
65
	public function __construct(auth $auth, config $config, driver_interface $db, language $language, user $user, $table_ideas, $table_votes, $table_topics, $phpEx)
66
	{
67
		$this->auth = $auth;
68
		$this->config = $config;
69
		$this->db = $db;
70
		$this->language = $language;
71
		$this->user = $user;
72
73
		$this->php_ext = $phpEx;
74
75
		$this->table_ideas = $table_ideas;
76
		$this->table_votes = $table_votes;
77
		$this->table_topics = $table_topics;
78
	}
79
80
	/**
81
	 * Returns the status name from the status ID specified.
82
	 *
83
	 * @param int $id ID of the status.
84
	 *
85
	 * @return string|bool The status name if it exists, false otherwise.
86
	 */
87
	public function get_status_from_id($id)
88
	{
89
		return $this->language->lang(array_search($id, ext::$statuses));
90
	}
91
92
	/**
93
	 * Helper method for inserting new idea data
94
	 *
95
	 * @param array  $data  The array of data to insert
96
	 * @param string $table The name of the table
97
	 *
98
	 * @return int The ID of the inserted row
99
	 */
100
	protected function insert_idea_data(array $data, $table)
101
	{
102
		$sql = 'INSERT INTO ' . $table . '
103
		' . $this->db->sql_build_array('INSERT', $data);
104
		$this->db->sql_query($sql);
105
106
		return (int) $this->db->sql_nextid();
107
	}
108
109
	/**
110
	 * Helper method for updating idea data
111
	 *
112
	 * @param array  $data  The array of data to insert
113
	 * @param int    $id    The ID of the idea
114
	 * @param string $table The name of the table
115
	 *
116
	 * @return void
117
	 */
118
	protected function update_idea_data(array $data, $id, $table)
119
	{
120
		$sql = 'UPDATE ' . $table . '
121
			SET ' . $this->db->sql_build_array('UPDATE', $data) . '
122
			WHERE idea_id = ' . (int) $id;
123
		$this->db->sql_query($sql);
124
	}
125
126
	/**
127
	 * Helper method for deleting idea data
128
	 *
129
	 * @param int    $id    The ID of the idea
130
	 * @param string $table The name of the table
131
	 *
132
	 * @return bool True if idea was deleted, false otherwise
133
	 */
134
	protected function delete_idea_data($id, $table)
135
	{
136
		$sql = 'DELETE FROM ' . $table . '
137
			WHERE idea_id = ' . (int) $id;
138
		$this->db->sql_query($sql);
139
140
		return (bool) $this->db->sql_affectedrows();
141
	}
142
}
143