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\config\config; |
14
|
|
|
use phpbb\controller\helper; |
15
|
|
|
use phpbb\ideas\ext; |
16
|
|
|
use phpbb\ideas\factory\idea; |
17
|
|
|
use phpbb\user_loader; |
18
|
|
|
use Symfony\Component\Routing\Generator\UrlGeneratorInterface; |
|
|
|
|
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* Ideas status change notification class. |
22
|
|
|
*/ |
23
|
|
|
class status extends \phpbb\notification\type\base |
|
|
|
|
24
|
|
|
{ |
25
|
|
|
/** @var config */ |
26
|
|
|
protected $config; |
27
|
|
|
|
28
|
|
|
/** @var helper */ |
29
|
|
|
protected $helper; |
30
|
|
|
|
31
|
|
|
/** @var idea */ |
32
|
|
|
protected $idea; |
33
|
|
|
|
34
|
|
|
/** @var user_loader */ |
35
|
|
|
protected $user_loader; |
36
|
|
|
|
37
|
|
|
/** @var int */ |
38
|
|
|
protected $ideas_forum_id; |
39
|
|
|
|
40
|
|
|
/** @var array */ |
41
|
|
|
protected $idea_cache = []; |
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* Set additional services and properties |
45
|
|
|
* |
46
|
|
|
* @param config $config |
47
|
|
|
* @param helper $helper |
48
|
|
|
* @param idea $idea |
49
|
|
|
* @param user_loader $user_loader |
50
|
|
|
* @return void |
51
|
|
|
*/ |
52
|
|
|
public function set_additional_services(config $config, helper $helper, idea $idea, user_loader $user_loader) |
53
|
|
|
{ |
54
|
|
|
$this->helper = $helper; |
55
|
|
|
$this->idea = $idea; |
56
|
|
|
$this->user_loader = $user_loader; |
57
|
|
|
$this->ideas_forum_id = (int) $config['ideas_forum_id']; |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
/** |
61
|
|
|
* Email template to use to send notifications |
62
|
|
|
* |
63
|
|
|
* @var string |
64
|
|
|
*/ |
65
|
|
|
protected $email_template = '@phpbb_ideas/status_notification'; |
66
|
|
|
|
67
|
|
|
/** |
68
|
|
|
* Language key used to output the text |
69
|
|
|
* |
70
|
|
|
* @var string |
71
|
|
|
*/ |
72
|
|
|
protected $language_key = 'IDEA_STATUS_CHANGE'; |
73
|
|
|
|
74
|
|
|
/** |
75
|
|
|
* {@inheritDoc} |
76
|
|
|
*/ |
77
|
|
|
public static $notification_option = [ |
78
|
|
|
'lang' => 'NOTIFICATION_TYPE_IDEAS', |
79
|
|
|
'group' => 'NOTIFICATION_GROUP_MISCELLANEOUS', |
80
|
|
|
]; |
81
|
|
|
|
82
|
|
|
/** |
83
|
|
|
* {@inheritDoc} |
84
|
|
|
*/ |
85
|
|
|
public function get_type() |
86
|
|
|
{ |
87
|
|
|
return 'phpbb.ideas.notification.type.status'; |
88
|
|
|
} |
89
|
|
|
|
90
|
|
|
/** |
91
|
|
|
* {@inheritDoc} |
92
|
|
|
*/ |
93
|
|
|
public static function get_item_id($type_data) |
94
|
|
|
{ |
95
|
|
|
return (int) $type_data['idea_id']; |
96
|
|
|
} |
97
|
|
|
|
98
|
|
|
/** |
99
|
|
|
* {@inheritDoc} |
100
|
|
|
*/ |
101
|
|
|
public static function get_item_parent_id($type_data) |
102
|
|
|
{ |
103
|
|
|
return 0; |
104
|
|
|
} |
105
|
|
|
|
106
|
|
|
/** |
107
|
|
|
* {@inheritDoc} |
108
|
|
|
*/ |
109
|
|
|
public function is_available() |
110
|
|
|
{ |
111
|
|
|
return (bool) $this->auth->acl_get('f_read', $this->ideas_forum_id); |
112
|
|
|
} |
113
|
|
|
|
114
|
|
|
/** |
115
|
|
|
* {@inheritDoc} |
116
|
|
|
*/ |
117
|
|
|
public function find_users_for_notification($type_data, $options = []) |
118
|
|
|
{ |
119
|
|
|
$options = array_merge([ |
120
|
|
|
'ignore_users' => [], |
121
|
|
|
], $options); |
122
|
|
|
|
123
|
|
|
$idea = $this->load_idea($type_data['idea_id']); |
124
|
|
|
|
125
|
|
|
$users = $idea ? [$idea['idea_author']] : []; |
126
|
|
|
|
127
|
|
|
return $this->get_authorised_recipients($users, $this->ideas_forum_id, $options); |
128
|
|
|
} |
129
|
|
|
|
130
|
|
|
/** |
131
|
|
|
* {@inheritDoc} |
132
|
|
|
*/ |
133
|
|
|
public function users_to_query() |
134
|
|
|
{ |
135
|
|
|
return [$this->get_data('idea_author')]; |
136
|
|
|
} |
137
|
|
|
|
138
|
|
|
/** |
139
|
|
|
* {@inheritDoc} |
140
|
|
|
*/ |
141
|
|
|
public function get_title() |
142
|
|
|
{ |
143
|
|
|
if (!$this->language->is_set($this->language_key)) |
144
|
|
|
{ |
145
|
|
|
$this->language->add_lang('common', 'phpbb/ideas'); |
146
|
|
|
} |
147
|
|
|
return $this->language->lang($this->language_key, $this->get_data('idea_title')); |
148
|
|
|
} |
149
|
|
|
|
150
|
|
|
/** |
151
|
|
|
* {@inheritDoc} |
152
|
|
|
*/ |
153
|
|
|
public function get_reference() |
154
|
|
|
{ |
155
|
|
|
return $this->language->lang(ext::status_name($this->get_data('status'))); |
156
|
|
|
} |
157
|
|
|
|
158
|
|
|
/** |
159
|
|
|
* {@inheritDoc} |
160
|
|
|
*/ |
161
|
|
|
public function get_url($reference_type = UrlGeneratorInterface::ABSOLUTE_PATH) |
162
|
|
|
{ |
163
|
|
|
$params = ['idea_id' => $this->get_data('idea_id')]; |
164
|
|
|
|
165
|
|
|
return $this->helper->route('phpbb_ideas_idea_controller', $params, true, false, $reference_type); |
166
|
|
|
} |
167
|
|
|
|
168
|
|
|
/** |
169
|
|
|
* {@inheritDoc} |
170
|
|
|
*/ |
171
|
|
|
public function get_avatar() |
172
|
|
|
{ |
173
|
|
|
return $this->user_loader->get_avatar($this->get_data('idea_author'), false, true); |
174
|
|
|
} |
175
|
|
|
|
176
|
|
|
/** |
177
|
|
|
* {@inheritDoc} |
178
|
|
|
*/ |
179
|
|
|
public function get_email_template() |
180
|
|
|
{ |
181
|
|
|
return $this->email_template; |
182
|
|
|
} |
183
|
|
|
|
184
|
|
|
/** |
185
|
|
|
* {@inheritDoc} |
186
|
|
|
*/ |
187
|
|
|
public function get_email_template_variables() |
188
|
|
|
{ |
189
|
|
|
return [ |
190
|
|
|
'IDEA_TITLE' => html_entity_decode(censor_text($this->get_data('idea_title')), ENT_COMPAT), |
|
|
|
|
191
|
|
|
'STATUS' => html_entity_decode($this->language->lang(ext::status_name($this->get_data('status'))), ENT_COMPAT), |
192
|
|
|
'U_VIEW_IDEA' => $this->get_url(UrlGeneratorInterface::ABSOLUTE_URL), |
193
|
|
|
]; |
194
|
|
|
} |
195
|
|
|
|
196
|
|
|
/** |
197
|
|
|
* {@inheritDoc} |
198
|
|
|
*/ |
199
|
|
|
public function create_insert_array($type_data, $pre_create_data = []) |
200
|
|
|
{ |
201
|
|
|
$idea = $this->load_idea($type_data['idea_id']); |
202
|
|
|
|
203
|
|
|
$this->set_data('idea_id', (int) $type_data['idea_id']); |
204
|
|
|
$this->set_data('status', (int) $type_data['status']); |
205
|
|
|
$this->set_data('idea_title', $idea ? $idea['idea_title'] : ''); |
206
|
|
|
$this->set_data('idea_author', $idea ? (int) $idea['idea_author'] : 0); |
207
|
|
|
|
208
|
|
|
parent::create_insert_array($type_data, $pre_create_data); |
209
|
|
|
} |
210
|
|
|
|
211
|
|
|
/** |
212
|
|
|
* Load and cache an idea by id |
213
|
|
|
* |
214
|
|
|
* @param int $idea_id |
215
|
|
|
* @return array|false |
216
|
|
|
*/ |
217
|
|
|
protected function load_idea($idea_id) |
218
|
|
|
{ |
219
|
|
|
$idea_id = (int) $idea_id; |
220
|
|
|
|
221
|
|
|
if (!array_key_exists($idea_id, $this->idea_cache)) |
222
|
|
|
{ |
223
|
|
|
$this->idea_cache[$idea_id] = $this->idea->get_idea($idea_id) ?: false; |
224
|
|
|
} |
225
|
|
|
|
226
|
|
|
return $this->idea_cache[$idea_id]; |
227
|
|
|
} |
228
|
|
|
} |
229
|
|
|
|
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