|
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
|
|
|
/** |
|
14
|
|
|
* Class for managing ideas |
|
15
|
|
|
*/ |
|
16
|
|
|
class manager |
|
17
|
|
|
{ |
|
18
|
|
|
/** @var \phpbb\ideas\factory\idea */ |
|
19
|
|
|
private $idea; |
|
20
|
|
|
|
|
21
|
|
|
/** @var \phpbb\ideas\factory\ideas */ |
|
22
|
|
|
private $ideas; |
|
23
|
|
|
|
|
24
|
|
|
/** @var \phpbb\ideas\factory\vote */ |
|
25
|
|
|
private $vote; |
|
26
|
|
|
|
|
27
|
|
|
/** |
|
28
|
|
|
* Ideas manager constructor |
|
29
|
|
|
* |
|
30
|
|
|
* @param \phpbb\ideas\factory\idea $idea |
|
31
|
|
|
* @param \phpbb\ideas\factory\ideas $ideas |
|
32
|
|
|
* @param \phpbb\ideas\factory\vote $vote |
|
33
|
|
|
*/ |
|
34
|
|
|
public function __construct(idea $idea, ideas $ideas, vote $vote) |
|
35
|
|
|
{ |
|
36
|
|
|
$this->vote = $vote; |
|
37
|
|
|
$this->idea = $idea; |
|
38
|
|
|
$this->ideas = $ideas; |
|
39
|
|
|
} |
|
40
|
|
|
|
|
41
|
|
|
/** |
|
42
|
|
|
* Returns an array of ideas. Defaults to ten ideas ordered by date |
|
43
|
|
|
* excluding implemented, duplicate or invalid ideas. |
|
44
|
|
|
* |
|
45
|
|
|
* @param int $number The number of ideas to return |
|
46
|
|
|
* @param string $sort A sorting option/collection |
|
47
|
|
|
* @param string $direction Should either be ASC or DESC |
|
48
|
|
|
* @param array|int $status The id of the status(es) to load |
|
49
|
|
|
* @param int $start Start value for pagination |
|
50
|
|
|
* |
|
51
|
|
|
* @return array Array of row data |
|
52
|
|
|
*/ |
|
53
|
|
|
public function get_ideas($number = 10, $sort = 'date', $direction = 'DESC', $status = [], $start = 0) |
|
54
|
|
|
{ |
|
55
|
|
|
return $this->ideas->get($number, $sort, $direction, $status, $start); |
|
56
|
|
|
} |
|
57
|
|
|
|
|
58
|
|
|
/** |
|
59
|
|
|
* Get the stored idea count |
|
60
|
|
|
* Note: this should only be called after get_ideas() |
|
61
|
|
|
* |
|
62
|
|
|
* @return int Count of ideas |
|
63
|
|
|
*/ |
|
64
|
|
|
public function get_idea_count() |
|
65
|
|
|
{ |
|
66
|
|
|
return $this->ideas->count(); |
|
67
|
|
|
} |
|
68
|
|
|
|
|
69
|
|
|
/** |
|
70
|
|
|
* Returns the specified idea. |
|
71
|
|
|
* |
|
72
|
|
|
* @param int $id The ID of the idea to return. |
|
73
|
|
|
* |
|
74
|
|
|
* @return array|false The idea row set, or false if not found. |
|
75
|
|
|
*/ |
|
76
|
|
|
public function get_idea($id) |
|
77
|
|
|
{ |
|
78
|
|
|
return $this->idea->get_idea($id); |
|
79
|
|
|
} |
|
80
|
|
|
|
|
81
|
|
|
/** |
|
82
|
|
|
* Returns an idea specified by its topic ID. |
|
83
|
|
|
* |
|
84
|
|
|
* @param int $id The ID of the idea to return. |
|
85
|
|
|
* |
|
86
|
|
|
* @return array|false The idea row set, or false if not found. |
|
87
|
|
|
*/ |
|
88
|
|
|
public function get_idea_by_topic_id($id) |
|
89
|
|
|
{ |
|
90
|
|
|
return $this->idea->get_idea_by_topic_id($id); |
|
91
|
|
|
} |
|
92
|
|
|
|
|
93
|
|
|
/** |
|
94
|
|
|
* Returns the status name from the status ID specified. |
|
95
|
|
|
* |
|
96
|
|
|
* @param int $id ID of the status. |
|
97
|
|
|
* |
|
98
|
|
|
* @return string|bool The status name if it exists, false otherwise. |
|
99
|
|
|
*/ |
|
100
|
|
|
public function get_status_from_id($id) |
|
101
|
|
|
{ |
|
102
|
|
|
return $this->idea->get_status_from_id($id); |
|
103
|
|
|
} |
|
104
|
|
|
|
|
105
|
|
|
/** |
|
106
|
|
|
* Updates the status of an idea. |
|
107
|
|
|
* |
|
108
|
|
|
* @param int $idea_id The ID of the idea. |
|
109
|
|
|
* @param int $status The ID of the status. |
|
110
|
|
|
* |
|
111
|
|
|
* @return void |
|
112
|
|
|
*/ |
|
113
|
|
|
public function set_status($idea_id, $status) |
|
114
|
|
|
{ |
|
115
|
|
|
$this->idea->set_status($idea_id, $status); |
|
116
|
|
|
} |
|
117
|
|
|
|
|
118
|
|
|
/** |
|
119
|
|
|
* Sets the ID of the duplicate for an idea. |
|
120
|
|
|
* |
|
121
|
|
|
* @param int $idea_id ID of the idea to be updated. |
|
122
|
|
|
* @param string $duplicate Idea ID of duplicate. |
|
123
|
|
|
* |
|
124
|
|
|
* @return bool True if set, false if invalid. |
|
125
|
|
|
*/ |
|
126
|
|
|
public function set_duplicate($idea_id, $duplicate) |
|
127
|
|
|
{ |
|
128
|
|
|
return $this->idea->set_duplicate($idea_id, $duplicate); |
|
129
|
|
|
} |
|
130
|
|
|
|
|
131
|
|
|
/** |
|
132
|
|
|
* Sets the RFC link of an idea. |
|
133
|
|
|
* |
|
134
|
|
|
* @param int $idea_id ID of the idea to be updated. |
|
135
|
|
|
* @param string $rfc Link to the RFC. |
|
136
|
|
|
* |
|
137
|
|
|
* @return bool True if set, false if invalid. |
|
138
|
|
|
*/ |
|
139
|
|
|
public function set_rfc($idea_id, $rfc) |
|
140
|
|
|
{ |
|
141
|
|
|
return $this->idea->set_rfc($idea_id, $rfc); |
|
142
|
|
|
} |
|
143
|
|
|
|
|
144
|
|
|
/** |
|
145
|
|
|
* Sets the ticket ID of an idea. |
|
146
|
|
|
* |
|
147
|
|
|
* @param int $idea_id ID of the idea to be updated. |
|
148
|
|
|
* @param string $ticket Ticket ID. |
|
149
|
|
|
* |
|
150
|
|
|
* @return bool True if set, false if invalid. |
|
151
|
|
|
*/ |
|
152
|
|
|
public function set_ticket($idea_id, $ticket) |
|
153
|
|
|
{ |
|
154
|
|
|
return $this->idea->set_ticket($idea_id, $ticket); |
|
155
|
|
|
} |
|
156
|
|
|
|
|
157
|
|
|
/** |
|
158
|
|
|
* Sets the implemented version of an idea. |
|
159
|
|
|
* |
|
160
|
|
|
* @param int $idea_id ID of the idea to be updated. |
|
161
|
|
|
* @param string $version Version of phpBB the idea was implemented in. |
|
162
|
|
|
* |
|
163
|
|
|
* @return bool True if set, false if invalid. |
|
164
|
|
|
*/ |
|
165
|
|
|
public function set_implemented($idea_id, $version) |
|
166
|
|
|
{ |
|
167
|
|
|
return $this->idea->set_implemented($idea_id, $version); |
|
168
|
|
|
} |
|
169
|
|
|
|
|
170
|
|
|
/** |
|
171
|
|
|
* Sets the title of an idea. |
|
172
|
|
|
* |
|
173
|
|
|
* @param int $idea_id ID of the idea to be updated. |
|
174
|
|
|
* @param string $title New title. |
|
175
|
|
|
* |
|
176
|
|
|
* @return boolean True if updated, false if invalid length. |
|
177
|
|
|
*/ |
|
178
|
|
|
public function set_title($idea_id, $title) |
|
179
|
|
|
{ |
|
180
|
|
|
return $this->idea->set_title($idea_id, $title); |
|
181
|
|
|
} |
|
182
|
|
|
|
|
183
|
|
|
/** |
|
184
|
|
|
* Get the title of an idea. |
|
185
|
|
|
* |
|
186
|
|
|
* @param int $id ID of an idea |
|
187
|
|
|
* |
|
188
|
|
|
* @return string The idea's title, empty string if not found |
|
189
|
|
|
*/ |
|
190
|
|
|
public function get_title($id) |
|
191
|
|
|
{ |
|
192
|
|
|
return $this->idea->get_title($id); |
|
193
|
|
|
} |
|
194
|
|
|
|
|
195
|
|
|
/** |
|
196
|
|
|
* Submit new idea data to the ideas table |
|
197
|
|
|
* |
|
198
|
|
|
* @param array $data An array of post data from a newly posted idea |
|
199
|
|
|
* |
|
200
|
|
|
* @return int The ID of the new idea. |
|
201
|
|
|
*/ |
|
202
|
|
|
public function submit($data) |
|
203
|
|
|
{ |
|
204
|
|
|
return $this->idea->submit($data); |
|
205
|
|
|
} |
|
206
|
|
|
|
|
207
|
|
|
/** |
|
208
|
|
|
* Deletes an idea and the topic to go with it. |
|
209
|
|
|
* |
|
210
|
|
|
* @param int $id The ID of the idea to be deleted. |
|
211
|
|
|
* @param int $topic_id The ID of the idea topic. Optional, but preferred. |
|
212
|
|
|
* |
|
213
|
|
|
* @return boolean Whether the idea was deleted or not. |
|
214
|
|
|
*/ |
|
215
|
|
|
public function delete($id, $topic_id = 0) |
|
216
|
|
|
{ |
|
217
|
|
|
return $this->idea->delete($id, $topic_id); |
|
218
|
|
|
} |
|
219
|
|
|
|
|
220
|
|
|
/** |
|
221
|
|
|
* Do a live search on idea titles. Return any matches based on a given search query. |
|
222
|
|
|
* |
|
223
|
|
|
* @param string $search The string of characters to search using LIKE |
|
224
|
|
|
* @param int $limit The number of results to return |
|
225
|
|
|
* |
|
226
|
|
|
* @return array An array of matching idea id/key and title/values |
|
227
|
|
|
*/ |
|
228
|
|
|
public function ideas_title_livesearch($search, $limit = 10) |
|
229
|
|
|
{ |
|
230
|
|
|
return $this->ideas->livesearch($search, $limit); |
|
231
|
|
|
} |
|
232
|
|
|
|
|
233
|
|
|
/** |
|
234
|
|
|
* Delete orphaned ideas. Orphaned ideas may exist after a |
|
235
|
|
|
* topic has been deleted or moved to another forum. |
|
236
|
|
|
* |
|
237
|
|
|
* @return int Number of rows affected |
|
238
|
|
|
*/ |
|
239
|
|
|
public function delete_orphans() |
|
240
|
|
|
{ |
|
241
|
|
|
return $this->ideas->delete_orphans(); |
|
242
|
|
|
} |
|
243
|
|
|
|
|
244
|
|
|
/** |
|
245
|
|
|
* Submits a vote on an idea. |
|
246
|
|
|
* |
|
247
|
|
|
* @param array $idea The idea returned by get_idea(). |
|
248
|
|
|
* @param int $user_id The ID of the user voting. |
|
249
|
|
|
* @param int $value Up (1) or down (0)? |
|
250
|
|
|
* |
|
251
|
|
|
* @return array|string Array of information or string on error. |
|
252
|
|
|
*/ |
|
253
|
|
|
public function vote(&$idea, $user_id, $value) |
|
254
|
|
|
{ |
|
255
|
|
|
return $this->vote->submit($idea, $user_id, $value); |
|
256
|
|
|
} |
|
257
|
|
|
|
|
258
|
|
|
/** |
|
259
|
|
|
* Remove a user's vote from an idea |
|
260
|
|
|
* |
|
261
|
|
|
* @param array $idea The idea returned by get_idea(). |
|
262
|
|
|
* @param int $user_id The ID of the user voting. |
|
263
|
|
|
* |
|
264
|
|
|
* @return array Array of information. |
|
265
|
|
|
*/ |
|
266
|
|
|
public function remove_vote(&$idea, $user_id) |
|
267
|
|
|
{ |
|
268
|
|
|
return $this->vote->remove($idea, $user_id); |
|
269
|
|
|
} |
|
270
|
|
|
|
|
271
|
|
|
/** |
|
272
|
|
|
* Returns voter info on an idea. |
|
273
|
|
|
* |
|
274
|
|
|
* @param int $id ID of the idea. |
|
275
|
|
|
* |
|
276
|
|
|
* @return array Array of row data |
|
277
|
|
|
*/ |
|
278
|
|
|
public function get_voters($id) |
|
279
|
|
|
{ |
|
280
|
|
|
return $this->vote->get_voters($id); |
|
281
|
|
|
} |
|
282
|
|
|
} |
|
283
|
|
|
|