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

status   A

Complexity

Total Complexity 21

Size/Duplication

Total Lines 244
Duplicated Lines 0 %

Importance

Changes 6
Bugs 1 Features 0
Metric Value
wmc 21
eloc 40
c 6
b 1
f 0
dl 0
loc 244
rs 10

18 Methods

Rating   Name   Duplication   Size   Complexity  
A create_insert_array() 0 8 1
A is_available() 0 3 1
A get_avatar() 0 4 2
A set_config() 0 3 1
A find_users_for_notification() 0 12 2
A users_to_query() 0 3 1
A get_reference() 0 3 1
A pre_create_insert_array() 0 12 2
A set_idea_factory() 0 3 1
A get_item_id() 0 3 1
A set_controller_helper() 0 3 1
A set_user_loader() 0 3 1
A get_url() 0 5 1
A get_email_template() 0 3 1
A get_email_template_variables() 0 3 1
A get_title() 0 3 1
A get_item_parent_id() 0 3 1
A get_type() 0 3 1
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
0 ignored issues
show
Bug introduced by
The type phpbb\notification\type\base 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...
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
		return $this->language->lang('PHPBB_IDEAS_NOTIFICATION', $this->get_data('idea_title'));
178
	}
179
180
	/**
181
	 * Get the HTML-formatted reference of the notification
182
	 *
183
	 * @return string
184
	 */
185
	public function get_reference()
186
	{
187
		return  $this->language->lang(ext::status_name($this->get_data('status')));
188
	}
189
190
	/**
191
	 * Get the url to this item
192
	 *
193
	 * @return string URL
194
	 */
195
	public function get_url()
196
	{
197
		$params = ['idea_id' => $this->get_data('idea_id')];
198
199
		return $this->helper->route('phpbb_ideas_idea_controller', $params);
200
	}
201
202
	/**
203
	 * Get email template
204
	 *
205
	 * @return string|bool
206
	 */
207
	public function get_email_template()
208
	{
209
		return false;
210
	}
211
212
	/**
213
	 * Get email template variables
214
	 *
215
	 * @return array
216
	 */
217
	public function get_email_template_variables()
218
	{
219
		return [];
220
	}
221
222
	/**
223
	 * Pre create insert array function
224
	 * This allows you to perform certain actions, like run a query
225
	 * and load data, before create_insert_array() is run. The data
226
	 * returned from this function will be sent to create_insert_array().
227
	 *
228
	 * @param array $type_data The type-specific data
229
	 * @param array $notify_users Notify users list
230
	 * 		Formatted from find_users_for_notification()
231
	 * @return array Whatever you want to send to create_insert_array().
232
	 */
233
	public function pre_create_insert_array($type_data, $notify_users)
234
	{
235
		$pre_create_data = [];
236
237
		$idea = $this->idea->get_idea($type_data['idea_id']);
238
		if ($idea !== false)
239
		{
240
			$pre_create_data['idea_title'] = $idea['idea_title'];
241
			$pre_create_data['idea_author'] = $idea['idea_author'];
242
		}
243
244
		return $pre_create_data;
245
	}
246
247
	/**
248
	 * Function for preparing the data for insertion in an SQL query
249
	 * (The service handles insertion)
250
	 *
251
	 * @param array $type_data The type-specific data
252
	 * @param array $pre_create_data Data from pre_create_insert_array()
253
	 */
254
	public function create_insert_array($type_data, $pre_create_data = [])
255
	{
256
		$this->set_data('idea_id', $type_data['idea_id']);
257
		$this->set_data('status', $type_data['status']);
258
		$this->set_data('idea_title', $pre_create_data['idea_title']);
259
		$this->set_data('idea_author', $pre_create_data['idea_author']);
260
261
		parent::create_insert_array($type_data, $pre_create_data);
262
	}
263
}
264