Passed
Pull Request — master (#159)
by Matt
02:50
created

status   A

Complexity

Total Complexity 17

Size/Duplication

Total Lines 200
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 17
eloc 32
c 1
b 0
f 0
dl 0
loc 200
rs 10

15 Methods

Rating   Name   Duplication   Size   Complexity  
A create_insert_array() 0 7 1
A is_available() 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 11 2
A set_idea_factory() 0 3 1
A get_item_id() 0 3 1
A set_controller_helper() 0 3 1
A get_url() 0 5 1
A get_email_template() 0 3 1
A get_title() 0 3 1
A get_item_parent_id() 0 4 1
A get_email_template_variables() 0 3 1
A get_type() 0 3 1
1
<?php
2
/**
3
 *
4
 * ideas. An extension for the phpBB Forum Software package.
5
 *
6
 * @copyright (c) 2025
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\controller\helper */
21
	protected $helper;
22
23
	/** @var \phpbb\ideas\factory\idea */
24
	protected $idea;
25
26
	/**
27
	 * Set the controller helper
28
	 *
29
	 * @param \phpbb\controller\helper $helper
30
	 *
31
	 * @return void
32
	 */
33
	public function set_controller_helper(\phpbb\controller\helper $helper)
34
	{
35
		$this->helper = $helper;
36
	}
37
38
	/**
39
	 * Set the Idea helper
40
	 *
41
	 * @param \phpbb\ideas\factory\idea $idea
42
	 *
43
	 * @return void
44
	 */
45
	public function set_idea_factory(\phpbb\ideas\factory\idea $idea)
46
	{
47
		$this->idea = $idea;
48
	}
49
50
	/**
51
	 * Get notification type name
52
	 *
53
	 * @return string
54
	 */
55
	public function get_type()
56
	{
57
		return 'phpbb.ideas.notification.type.status';
58
	}
59
60
	/**
61
	 * Notification option data (for outputting to the user)
62
	 *
63
	 * @var bool|array False if the service should use its default data
64
	 * 					Array of data (including keys 'id', 'lang', and 'group')
65
	 */
66
	public static $notification_option = [
67
		'lang'	=> 'NOTIFICATION_TYPE_IDEAS',
68
	];
69
70
	/**
71
	 * Is this type available to the current user (defines whether it will be shown in the UCP Edit notification options)
72
	 *
73
	 * @return bool True/False whether this is available to the user
74
	 */
75
	public function is_available()
76
	{
77
		return true; //(bool) $this->config['ideas_forum_id'];
78
	}
79
80
	/**
81
	 * Get the id of the notification
82
	 *
83
	 * @param array $type_data The type-specific data
84
	 *
85
	 * @return int Id of the notification
86
	 */
87
	public static function get_item_id($type_data)
88
	{
89
		return $type_data['idea_id'];
90
	}
91
92
	/**
93
	 * Get the id of the parent
94
	 *
95
	 * @param array $type_data The type-specific data
96
	 *
97
	 * @return int Id of the parent
98
	 */
99
	public static function get_item_parent_id($type_data)
100
	{
101
		// No parent
102
		return 0;
103
	}
104
105
	/**
106
	 * Find the users who want to receive notifications
107
	 *
108
	 * @param array $type_data The type-specific data
109
	 * @param array $options Options for finding users for notification
110
	 * 		ignore_users => array of users and user types that should not receive notifications from this type because they've already been notified
111
	 * 						e.g.: [2 => [''], 3 => ['', 'email'], ...]
112
	 *
113
	 * @return array
114
	 */
115
	public function find_users_for_notification($type_data, $options = [])
116
	{
117
		$users = [];
118
119
		$idea = $this->idea->get_idea($type_data['idea_id']);
120
121
		if ($idea !== false)
122
		{
123
			$users[$idea['idea_author']] = $this->notification_manager->get_default_methods();
124
		}
125
126
		return $users;
127
	}
128
129
	/**
130
	 * Users needed to query before this notification can be displayed
131
	 *
132
	 * @return array Array of user_ids
133
	 */
134
	public function users_to_query()
135
	{
136
		return [];
137
	}
138
139
	/**
140
	 * Get the HTML-formatted title of this notification
141
	 *
142
	 * @return string
143
	 */
144
	public function get_title()
145
	{
146
		return $this->language->lang('PHPBB_IDEAS_NOTIFICATION', $this->get_data('idea_title'));
147
	}
148
149
	/**
150
	 * Get the HTML-formatted reference of the notification
151
	 *
152
	 * @return string
153
	 */
154
	public function get_reference()
155
	{
156
		return  $this->language->lang(ext::status_name($this->get_data('status')));
157
	}
158
159
	/**
160
	 * Get the url to this item
161
	 *
162
	 * @return string URL
163
	 */
164
	public function get_url()
165
	{
166
		$params = ['idea_id' => $this->get_data('idea_id')];
167
168
		return $this->helper->route('phpbb_ideas_idea_controller', $params);
169
	}
170
171
	/**
172
	 * Get email template
173
	 *
174
	 * @return string|bool
175
	 */
176
	public function get_email_template()
177
	{
178
		return false;
179
	}
180
181
	/**
182
	 * Get email template variables
183
	 *
184
	 * @return array
185
	 */
186
	public function get_email_template_variables()
187
	{
188
		return [];
189
	}
190
191
	public function pre_create_insert_array($type_data, $notify_users)
192
	{
193
		$pre_create_data = [];
194
195
		$idea = $this->idea->get_idea($type_data['idea_id']);
196
		if ($idea !== false)
197
		{
198
			$pre_create_data['idea_title'] = $idea['idea_title'];
199
		}
200
201
		return $pre_create_data;
202
	}
203
204
	/**
205
	 * Function for preparing the data for insertion in an SQL query
206
	 * (The service handles insertion)
207
	 *
208
	 * @param array $type_data The type-specific data
209
	 * @param array $pre_create_data Data from pre_create_insert_array()
210
	 */
211
	public function create_insert_array($type_data, $pre_create_data = [])
212
	{
213
		$this->set_data('idea_id', $type_data['idea_id']);
214
		$this->set_data('status', $type_data['status']);
215
		$this->set_data('idea_title', $pre_create_data['idea_title']);
216
217
		parent::create_insert_array($type_data, $pre_create_data);
218
	}
219
}
220