Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
66.67% |
32 / 48 |
|
50.00% |
2 / 4 |
CRAP | |
0.00% |
0 / 1 |
forum | |
66.67% |
32 / 48 |
|
50.00% |
2 / 4 |
12.00 | |
0.00% |
0 / 1 |
get_type | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
find_users_for_notification | |
100.00% |
31 / 31 |
|
100.00% |
1 / 1 |
5 | |||
get_email_template | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
get_email_template_variables | |
0.00% |
0 / 15 |
|
0.00% |
0 / 1 |
6 |
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 | |
14 | namespace phpbb\notification\type; |
15 | |
16 | /** |
17 | * Forum notifications class |
18 | * This class handles notifications for replies to a topic in a forum user subscribed to |
19 | */ |
20 | |
21 | class forum 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.forum'; |
31 | } |
32 | |
33 | /** |
34 | * Notification option data (for outputting to the user) |
35 | * |
36 | * @var bool|array False if the service should use its default data |
37 | * Array of data (including keys 'id', 'lang', and 'group') |
38 | */ |
39 | public static $notification_option = [ |
40 | 'lang' => 'NOTIFICATION_TYPE_FORUM', |
41 | 'group' => 'NOTIFICATION_GROUP_POSTING', |
42 | ]; |
43 | |
44 | /** |
45 | * Find the users who want to receive notifications |
46 | * |
47 | * @param array $type_data Data from submit_post |
48 | * @param array $options Options for finding users for notification |
49 | * |
50 | * @return array |
51 | */ |
52 | public function find_users_for_notification($type_data, $options = []) |
53 | { |
54 | $options = array_merge([ |
55 | 'ignore_users' => [], |
56 | ], $options); |
57 | |
58 | $users = []; |
59 | |
60 | $sql = 'SELECT user_id |
61 | FROM ' . FORUMS_WATCH_TABLE . ' |
62 | WHERE forum_id = ' . (int) $type_data['forum_id'] . ' |
63 | AND notify_status = ' . NOTIFY_YES . ' |
64 | AND user_id <> ' . (int) $type_data['poster_id']; |
65 | $result = $this->db->sql_query($sql); |
66 | while ($row = $this->db->sql_fetchrow($result)) |
67 | { |
68 | $users[] = (int) $row['user_id']; |
69 | } |
70 | $this->db->sql_freeresult($result); |
71 | |
72 | $notify_users = $this->get_authorised_recipients($users, $type_data['forum_id'], $options, true); |
73 | |
74 | if (empty($notify_users)) |
75 | { |
76 | return []; |
77 | } |
78 | |
79 | // Try to find the users who already have been notified about replies and have not read them |
80 | // Just update their notifications |
81 | $notified_users = $this->notification_manager->get_notified_users($this->get_type(), [ |
82 | 'item_parent_id' => static::get_item_parent_id($type_data), |
83 | 'read' => 0, |
84 | ]); |
85 | |
86 | foreach ($notified_users as $user => $notification_data) |
87 | { |
88 | unset($notify_users[$user]); |
89 | |
90 | /** @var post $notification */ |
91 | $notification = $this->notification_manager->get_item_type_class($this->get_type(), $notification_data); |
92 | $update_responders = $notification->add_responders($type_data); |
93 | if (!empty($update_responders)) |
94 | { |
95 | $this->notification_manager->update_notification($notification, $update_responders, [ |
96 | 'item_parent_id' => self::get_item_parent_id($type_data), |
97 | 'read' => 0, |
98 | 'user_id' => $user, |
99 | ]); |
100 | } |
101 | } |
102 | |
103 | return $notify_users; |
104 | } |
105 | |
106 | /** |
107 | * {@inheritdoc} |
108 | */ |
109 | public function get_email_template() |
110 | { |
111 | return 'forum_notify'; |
112 | } |
113 | |
114 | /** |
115 | * Get email template variables |
116 | * |
117 | * @return array |
118 | */ |
119 | public function get_email_template_variables() |
120 | { |
121 | if ($this->get_data('post_username')) |
122 | { |
123 | $username = $this->get_data('post_username'); |
124 | } |
125 | else |
126 | { |
127 | $username = $this->user_loader->get_username($this->get_data('poster_id'), 'username'); |
128 | } |
129 | |
130 | return [ |
131 | 'AUTHOR_NAME' => html_entity_decode($username, ENT_COMPAT), |
132 | 'FORUM_NAME' => html_entity_decode(censor_text($this->get_data('forum_name')), ENT_COMPAT), |
133 | 'POST_SUBJECT' => html_entity_decode(censor_text($this->get_data('post_subject')), ENT_COMPAT), |
134 | 'TOPIC_TITLE' => html_entity_decode(censor_text($this->get_data('topic_title')), ENT_COMPAT), |
135 | |
136 | 'U_VIEW_POST' => generate_board_url() . "/viewtopic.{$this->php_ext}?p={$this->item_id}#p{$this->item_id}", |
137 | 'U_NEWEST_POST' => generate_board_url() . "/viewtopic.{$this->php_ext}?t={$this->item_parent_id}&e=1&view=unread#unread", |
138 | 'U_TOPIC' => generate_board_url() . "/viewtopic.{$this->php_ext}?t={$this->item_parent_id}", |
139 | 'U_VIEW_TOPIC' => generate_board_url() . "/viewtopic.{$this->php_ext}?t={$this->item_parent_id}", |
140 | 'U_FORUM' => generate_board_url() . "/viewforum.{$this->php_ext}?f={$this->get_data('forum_id')}", |
141 | 'U_STOP_WATCHING_FORUM' => generate_board_url() . "/viewforum.{$this->php_ext}?uid={$this->user_id}&f={$this->get_data('forum_id')}&unwatch=forum", |
142 | ]; |
143 | } |
144 | } |