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\notification\type; |
12
|
|
|
|
13
|
|
|
use phpbb\ideas\ext; |
14
|
|
|
|
15
|
|
|
/** |
16
|
|
|
* Ideas status change notification class. |
17
|
|
|
*/ |
18
|
|
|
class status extends \phpbb\notification\type\base |
|
|
|
|
19
|
|
|
{ |
20
|
|
|
/** @var \phpbb\config\config */ |
21
|
|
|
protected $config; |
22
|
|
|
|
23
|
|
|
/** @var \phpbb\controller\helper */ |
24
|
|
|
protected $helper; |
25
|
|
|
|
26
|
|
|
/** @var \phpbb\ideas\factory\idea */ |
27
|
|
|
protected $idea; |
28
|
|
|
|
29
|
|
|
/** @var \phpbb\user_loader */ |
30
|
|
|
protected $user_loader; |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* Set the controller helper |
34
|
|
|
* |
35
|
|
|
* @param \phpbb\controller\helper $helper |
36
|
|
|
* |
37
|
|
|
* @return void |
38
|
|
|
*/ |
39
|
|
|
public function set_controller_helper(\phpbb\controller\helper $helper) |
40
|
|
|
{ |
41
|
|
|
$this->helper = $helper; |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* Set the Idea object |
46
|
|
|
* |
47
|
|
|
* @param \phpbb\ideas\factory\idea $idea |
48
|
|
|
* |
49
|
|
|
* @return void |
50
|
|
|
*/ |
51
|
|
|
public function set_idea_factory(\phpbb\ideas\factory\idea $idea) |
52
|
|
|
{ |
53
|
|
|
$this->idea = $idea; |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
/** |
57
|
|
|
* Set the config object |
58
|
|
|
* |
59
|
|
|
* @param \phpbb\config\config $config |
60
|
|
|
* |
61
|
|
|
* @return void |
62
|
|
|
*/ |
63
|
|
|
public function set_config(\phpbb\config\config $config) |
64
|
|
|
{ |
65
|
|
|
$this->config = $config; |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
public function set_user_loader(\phpbb\user_loader $user_loader) |
69
|
|
|
{ |
70
|
|
|
$this->user_loader = $user_loader; |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
/** |
74
|
|
|
* Get notification type name |
75
|
|
|
* |
76
|
|
|
* @return string |
77
|
|
|
*/ |
78
|
|
|
public function get_type() |
79
|
|
|
{ |
80
|
|
|
return 'phpbb.ideas.notification.type.status'; |
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
/** |
84
|
|
|
* Notification option data (for outputting to the user) |
85
|
|
|
* |
86
|
|
|
* @var bool|array False if the service should use its default data |
87
|
|
|
* Array of data (including keys 'id', 'lang', and 'group') |
88
|
|
|
*/ |
89
|
|
|
public static $notification_option = [ |
90
|
|
|
'lang' => 'NOTIFICATION_TYPE_IDEAS', |
91
|
|
|
]; |
92
|
|
|
|
93
|
|
|
/** |
94
|
|
|
* Is this type available to the current user (defines whether it will be shown in the UCP Edit notification options) |
95
|
|
|
* |
96
|
|
|
* @return bool True/False whether this is available to the user |
97
|
|
|
*/ |
98
|
|
|
public function is_available() |
99
|
|
|
{ |
100
|
|
|
return (bool) $this->auth->acl_get('f_', $this->config['ideas_forum_id']); |
101
|
|
|
} |
102
|
|
|
|
103
|
|
|
/** |
104
|
|
|
* Get the id of the notification |
105
|
|
|
* |
106
|
|
|
* @param array $type_data The type-specific data |
107
|
|
|
* |
108
|
|
|
* @return int ID of the notification |
109
|
|
|
*/ |
110
|
|
|
public static function get_item_id($type_data) |
111
|
|
|
{ |
112
|
|
|
return (int) ($type_data['idea_id'] . $type_data['status']); |
113
|
|
|
} |
114
|
|
|
|
115
|
|
|
/** |
116
|
|
|
* Get the id of the parent |
117
|
|
|
* |
118
|
|
|
* @param array $type_data The type-specific data |
119
|
|
|
* |
120
|
|
|
* @return int ID of the parent |
121
|
|
|
*/ |
122
|
|
|
public static function get_item_parent_id($type_data) |
123
|
|
|
{ |
124
|
|
|
return 0; |
125
|
|
|
} |
126
|
|
|
|
127
|
|
|
/** |
128
|
|
|
* Find the users who want to receive notifications |
129
|
|
|
* |
130
|
|
|
* @param array $type_data The type-specific data |
131
|
|
|
* @param array $options Options for finding users for notification |
132
|
|
|
* ignore_users => array of users and user types that should not receive notifications from this type because they've already been notified |
133
|
|
|
* e.g.: [2 => [''], 3 => ['', 'email'], ...] |
134
|
|
|
* |
135
|
|
|
* @return array |
136
|
|
|
*/ |
137
|
|
|
public function find_users_for_notification($type_data, $options = []) |
138
|
|
|
{ |
139
|
|
|
$users = []; |
140
|
|
|
|
141
|
|
|
$idea = $this->idea->get_idea($type_data['idea_id']); |
142
|
|
|
|
143
|
|
|
if ($idea !== false) |
144
|
|
|
{ |
145
|
|
|
$users[$idea['idea_author']] = $this->notification_manager->get_default_methods(); |
146
|
|
|
} |
147
|
|
|
|
148
|
|
|
return $users; |
149
|
|
|
} |
150
|
|
|
|
151
|
|
|
/** |
152
|
|
|
* Get the user's avatar |
153
|
|
|
*/ |
154
|
|
|
public function get_avatar() |
155
|
|
|
{ |
156
|
|
|
$author = (int) $this->get_data('idea_author'); |
157
|
|
|
return $author ? $this->user_loader->get_avatar($author, true) : ''; |
158
|
|
|
} |
159
|
|
|
|
160
|
|
|
/** |
161
|
|
|
* Users needed to query before this notification can be displayed |
162
|
|
|
* |
163
|
|
|
* @return array Array of user_ids |
164
|
|
|
*/ |
165
|
|
|
public function users_to_query() |
166
|
|
|
{ |
167
|
|
|
return []; |
168
|
|
|
} |
169
|
|
|
|
170
|
|
|
/** |
171
|
|
|
* Get the HTML-formatted title of this notification |
172
|
|
|
* |
173
|
|
|
* @return string |
174
|
|
|
*/ |
175
|
|
|
public function get_title() |
176
|
|
|
{ |
177
|
|
|
if (!$this->language->is_set('PHPBB_IDEAS_NOTIFICATION')) |
178
|
|
|
{ |
179
|
|
|
$this->language->add_lang('common', 'phpbb/ideas'); |
180
|
|
|
} |
181
|
|
|
return $this->language->lang('PHPBB_IDEAS_NOTIFICATION', $this->get_data('idea_title')); |
182
|
|
|
} |
183
|
|
|
|
184
|
|
|
/** |
185
|
|
|
* Get the HTML-formatted reference of the notification |
186
|
|
|
* |
187
|
|
|
* @return string |
188
|
|
|
*/ |
189
|
|
|
public function get_reference() |
190
|
|
|
{ |
191
|
|
|
return $this->language->lang(ext::status_name($this->get_data('status'))); |
192
|
|
|
} |
193
|
|
|
|
194
|
|
|
/** |
195
|
|
|
* Get the url to this item |
196
|
|
|
* |
197
|
|
|
* @return string URL |
198
|
|
|
*/ |
199
|
|
|
public function get_url() |
200
|
|
|
{ |
201
|
|
|
$params = ['idea_id' => $this->get_data('idea_id')]; |
202
|
|
|
|
203
|
|
|
return $this->helper->route('phpbb_ideas_idea_controller', $params); |
204
|
|
|
} |
205
|
|
|
|
206
|
|
|
/** |
207
|
|
|
* Get email template |
208
|
|
|
* |
209
|
|
|
* @return string|bool |
210
|
|
|
*/ |
211
|
|
|
public function get_email_template() |
212
|
|
|
{ |
213
|
|
|
return '@phpbb_ideas/status_notification'; |
214
|
|
|
} |
215
|
|
|
|
216
|
|
|
/** |
217
|
|
|
* Get email template variables |
218
|
|
|
* |
219
|
|
|
* @return array |
220
|
|
|
*/ |
221
|
|
|
public function get_email_template_variables() |
222
|
|
|
{ |
223
|
|
|
return [ |
224
|
|
|
'IDEA_TITLE' => html_entity_decode(censor_text($this->get_data('idea_title')), ENT_COMPAT), |
|
|
|
|
225
|
|
|
'STATUS' => html_entity_decode($this->language->lang(ext::status_name($this->get_data('status'))), ENT_COMPAT), |
226
|
|
|
'U_VIEW_IDEA' => $this->get_url(), |
227
|
|
|
]; |
228
|
|
|
} |
229
|
|
|
|
230
|
|
|
/** |
231
|
|
|
* Pre create insert array function |
232
|
|
|
* This allows you to perform certain actions, like run a query |
233
|
|
|
* and load data, before create_insert_array() is run. The data |
234
|
|
|
* returned from this function will be sent to create_insert_array(). |
235
|
|
|
* |
236
|
|
|
* @param array $type_data The type-specific data |
237
|
|
|
* @param array $notify_users Notify users list |
238
|
|
|
* Formatted from find_users_for_notification() |
239
|
|
|
* @return array Whatever you want to send to create_insert_array(). |
240
|
|
|
*/ |
241
|
|
|
public function pre_create_insert_array($type_data, $notify_users) |
242
|
|
|
{ |
243
|
|
|
$pre_create_data = []; |
244
|
|
|
|
245
|
|
|
$idea = $this->idea->get_idea($type_data['idea_id']); |
246
|
|
|
if ($idea !== false) |
247
|
|
|
{ |
248
|
|
|
$pre_create_data['idea_title'] = $idea['idea_title']; |
249
|
|
|
$pre_create_data['idea_author'] = $idea['idea_author']; |
250
|
|
|
} |
251
|
|
|
|
252
|
|
|
return $pre_create_data; |
253
|
|
|
} |
254
|
|
|
|
255
|
|
|
/** |
256
|
|
|
* Function for preparing the data for insertion in an SQL query |
257
|
|
|
* (The service handles insertion) |
258
|
|
|
* |
259
|
|
|
* @param array $type_data The type-specific data |
260
|
|
|
* @param array $pre_create_data Data from pre_create_insert_array() |
261
|
|
|
*/ |
262
|
|
|
public function create_insert_array($type_data, $pre_create_data = []) |
263
|
|
|
{ |
264
|
|
|
$this->set_data('idea_id', $type_data['idea_id']); |
265
|
|
|
$this->set_data('status', $type_data['status']); |
266
|
|
|
$this->set_data('idea_title', $pre_create_data['idea_title']); |
267
|
|
|
$this->set_data('idea_author', $pre_create_data['idea_author']); |
268
|
|
|
|
269
|
|
|
parent::create_insert_array($type_data, $pre_create_data); |
270
|
|
|
} |
271
|
|
|
} |
272
|
|
|
|
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:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths