Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
5.00% covered (danger)
5.00%
3 / 60
14.29% covered (danger)
14.29%
2 / 14
CRAP
0.00% covered (danger)
0.00%
0 / 1
report_pm
5.00% covered (danger)
5.00%
3 / 60
14.29% covered (danger)
14.29%
2 / 14
328.51
0.00% covered (danger)
0.00%
0 / 1
 get_type
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 get_style_class
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 get_item_parent_id
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 is_available
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
1 / 1
2
 find_users_for_notification
0.00% covered (danger)
0.00%
0 / 12
0.00% covered (danger)
0.00%
0 / 1
12
 get_email_template
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 get_email_template_variables
0.00% covered (danger)
0.00%
0 / 7
0.00% covered (danger)
0.00%
0 / 1
2
 get_url
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 get_title
0.00% covered (danger)
0.00%
0 / 6
0.00% covered (danger)
0.00%
0 / 1
2
 get_reference
0.00% covered (danger)
0.00%
0 / 4
0.00% covered (danger)
0.00%
0 / 1
2
 get_reason
0.00% covered (danger)
0.00%
0 / 14
0.00% covered (danger)
0.00%
0 / 1
12
 get_avatar
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 users_to_query
0.00% covered (danger)
0.00%
0 / 4
0.00% covered (danger)
0.00%
0 / 1
2
 create_insert_array
