Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
32.14% covered (danger)
32.14%
9 / 28
28.57% covered (danger)
28.57%
2 / 7
CRAP
0.00% covered (danger)
0.00%
0 / 1
topic_in_queue
32.14% covered (danger)
32.14%
9 / 28
28.57% covered (danger)
28.57%
2 / 7
48.81
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%
2 / 2
100.00% covered (success)
100.00%
1 / 1
1
 find_users_for_notification
33.33% covered (danger)
33.33%
6 / 18
0.00% covered (danger)
0.00%
0 / 1
12.41
 get_url
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 / 2
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
 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* Topic in queue notifications class
18* This class handles notifications for topics when they are put in the moderation queue (for moderators)
19*/
20
21class topic_in_queue extends \phpbb\notification\type\topic
22{
23    /**
24    * Get notification type name
25    *
26    * @return string
27    */
28    public function get_type()
29    {
30        return 'notification.type.topic_in_queue';
31    }
32
33    /**
34    * Language key used to output the text
35    *
36    * @var string
37    */
38    protected $language_key = 'NOTIFICATION_TOPIC_IN_QUEUE';
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        'id'    => 'notification.type.needs_approval',
48        'lang'    => 'NOTIFICATION_TYPE_IN_MODERATION_QUEUE',
49        'group'    => 'NOTIFICATION_GROUP_MODERATION',
50    );
51
52    /**
53    * Permission to check for (in find_users_for_notification)
54    *
55    * @var string Permission name
56    */
57    protected $permission = 'm_approve';
58
59    /**
60    * Is available
61    */
62    public function is_available()
63    {
64        $has_permission = $this->auth->acl_getf($this->permission, true);
65
66        return (!empty($has_permission));
67    }
68
69    /**
70    * Find the users who want to receive notifications
71    *
72    * @param array $type_data Data from the topic
73    * @param array $options Options for finding users for notification
74    *
75    * @return array
76    */
77    public function find_users_for_notification($type_data, $options = array())
78    {
79        $options = array_merge(array(
80            'ignore_users'        => array(),
81        ), $options);
82
83        // 0 is for global moderator permissions
84        $auth_approve = $this->auth->acl_get_list(false, 'm_approve', array($type_data['forum_id'], 0));
85
86        if (empty($auth_approve))
87        {
88            return array();
89        }
90
91        $has_permission = array();
92
93        if (isset($auth_approve[$type_data['forum_id']][$this->permission]))
94        {
95            $has_permission = $auth_approve[$type_data['forum_id']][$this->permission];
96        }
97
98        if (isset($auth_approve[0][$this->permission]))
99        {
100            $has_permission = array_unique(array_merge($has_permission, $auth_approve[0][$this->permission]));
101        }
102        sort($has_permission);
103
104        $auth_read = $this->auth->acl_get_list($has_permission, 'f_read', $type_data['forum_id']);
105        if (empty($auth_read))
106        {
107            return array();
108        }
109
110        return $this->check_user_notification_options($auth_read[$type_data['forum_id']]['f_read'], array_merge($options, array(
111            'item_type'        => static::$notification_option['id'],
112        )));
113    }
114
115    /**
116    * Get the url to this item
117    *
118    * @return string URL
119    */
120    public function get_url()
121    {
122        return append_sid($this->phpbb_root_path . 'mcp.' . $this->php_ext, "i=queue&amp;mode=approve_details&amp;t={$this->item_id}");
123    }
124
125    /**
126    * {@inheritdoc}
127    */
128    public function create_insert_array($type_data, $pre_create_data = array())
129    {
130        parent::create_insert_array($type_data, $pre_create_data);
131
132        $this->notification_time = time();
133    }
134
135    /**
136    * {@inheritdoc}
137    */
138    public function get_insert_array()
139    {
140        $data = parent::get_insert_array();
141        $data['notification_time'] = $this->notification_time;
142
143        return $data;
144    }
145
146    /**
147    * {@inheritdoc}
148    */
149    public function get_email_template()
150    {
151        return 'topic_in_queue';
152    }
153}