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