Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
96.97% covered (success)
96.97%
32 / 33
75.00% covered (warning)
75.00%
3 / 4
CRAP
0.00% covered (danger)
0.00%
0 / 1
bookmark
96.97% covered (success)
96.97%
32 / 33
75.00% covered (warning)
75.00%
3 / 4
8
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
100.00% covered (success)
100.00%
30 / 30
100.00% covered (success)
100.00%
1 / 1
5
 get_email_template
0.00% covered (danger)
0.00%
0 / 1
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* Bookmark updating notifications class
18* This class handles notifications for replies to a bookmarked topic
19*/
20
21class bookmark 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.bookmark';
31    }
32
33    /**
34    * Language key used to output the text
35    *
36    * @var string
37    */
38    protected $language_key = 'NOTIFICATION_BOOKMARK';
39
40    /**
41    * Notification option data (for outputting to the user)
42    *
43    * @var bool|array False if the service should use it's default data
44    *                     Array of data (including keys 'id', 'lang', and 'group')
45    */
46    public static $notification_option = array(
47        'lang'    => 'NOTIFICATION_TYPE_BOOKMARK',
48        'group'    => 'NOTIFICATION_GROUP_POSTING',
49    );
50
51    /**
52    * Is available
53    */
54    public function is_available()
55    {
56        return (bool) $this->config['allow_bookmarks'];
57    }
58
59    /**
60     * Find the users who want to receive notifications
61     *
62     * @param array $type_data Data from submit_post
63     * @param array $options Options for finding users for notification
64     *
65     * @return array
66     * @throws \Exception
67     */
68    public function find_users_for_notification($type_data, $options = array())
69    {
70        $options = array_merge(array(
71            'ignore_users'        => array(),
72        ), $options);
73
74        $users = array();
75
76        $sql = 'SELECT user_id
77            FROM ' . BOOKMARKS_TABLE . '
78            WHERE ' . $this->db->sql_in_set('topic_id', $type_data['topic_id']) . '
79                AND user_id <> ' . (int) $type_data['poster_id'];
80        $result = $this->db->sql_query($sql);
81        while ($row = $this->db->sql_fetchrow($result))
82        {
83            $users[] = (int) $row['user_id'];
84        }
85        $this->db->sql_freeresult($result);
86
87        $notify_users = $this->get_authorised_recipients($users, $type_data['forum_id'], $options, true);
88
89        if (empty($notify_users))
90        {
91            return array();
92        }
93
94        // Try to find the users who already have been notified about replies and have not read the topic since and just update their notifications
95        $notified_users = $this->notification_manager->get_notified_users($this->get_type(), array(
96            'item_parent_id'    => static::get_item_parent_id($type_data),
97            'read'                => 0,
98        ));
99
100        foreach ($notified_users as $user => $notification_data)
101        {
102            unset($notify_users[$user]);
103
104            /** @var bookmark $notification */
105            $notification = $this->notification_manager->get_item_type_class($this->get_type(), $notification_data);
106            $update_responders = $notification->add_responders($type_data);
107            if (!empty($update_responders))
108            {
109                $this->notification_manager->update_notification($notification, $update_responders, array(
110                    'item_parent_id'    => self::get_item_parent_id($type_data),
111                    'read'                => 0,
112                    'user_id'            => $user,
113                ));
114            }
115        }
116
117        return $notify_users;
118    }
119
120    /**
121    * {@inheritdoc}
122    */
123    public function get_email_template()
124    {
125        return 'bookmark';
126    }
127}