Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
5.41% covered (danger)
5.41%
2 / 37
15.38% covered (danger)
15.38%
2 / 13
CRAP
0.00% covered (danger)
0.00%
0 / 1
report_post_closed
5.41% covered (danger)
5.41%
2 / 37
15.38% covered (danger)
15.38%
2 / 13
205.45
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 / 9
0.00% covered (danger)
0.00%
0 / 1
6
 get_url
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 get_redirect_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 / 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* Post report closed notifications class
18* This class handles notifications for when reports are closed on posts (for the one who reported the post)
19*/
20
21class report_post_closed extends \phpbb\notification\type\post
22{
23    /**
24    * Get notification type name
25    *
26    * @return string
27    */
28    public function get_type()
29    {
30        return 'notification.type.report_post_closed';
31    }
32
33    /**
34    * Email template to use to send notifications
35    *
36    * @var string
37    */
38    public $email_template = 'report_closed';
39
40    /**
41    * Language key used to output the text
42    *
43    * @var string
44    */
45    protected $language_key = 'NOTIFICATION_REPORT_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_post_closed',
55        'lang'    => 'NOTIFICATION_TYPE_REPORT_CLOSED',
56        'group'    => 'NOTIFICATION_GROUP_MISCELLANEOUS',
57    ];
58
59    /**
60    * Inherit notification read status from post.
61    *
62    * @var bool
63    */
64    protected $inherit_read_status = false;
65
66    public function is_available()
67    {
68        return $this->auth->acl_getf_global('f_report');
69    }
70
71    /**
72    * Find the users who want to receive notifications
73    *
74    * @param array $type_data Data from submit_post
75    * @param array $options Options for finding users for notification
76    *
77    * @return array
78    */
79    public function find_users_for_notification($type_data, $options = [])
80    {
81        $options = array_merge([
82            'ignore_users'        => [],
83        ], $options);
84
85        if ($type_data['reporter'] == $this->user->data['user_id'])
86        {
87            return [];
88        }
89
90        return $this->check_user_notification_options([$type_data['reporter']], $options);
91    }
92
93    /**
94    * {@inheritdoc}
95    */
96    public function get_email_template()
97    {
98        return $this->email_template;
99    }
100
101    /**
102    * Get email template variables
103    *
104    * @return array
105    */
106    public function get_email_template_variables()
107    {
108        $post_username = $this->get_data('post_username') ?: $this->user_loader->get_username($this->get_data('poster_id'), 'username');
109        $closer_username = $this->user_loader->get_username($this->get_data('closer_id'), 'username');
110
111        return [
112            'AUTHOR_NAME'    => html_entity_decode($post_username, ENT_COMPAT),
113            'CLOSER_NAME'    => html_entity_decode($closer_username, ENT_COMPAT),
114            'POST_SUBJECT'    => html_entity_decode(censor_text($this->get_data('post_subject')), ENT_COMPAT),
115            'TOPIC_TITLE'    => html_entity_decode(censor_text($this->get_data('topic_title')), ENT_COMPAT),
116
117            'U_VIEW_POST'    => generate_board_url() . "/viewtopic.{$this->php_ext}?p={$this->item_id}#p{$this->item_id}",
118        ];
119    }
120
121    /**
122    * Get the url to this item
123    *
124    * @return string URL
125    */
126    public function get_url()
127    {
128        return append_sid($this->phpbb_root_path . 'viewtopic.' . $this->php_ext, "p={$this->item_id}#p{$this->item_id}");
129    }
130
131    /**
132    * {inheritDoc}
133    */
134    public function get_redirect_url()
135    {
136        return $this->get_url();
137    }
138
139    /**
140    * Get the HTML formatted title of this notification
141    *
142    * @return string
143    */
144    public function get_title()
145    {
146        $username = $this->user_loader->get_username($this->get_data('closer_id'), 'no_profile');
147
148        return $this->language->lang(
149            $this->language_key,
150            $username
151        );
152    }
153
154    /**
155    * Get the HTML formatted reference of the notification
156    *
157    * @return string
158    */
159    public function get_reference()
160    {
161        return $this->language->lang(
162            'NOTIFICATION_REFERENCE',
163            censor_text($this->get_data('post_subject'))
164        );
165    }
166
167    /**
168    * Get the user's avatar
169    */
170    public function get_avatar()
171    {
172        return $this->user_loader->get_avatar($this->get_data('closer_id'), false, true);
173    }
174
175    /**
176    * Users needed to query before this notification can be displayed
177    *
178    * @return array Array of user_ids
179    */
180    public function users_to_query()
181    {
182        return [$this->get_data('closer_id')];
183    }
184
185    /**
186    * {@inheritdoc}
187    */
188    public function create_insert_array($type_data, $pre_create_data = [])
189    {
190        $this->set_data('closer_id', $type_data['closer_id']);
191
192        parent::create_insert_array($type_data, $pre_create_data);
193
194        $this->notification_time = time();
195    }
196
197    /**
198    * {@inheritdoc}
199    */
200    public function get_insert_array()
201    {
202        $data = parent::get_insert_array();
203        $data['notification_time'] = $this->notification_time;
204
205        return $data;
206    }
207}