Passed
Pull Request — master (#159)
by Matt
01:31
created

factory/base.php (1 issue)

Labels
Severity
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\language\language;
17
use phpbb\notification\manager as notification_manager;
0 ignored issues
show
The type phpbb\notification\manager was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
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 notification_manager */
38
	protected $notification_manager;
39
40
	/* @var user */
41
	protected $user;
42
43
	/** @var string */
44
	protected $table_ideas;
45
46
	/** @var string */
47
	protected $table_votes;
48
49
	/** @var string */
50
	protected $table_topics;
51
52
	/** @var string */
53
	protected $php_ext;
54
55
	/**
56
	 * Constructor
57
	 *
58
	 * @param auth $auth
59
	 * @param config $config
60
	 * @param driver_interface $db
61
	 * @param language $language
62
	 * @param notification_manager $notification_manager
63
	 * @param user $user
64
	 * @param string $table_ideas
65
	 * @param string $table_votes
66
	 * @param string $table_topics
67
	 * @param string $phpEx
68
	 */
69
	public function __construct(auth $auth, config $config, driver_interface $db, language $language, notification_manager $notification_manager, user $user, $table_ideas, $table_votes, $table_topics, $phpEx)
70
	{
71
		$this->auth = $auth;
72
		$this->config = $config;
73
		$this->db = $db;
74
		$this->language = $language;
75
		$this->notification_manager = $notification_manager;
76
		$this->user = $user;
77
78
		$this->php_ext = $phpEx;
79
80
		$this->table_ideas = $table_ideas;
81
		$this->table_votes = $table_votes;
82
		$this->table_topics = $table_topics;
83
	}
84
85
	/**
86
	 * Helper method for inserting new idea data
87
	 *
88
	 * @param array  $data  The array of data to insert
89
	 * @param string $table The name of the table
90
	 *
91
	 * @return int The ID of the inserted row
92
	 */
93
	protected function insert_idea_data(array $data, $table)
94
	{
95
		$sql = 'INSERT INTO ' . $table . '
96
		' . $this->db->sql_build_array('INSERT', $data);
97
		$this->db->sql_query($sql);
98
99
		return (int) $this->db->sql_nextid();
100
	}
101
102
	/**
103
	 * Helper method for updating idea data
104
	 *
105
	 * @param array  $data  The array of data to insert
106
	 * @param int    $id    The ID of the idea
107
	 * @param string $table The name of the table
108
	 *
109
	 * @return void
110
	 */
111
	protected function update_idea_data(array $data, $id, $table)
112
	{
113
		$sql = 'UPDATE ' . $table . '
114
			SET ' . $this->db->sql_build_array('UPDATE', $data) . '
115
			WHERE idea_id = ' . (int) $id;
116
		$this->db->sql_query($sql);
117
	}
118
119
	/**
120
	 * Helper method for deleting idea data
121
	 *
122
	 * @param int    $id    The ID of the idea
123
	 * @param string $table The name of the table
124
	 *
125
	 * @return bool True if idea was deleted, false otherwise
126
	 */
127
	protected function delete_idea_data($id, $table)
128
	{
129
		$sql = 'DELETE FROM ' . $table . '
130
			WHERE idea_id = ' . (int) $id;
131
		$this->db->sql_query($sql);
132
133
		return (bool) $this->db->sql_affectedrows();
134
	}
135
}
136