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

status   A

Complexity

Total Complexity 16

Size/Duplication

Total Lines 183
Duplicated Lines 0 %

Importance

Changes 11
Bugs 1 Features 0
Metric Value
wmc 16
eloc 44
c 11
b 1
f 0
dl 0
loc 183
rs 10

14 Methods

Rating   Name   Duplication   Size   Complexity  
A get_email_template() 0 3 1
A get_type() 0 3 1
A is_available() 0 3 1
A get_avatar() 0 3 1
A find_users_for_notification() 0 11 2
A users_to_query() 0 3 1
A get_reference() 0 3 1
A get_item_id() 0 3 1
A set_additional_services() 0 6 1
A get_url() 0 5 1
A get_title() 0 7 2
A get_item_parent_id() 0 3 1
A get_email_template_variables() 0 6 1
A create_insert_array() 0 10 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\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;
0 ignored issues
show
Bug introduced by
The type Symfony\Component\Routin...r\UrlGeneratorInterface 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
/**
21
 * Ideas status change notification class.
22
 */
23
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...
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
	/**
41
	 * Set additional services and properties
42
	 *
43
	 * @param config $config
44
	 * @param helper $helper
45
	 * @param idea $idea
46
	 * @param user_loader $user_loader
47
	 * @return void
48
	 */
49
	public function set_additional_services(config $config, helper $helper, idea $idea, user_loader $user_loader)
50
	{
51
		$this->helper = $helper;
52
		$this->idea = $idea;
53
		$this->user_loader = $user_loader;
54
		$this->ideas_forum_id = (int) $config['ideas_forum_id'];
55
	}
56
57
	/**
58
	 * Email template to use to send notifications
59
	 *
60
	 * @var string
61
	 */
62
	protected $email_template = '@phpbb_ideas/status_notification';
63
64
	/**
65
	 * Language key used to output the text
66
	 *
67
	 * @var string
68
	 */
69
	protected $language_key = 'IDEA_STATUS_CHANGE';
70
71
	/**
72
	 * {@inheritDoc}
73
	 */
74
	public static $notification_option = [
75
		'lang'	=> 'NOTIFICATION_TYPE_IDEAS',
76
		'group'	=> 'NOTIFICATION_GROUP_MISCELLANEOUS',
77
	];
78
79
	/**
80
	 * {@inheritDoc}
81
	 */
82
	public function get_type()
83
	{
84
		return 'phpbb.ideas.notification.type.status';
85
	}
86
87
	/**
88
	 * {@inheritDoc}
89
	 */
90
	public static function get_item_id($type_data)
91
	{
92
		return (int) $type_data['idea_id'];
93
	}
94
95
	/**
96
	 * {@inheritDoc}
97
	 */
98
	public static function get_item_parent_id($type_data)
99
	{
100
		return 0;
101
	}
102
103
	/**
104
	 * {@inheritDoc}
105
	 */
106
	public function is_available()
107
	{
108
		return (bool) $this->auth->acl_get('f_read', $this->ideas_forum_id);
109
	}
110
111
	/**
112
	 * {@inheritDoc}
113
	 */
114
	public function find_users_for_notification($type_data, $options = [])
115
	{
116
		$options = array_merge([
117
			'ignore_users'		=> [],
118
		], $options);
119
120
		$idea = $this->idea->get_idea($type_data['idea_id']);
121
122
		$users = $idea ? [$idea['idea_author']] : [];
123
124
		return $this->get_authorised_recipients($users, $this->ideas_forum_id, $options);
125
	}
126
127
	/**
128
	 * {@inheritDoc}
129
	 */
130
	public function users_to_query()
131
	{
132
		return [$this->get_data('idea_author')];
133
	}
134
135
	/**
136
	 * {@inheritDoc}
137
	 */
138
	public function get_title()
139
	{
140
		if (!$this->language->is_set($this->language_key))
141
		{
142
			$this->language->add_lang('common', 'phpbb/ideas');
143
		}
144
		return $this->language->lang($this->language_key, $this->get_data('idea_title'));
145
	}
146
147
	/**
148
	 * {@inheritDoc}
149
	 */
150
	public function get_reference()
151
	{
152
		return  $this->language->lang(ext::status_name($this->get_data('status')));
153
	}
154
155
	/**
156
	 * {@inheritDoc}
157
	 */
158
	public function get_url($reference_type = UrlGeneratorInterface::ABSOLUTE_PATH)
159
	{
160
		$params = ['idea_id' => $this->get_data('idea_id')];
161
162
		return $this->helper->route('phpbb_ideas_idea_controller', $params, true, false, $reference_type);
163
	}
164
165
	/**
166
	 * {@inheritDoc}
167
	 */
168
	public function get_avatar()
169
	{
170
		return $this->user_loader->get_avatar($this->get_data('idea_author'), false, true);
171
	}
172
173
	/**
174
	 * {@inheritDoc}
175
	 */
176
	public function get_email_template()
177
	{
178
		return $this->email_template;
179
	}
180
181
	/**
182
	 * {@inheritDoc}
183
	 */
184
	public function get_email_template_variables()
185
	{
186
		return [
187
			'IDEA_TITLE'	=> html_entity_decode(censor_text($this->get_data('idea_title')), ENT_COMPAT),
0 ignored issues
show
Bug introduced by
The function censor_text was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

187
			'IDEA_TITLE'	=> html_entity_decode(/** @scrutinizer ignore-call */ censor_text($this->get_data('idea_title')), ENT_COMPAT),
Loading history...
188
			'STATUS'		=> html_entity_decode($this->language->lang(ext::status_name($this->get_data('status'))), ENT_COMPAT),
189
			'U_VIEW_IDEA'	=> $this->get_url(UrlGeneratorInterface::ABSOLUTE_URL),
190
		];
191
	}
192
193
	/**
194
	 * {@inheritDoc}
195
	 */
196
	public function create_insert_array($type_data, $pre_create_data = [])
197
	{
198
		$idea = $this->idea->get_idea($type_data['idea_id']);
199
200
		$this->set_data('idea_id', $type_data['idea_id']);
201
		$this->set_data('status', $type_data['status']);
202
		$this->set_data('idea_title', $idea['idea_title']);
203
		$this->set_data('idea_author', $idea['idea_author']);
204
205
		parent::create_insert_array($type_data, $pre_create_data);
206
	}
207
}
208