0.00% covered (danger)
0.00%
0 / 5
0.00% covered (danger)
0.00%
0 / 1
2
1<?php
2/**
3*
4* This file is part of 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* For full copyright and license information, please see
10* the docs/CREDITS.txt file.
11*
12*/
13
14namespace phpbb\notification\type;
15
16/**
17* Private message reported notifications class
18* This class handles notifications for private messages when they are reported
19*/
20
21class report_pm extends \phpbb\notification\type\pm
22{
23    /**
24    * Get notification type name
25    *
26    * @return string
27    */
28    public function get_type()
29    {
30        return 'notification.type.report_pm';
31    }
32
33    /**
34    * Get the CSS style class of the notification
35    *
36    * @return string
37    */
38    public function get_style_class()
39    {
40        return 'notification-reported';
41    }
42
43    /**
44    * Language key used to output the text
45    *
46    * @var string
47    */
48    protected $language_key = 'NOTIFICATION_REPORT_PM';
49
50    /**
51    * Permission to check for (in find_users_for_notification)
52    *
53    * @var string Permission name
54    */
55    protected $permission = 'm_pm_report';
56
57    /**
58    * Notification option data (for outputting to the user)
59    *
60    * @var bool|array False if the service should use it's default data
61    *                     Array of data (including keys 'id', 'lang', and 'group')
62    */
63    public static $notification_option = [
64        'id'    => 'notification.type.report_pm',
65        'lang'    => 'NOTIFICATION_TYPE_REPORT_PM',
66        'group'    => 'NOTIFICATION_GROUP_MODERATION',
67    ];
68
69    /**
70    * Get the id of the parent
71    *
72    * @param array $type_data The data from the pm
73    *
74    * @return int The report id
75    */
76    public static function get_item_parent_id($type_data)
77    {
78        return (int) $type_data['report_id'];
79    }
80
81    /**
82    * Is this type available to the current user (defines whether or not it will be shown in the UCP Edit notification options)
83    *
84    * @return bool True/False whether or not this is available to the user
85    */
86    public function is_available()
87    {
88        return $this->config['allow_pm_report'] &&
89            !empty($this->auth->acl_get($this->permission));
90    }
91
92    /**
93    * Find the users who want to receive notifications
94    *  (copied from post_in_queue)
95    *
96    * @param array $type_data Data from the post
97    * @param array $options Options for finding users for notification
98    *
99    * @return array
100    */
101    public function find_users_for_notification($type_data, $options = [])
102    {
103        $options = array_merge([
104            'ignore_users'        => [],
105        ], $options);
106
107        // Global
108        $type_data['forum_id'] = 0;
109
110        $auth_approve = $this->auth->acl_get_list(false, $this->permission, $type_data['forum_id']);
111
112        if (empty($auth_approve))
113        {
114            return [];
115        }
116
117        if (($key = array_search($this->user->data['user_id'], $auth_approve[$type_data['forum_id']][$this->permission])))
118        {
119            unset($auth_approve[$type_data['forum_id']][$this->permission][$key]);
120        }
121
122        return $this->check_user_notification_options($auth_approve[$type_data['forum_id']][$this->permission], array_merge($options, [
123            'item_type'        => static::$notification_option['id'],
124        ]));
125    }
126
127    /**
128    * {@inheritdoc}
129    */
130    public function get_email_template()
131    {
132        return 'report_pm';
133    }
134
135    /**
136    * Get email template variables
137    *
138    * @return array
139    */
140    public function get_email_template_variables()
141    {
142        $user_data = $this->user_loader->get_user($this->get_data('from_user_id'));
143
144        return [
145            'AUTHOR_NAME'    => html_entity_decode($user_data['username'], ENT_COMPAT),
146            'SUBJECT'        => html_entity_decode(censor_text($this->get_data('message_subject')), ENT_COMPAT),
147
148            /** @deprecated    3.2.6-RC1    (to be removed in 4.0.0) use {SUBJECT} instead in report_pm.txt */
149            'TOPIC_TITLE'    => html_entity_decode(censor_text($this->get_data('message_subject')), ENT_COMPAT),
150
151            'U_VIEW_REPORT'    => generate_board_url() . "/mcp.{$this->php_ext}?r={$this->item_parent_id}&i=pm_reports&mode=pm_report_details",
152        ];
153    }
154
155    /**
156    * Get the url to this item
157    *
158    * @return string URL
159    */
160    public function get_url()
161    {
162        return append_sid($this->phpbb_root_path . 'mcp.' . $this->php_ext, "r={$this->item_parent_id}&amp;i=pm_reports&amp;mode=pm_report_details");
163    }
164
165    /**
166    * Get the HTML formatted title of this notification
167    *
168    * @return string
169    */
170    public function get_title()
171    {
172        $this->language->add_lang('mcp');
173
174        $username = $this->user_loader->get_username($this->get_data('reporter_id'), 'no_profile');
175
176        return $this->language->lang(
177            $this->language_key,
178            $username
179        );
180    }
181
182    /**
183    * Get the HTML formatted reference of the notification
184    *
185    * @return string
186    */
187    public function get_reference()
188    {
189        return $this->language->lang(
190            'NOTIFICATION_REFERENCE',
191            censor_text($this->get_data('message_subject'))
192        );
193    }
194
195    /**
196    * Get the reason for the notification
197    *
198    * @return string
199    */
200    public function get_reason()
201    {
202        if ($this->get_data('report_text'))
203        {
204            return $this->language->lang(
205                'NOTIFICATION_REASON',
206                $this->get_data('report_text')
207            );
208        }
209
210        if ($this->language->is_set($this->get_data('reason_title')))
211        {
212            return $this->language->lang(
213                'NOTIFICATION_REASON',
214                $this->language->lang($this->get_data('reason_title'))
215            );
216        }
217
218        return $this->language->lang(
219            'NOTIFICATION_REASON',
220            $this->get_data('reason_description')
221        );
222    }
223
224    /**
225    * Get the user's avatar
226    */
227    public function get_avatar()
228    {
229        return $this->user_loader->get_avatar($this->get_data('reporter_id'), false, true);
230    }
231
232    /**
233    * Users needed to query before this notification can be displayed
234    *
235    * @return array Array of user_ids
236    */
237    public function users_to_query()
238    {
239        return [
240            $this->get_data('from_user_id'),
241            $this->get_data('reporter_id'),
242        ];
243    }
244
245    /**
246    * {@inheritdoc}
247    */
248    public function create_insert_array($type_data, $pre_create_data = [])
249    {
250        $this->set_data('reporter_id', $this->user->data['user_id']);
251        $this->set_data('reason_title', strtoupper($type_data['reason_title']));
252        $this->set_data('reason_description', $type_data['reason_description']);
253        $this->set_data('report_text', $type_data['report_text']);
254
255        parent::create_insert_array($type_data, $pre_create_data);
256    }
257}