Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
100.00% |
17 / 17 |
|
100.00% |
2 / 2 |
CRAP | |
100.00% |
1 / 1 |
friend | |
100.00% |
17 / 17 |
|
100.00% |
2 / 2 |
2 | |
100.00% |
1 / 1 |
set_user | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
query | |
100.00% |
16 / 16 |
|
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\mention\source; |
15 | |
16 | class friend extends base_user |
17 | { |
18 | /** @var \phpbb\user */ |
19 | protected $user; |
20 | |
21 | /** |
22 | * Set the user service used to retrieve current user ID |
23 | * |
24 | * @param \phpbb\user $user |
25 | */ |
26 | public function set_user(\phpbb\user $user): void |
27 | { |
28 | $this->user = $user; |
29 | } |
30 | |
31 | /** |
32 | * {@inheritdoc} |
33 | */ |
34 | protected function query(string $keyword, int $topic_id): string |
35 | { |
36 | /* |
37 | * For optimization purposes all friends are returned regardless of the keyword |
38 | * Names filtering is done on the frontend |
39 | * Results will be cached on a per-user basis |
40 | */ |
41 | return $this->db->sql_build_query('SELECT', [ |
42 | 'SELECT' => 'u.username_clean, u.user_id', |
43 | 'FROM' => [ |
44 | USERS_TABLE => 'u', |
45 | ], |
46 | 'LEFT_JOIN' => [ |
47 | [ |
48 | 'FROM' => [ZEBRA_TABLE => 'z'], |
49 | 'ON' => 'u.user_id = z.zebra_id' |
50 | ] |
51 | ], |
52 | 'WHERE' => 'z.friend = 1 AND z.user_id = ' . (int) $this->user->data['user_id'] . ' |
53 | AND ' . $this->db->sql_in_set('u.user_type', [USER_NORMAL, USER_FOUNDER]) . ' |
54 | AND u.username_clean ' . $this->db->sql_like_expression($keyword . $this->db->get_any_char()), |
55 | 'ORDER_BY' => 'u.user_lastvisit DESC' |
56 | ]); |
57 | } |
58 | } |