Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
12.12% covered (danger)
12.12%
4 / 33
26.67% covered (danger)
26.67%
4 / 15
CRAP
0.00% covered (danger)
0.00%
0 / 1
pm
12.12% covered (danger)
12.12%
4 / 33
26.67% covered (danger)
26.67%
4 / 15
213.13
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
 set_config
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 set_user_loader
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
2
 get_item_id
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
 find_users_for_notification
0.00% covered (danger)
0.00%
0 / 8
0.00% covered (danger)
0.00%
0 / 1
6
 get_avatar
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 / 2
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_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 / 6
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
 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
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 notifications class
18* This class handles notifications for private messages
19*/
20
21class pm extends \phpbb\notification\type\base
22{
23    /**
24    * Get notification type name
25    *
26    * @return string
27    */
28    public function get_type()
29    {
30        return 'notification.type.pm';
31    }
32
33    /**
34    * Notification option data (for outputting to the user)
35    *
36    * @var bool|array False if the service should use it's default data
37    *                     Array of data (including keys 'id', 'lang', and 'group')
38    */
39    public static $notification_option = array(
40        'lang'    => 'NOTIFICATION_TYPE_PM',
41    );
42
43    /** @var \phpbb\user_loader */
44    protected $user_loader;
45
46    /** @var \phpbb\config\config */
47    protected $config;
48
49    public function set_config(\phpbb\config\config $config)
50    {
51        $this->config = $config;
52    }
53
54    public function set_user_loader(\phpbb\user_loader $user_loader)
55    {
56        $this->user_loader = $user_loader;
57    }
58
59    /**
60    * Is available
61    */
62    public function is_available()
63    {
64        return ($this->config['allow_privmsg'] && $this->auth->acl_get('u_readpm'));
65    }
66
67    /**
68    * Get the id of the
69    *
70    * @param array $type_data The data from the private message
71    */
72    public static function get_item_id($type_data)
73    {
74        return (int) $type_data['msg_id'];
75    }
76
77    /**
78    * Get the id of the parent
79    *
80    * @param array $type_data The data from the pm
81    */
82    public static function get_item_parent_id($type_data)
83    {
84        // No parent
85        return 0;
86    }
87
88    /**
89    * Find the users who want to receive notifications
90    *
91    * @param array $type_data Data from submit_pm
92    * @param array $options Options for finding users for notification
93    *
94    * @return array
95    */
96    public function find_users_for_notification($type_data, $options = array())
97    {
98        $options = array_merge(array(
99            'ignore_users'        => array(),
100        ), $options);
101
102        if (!count($type_data['recipients']))
103        {
104            return array();
105        }
106
107        unset($type_data['recipients'][$type_data['from_user_id']]);
108
109        $this->user_loader->load_users(array_keys($type_data['recipients']));
110
111        return $this->check_user_notification_options(array_keys($type_data['recipients']), $options);
112    }
113
114    /**
115    * Get the user's avatar
116    */
117    public function get_avatar()
118    {
119        return $this->user_loader->get_avatar($this->get_data('from_user_id'), false, true);
120    }
121
122    /**
123    * Get the HTML formatted title of this notification
124    *
125    * @return string
126    */
127    public function get_title()
128    {
129        $username = $this->user_loader->get_username($this->get_data('from_user_id'), 'no_profile');
130
131        return $this->language->lang('NOTIFICATION_PM', $username);
132    }
133
134    /**
135    * Get the HTML formatted reference of the notification
136    *
137    * @return string
138    */
139    public function get_reference()
140    {
141        return $this->language->lang(
142            'NOTIFICATION_REFERENCE',
143            $this->get_data('message_subject')
144        );
145    }
146
147    /**
148    * {@inheritdoc}
149    */
150    public function get_email_template()
151    {
152        return 'privmsg_notify';
153    }
154
155    /**
156    * Get email template variables
157    *
158    * @return array
159    */
160    public function get_email_template_variables()
161    {
162        $user_data = $this->user_loader->get_user($this->get_data('from_user_id'));
163
164        return array(
165            'AUTHOR_NAME'                => html_entity_decode($user_data['username'], ENT_COMPAT),
166            'SUBJECT'                    => html_entity_decode(censor_text($this->get_data('message_subject')), ENT_COMPAT),
167
168            'U_VIEW_MESSAGE'            => generate_board_url() . '/ucp.' . $this->php_ext . "?i=pm&mode=view&p={$this->item_id}",
169        );
170    }
171
172    /**
173    * Get the url to this item
174    *
175    * @return string URL
176    */
177    public function get_url()
178    {
179        return append_sid($this->phpbb_root_path . 'ucp.' . $this->php_ext, "i=pm&amp;mode=view&amp;p={$this->item_id}");
180    }
181
182    /**
183    * Users needed to query before this notification can be displayed
184    *
185    * @return array Array of user_ids
186    */
187    public function users_to_query()
188    {
189        return array($this->get_data('from_user_id'));
190    }
191
192    /**
193    * {@inheritdoc}
194    */
195    public function create_insert_array($type_data, $pre_create_data = array())
196    {
197        $this->set_data('from_user_id', $type_data['from_user_id']);
198
199        $this->set_data('message_subject', $type_data['message_subject']);
200
201        parent::create_insert_array($type_data, $pre_create_data);
202    }
203}