Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
50.00% |
20 / 40 |
|
53.85% |
7 / 13 |
CRAP | |
0.00% |
0 / 1 |
group_request | |
50.00% |
20 / 40 |
|
53.85% |
7 / 13 |
43.12 | |
0.00% |
0 / 1 |
get_type | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
set_user_loader | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
is_available | |
0.00% |
0 / 8 |
|
0.00% |
0 / 1 |
6 | |||
get_item_id | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
get_item_parent_id | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
find_users_for_notification | |
100.00% |
13 / 13 |
|
100.00% |
1 / 1 |
2 | |||
get_avatar | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
get_title | |
0.00% |
0 / 2 |
|
0.00% |
0 / 1 |
2 | |||
get_email_template | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
get_email_template_variables | |
0.00% |
0 / 7 |
|
0.00% |
0 / 1 |
2 | |||
get_url | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
users_to_query | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
create_insert_array | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
1 |
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 | class group_request extends \phpbb\notification\type\base |
17 | { |
18 | /** |
19 | * {@inheritdoc} |
20 | */ |
21 | public function get_type() |
22 | { |
23 | return 'notification.type.group_request'; |
24 | } |
25 | |
26 | /** |
27 | * {@inheritdoc} |
28 | */ |
29 | public static $notification_option = array( |
30 | 'lang' => 'NOTIFICATION_TYPE_GROUP_REQUEST', |
31 | ); |
32 | |
33 | /** @var \phpbb\user_loader */ |
34 | protected $user_loader; |
35 | |
36 | public function set_user_loader(\phpbb\user_loader $user_loader) |
37 | { |
38 | $this->user_loader = $user_loader; |
39 | } |
40 | |
41 | /** |
42 | * {@inheritdoc} |
43 | */ |
44 | public function is_available() |
45 | { |
46 | // Leader of any groups? |
47 | $sql = 'SELECT group_id |
48 | FROM ' . USER_GROUP_TABLE . ' |
49 | WHERE user_id = ' . (int) $this->user->data['user_id'] . ' |
50 | AND group_leader = 1'; |
51 | $result = $this->db->sql_query_limit($sql, 1); |
52 | $row = $this->db->sql_fetchrow($result); |
53 | $this->db->sql_freeresult($result); |
54 | |
55 | return (!empty($row)) ? true : false; |
56 | } |
57 | |
58 | /** |
59 | * {@inheritdoc} |
60 | */ |
61 | public static function get_item_id($type_data) |
62 | { |
63 | return (int) $type_data['user_id']; |
64 | } |
65 | |
66 | /** |
67 | * {@inheritdoc} |
68 | */ |
69 | public static function get_item_parent_id($type_data) |
70 | { |
71 | // Group id is the parent |
72 | return (int) $type_data['group_id']; |
73 | } |
74 | |
75 | /** |
76 | * {@inheritdoc} |
77 | */ |
78 | public function find_users_for_notification($type_data, $options = array()) |
79 | { |
80 | $options = array_merge(array( |
81 | 'ignore_users' => array(), |
82 | ), $options); |
83 | |
84 | $sql = 'SELECT user_id |
85 | FROM ' . USER_GROUP_TABLE . ' |
86 | WHERE group_leader = 1 |
87 | AND group_id = ' . (int) $type_data['group_id']; |
88 | $result = $this->db->sql_query($sql); |
89 | |
90 | $user_ids = array(); |
91 | while ($row = $this->db->sql_fetchrow($result)) |
92 | { |
93 | $user_ids[] = (int) $row['user_id']; |
94 | } |
95 | $this->db->sql_freeresult($result); |
96 | |
97 | $this->user_loader->load_users($user_ids); |
98 | |
99 | return $this->check_user_notification_options($user_ids, $options); |
100 | } |
101 | |
102 | /** |
103 | * {@inheritdoc} |
104 | */ |
105 | public function get_avatar() |
106 | { |
107 | return $this->user_loader->get_avatar($this->item_id, false, true); |
108 | } |
109 | |
110 | /** |
111 | * {@inheritdoc} |
112 | */ |
113 | public function get_title() |
114 | { |
115 | $username = $this->user_loader->get_username($this->item_id, 'no_profile'); |
116 | |
117 | return $this->language->lang('NOTIFICATION_GROUP_REQUEST', $username, $this->get_data('group_name')); |
118 | } |
119 | |
120 | /** |
121 | * {@inheritdoc} |
122 | */ |
123 | public function get_email_template() |
124 | { |
125 | return 'group_request'; |
126 | } |
127 | |
128 | /** |
129 | * {@inheritdoc} |
130 | */ |
131 | public function get_email_template_variables() |
132 | { |
133 | $user_data = $this->user_loader->get_user($this->item_id); |
134 | |
135 | return array( |
136 | 'GROUP_NAME' => html_entity_decode($this->get_data('group_name'), ENT_COMPAT), |
137 | 'REQUEST_USERNAME' => html_entity_decode($user_data['username'], ENT_COMPAT), |
138 | |
139 | 'U_PENDING' => generate_board_url() . "/ucp.{$this->php_ext}?i=groups&mode=manage&action=list&g={$this->item_parent_id}", |
140 | 'U_GROUP' => generate_board_url() . "/memberlist.{$this->php_ext}?mode=group&g={$this->item_parent_id}", |
141 | ); |
142 | } |
143 | |
144 | /** |
145 | * {@inheritdoc} |
146 | */ |
147 | public function get_url() |
148 | { |
149 | return append_sid($this->phpbb_root_path . 'ucp.' . $this->php_ext, "i=groups&mode=manage&action=list&g={$this->item_parent_id}"); |
150 | } |
151 | |
152 | /** |
153 | * {@inheritdoc} |
154 | */ |
155 | public function users_to_query() |
156 | { |
157 | return array($this->item_id); |
158 | } |
159 | |
160 | /** |
161 | * {@inheritdoc} |
162 | */ |
163 | public function create_insert_array($type_data, $pre_create_data = array()) |
164 | { |
165 | $this->set_data('group_name', $type_data['group_name']); |
166 | |
167 | parent::create_insert_array($type_data, $pre_create_data); |
168 | } |
169 | } |