Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
100.00% |
21 / 21 |
|
100.00% |
2 / 2 |
CRAP | |
100.00% |
1 / 1 |
topic | |
100.00% |
21 / 21 |
|
100.00% |
2 / 2 |
3 | |
100.00% |
1 / 1 |
get_priority | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
2 | |||
query | |
100.00% |
20 / 20 |
|
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 topic extends base_user |
17 | { |
18 | /** |
19 | * {@inheritdoc} |
20 | */ |
21 | public function get_priority(array $row): int |
22 | { |
23 | /* |
24 | * Topic's open poster is probably the most mentionable user in the topic |
25 | * so we give him a significant priority |
26 | */ |
27 | return $row['user_id'] === $row['topic_poster'] ? 5 : 1; |
28 | } |
29 | |
30 | /** |
31 | * {@inheritdoc} |
32 | */ |
33 | protected function query(string $keyword, int $topic_id): string |
34 | { |
35 | /* |
36 | * Select poster's username together with topic author's ID |
37 | * that will be later used for prioritisation |
38 | * |
39 | * For optimization purposes all users are returned regardless of the keyword |
40 | * Names filtering is done on the frontend |
41 | * Results will be cached on a per-topic basis |
42 | */ |
43 | return $this->db->sql_build_query('SELECT', [ |
44 | 'SELECT' => 'u.username_clean, u.user_id, t.topic_poster', |
45 | 'FROM' => [ |
46 | USERS_TABLE => 'u', |
47 | ], |
48 | 'LEFT_JOIN' => [ |
49 | [ |
50 | 'FROM' => [POSTS_TABLE => 'p'], |
51 | 'ON' => 'u.user_id = p.poster_id' |
52 | ], |
53 | [ |
54 | 'FROM' => [TOPICS_TABLE => 't'], |
55 | 'ON' => 't.topic_id = p.topic_id' |
56 | ], |
57 | ], |
58 | 'WHERE' => 'p.topic_id = ' . (int) $topic_id . ' |
59 | AND ' . $this->db->sql_in_set('u.user_type', [USER_NORMAL, USER_FOUNDER]) . ' |
60 | AND u.username_clean ' . $this->db->sql_like_expression($keyword . $this->db->get_any_char()), |
61 | 'ORDER_BY' => 'p.post_time DESC' |
62 | ]); |
63 | } |
64 | } |