Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
5.88% covered (danger)
5.88%
2 / 34
18.18% covered (danger)
18.18%
2 / 11
CRAP
0.00% covered (danger)
0.00%
0 / 1
report_pm_closed
5.88% covered (danger)
5.88%
2 / 34
18.18% covered (danger)
18.18%
2 / 11
132.05
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
 is_available
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 find_users_for_notification
0.00% covered (danger)
0.00%
0 / 6
0.00% covered (danger)
0.00%
0 / 1
6
 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 / 8
0.00% covered (danger)
0.00%
0 / 1
2
 get_title
0.00% covered (danger)
0.00%
0 / 5
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_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 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 create_insert_array
0.00% covered (danger)
0.00%
0 / 3
0.00% covered (danger)
0.00%
0 / 1
2
 get_insert_array
0.00% covered (danger)
0.00%
0 / 3
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* PM report closed notifications class
18* This class handles notifications for when reports are closed on PMs (for the one who reported the PM)
19*/
20
21class report_pm_closed 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_closed';
31    }
32
33    /**
34    * Email template to use to send notifications
35    *
36    * @var string
37    */
38    public $email_template = 'report_pm_closed';
39
40    /**
41    * Language key used to output the text
42    *
43    * @var string
44    */
45    protected $language_key = 'NOTIFICATION_REPORT_PM_CLOSED';
46
47    /**
48    * Notification option data (for outputting to the user)
49    *
50    * @var bool|array False if the service should use it's default data
51    *                     Array of data (including keys 'id', 'lang', and 'group')
52    */
53    public static $notification_option = [
54        'id'    => 'notification.type.report_pm_closed',
55        'lang'    => 'NOTIFICATION_TYPE_REPORT_PM_CLOSED',
56        'group'    => 'NOTIFICATION_GROUP_MISCELLANEOUS',
57    ];
58
59    public function is_available()
60    {
61        return (bool) $this->config['allow_pm_report'];
62    }
63
64    /**
65    * Find the users who want to receive notifications
66    *
67    * @param array $type_data Data from submit_pm
68    * @param array $options Options for finding users for notification
69    *
70    * @return array
71    */
72    public function find_users_for_notification($type_data, $options = [])
73    {
74        $options = array_merge([
75            'ignore_users'        => [],
76        ], $options);
77
78        if ($type_data['reporter'] == $this->user->data['user_id'])
79        {
80            return [];
81        }
82
83        return $this->check_user_notification_options([$type_data['reporter']], $options);
84    }
85
86    /**
87    * {@inheritdoc}
88    */
89    public function get_email_template()
90    {
91        return $this->email_template;
92    }
93
94    /**
95    * Get email template variables
96    *
97    * @return array
98    */
99    public function get_email_template_variables()
100    {
101        $sender_username = $this->user_loader->get_username($this->get_data('from_user_id'), 'username');
102        $closer_username = $this->user_loader->get_username($this->get_data('closer_id'), 'username');
103
104        return [
105            'AUTHOR_NAME'    => html_entity_decode($sender_username, ENT_COMPAT),
106            'CLOSER_NAME'    => html_entity_decode($closer_username, ENT_COMPAT),
107            'SUBJECT'        => html_entity_decode(censor_text($this->get_data('message_subject')), ENT_COMPAT),
108
109            'U_VIEW_MESSAGE'=> generate_board_url() . "/ucp.{$this->php_ext}?i=pm&amp;mode=view&amp;p={$this->item_id}",
110        ];
111    }
112
113    /**
114    * Get the HTML formatted title of this notification
115    *
116    * @return string
117    */
118    public function get_title()
119    {
120        $username = $this->user_loader->get_username($this->get_data('closer_id'), 'no_profile');
121
122        return $this->language->lang(
123            $this->language_key,
124            $username
125        );
126    }
127
128    /**
129    * Get the HTML formatted reference of the notification
130    *
131    * @return string
132    */
133    public function get_reference()
134    {
135        return $this->language->lang(
136            'NOTIFICATION_REFERENCE',
137            censor_text($this->get_data('message_subject'))
138        );
139    }
140
141    /**
142    * Get the user's avatar
143    */
144    public function get_avatar()
145    {
146        return $this->user_loader->get_avatar($this->get_data('closer_id'), false, true);
147    }
148
149    /**
150    * Users needed to query before this notification can be displayed
151    *
152    * @return array Array of user_ids
153    */
154    public function users_to_query()
155    {
156        return [$this->get_data('closer_id')];
157    }
158
159    /**
160    * {@inheritdoc}
161    */
162    public function create_insert_array($type_data, $pre_create_data = [])
163    {
164        $this->set_data('closer_id', $type_data['closer_id']);
165
166        parent::create_insert_array($type_data, $pre_create_data);
167
168        $this->notification_time = time();
169    }
170
171    /**
172    * {@inheritdoc}
173    */
174    public function get_insert_array()
175    {
176        $data = parent::get_insert_array();
177        $data['notification_time'] = $this->notification_time;
178
179        return $data;
180    }
181}