1
0
mirror of https://github.com/phpbb/phpbb.git synced 2025-07-30 21:40:43 +02:00

[ticket/13713] Refactor sorting functionality

PHPBB3-13713
This commit is contained in:
lavigor
2018-07-09 02:16:42 +03:00
committed by Marc Alexander
parent ffbff7ed79
commit 2bb50add04
13 changed files with 86 additions and 37 deletions

View File

@@ -55,7 +55,7 @@ class mention
foreach ($this->mention_sources as $source)
{
$names += $source->get($keyword, $topic_id);
$source->get($names, $keyword, $topic_id);
}
return new JsonResponse(array_values($names));

View File

@@ -109,7 +109,7 @@ abstract class base_group implements source_interface
/**
* {@inheritdoc}
*/
public function get($keyword, $topic_id)
public function get(array &$names, $keyword, $topic_id)
{
// Grab all group IDs
$result = $this->db->sql_query($this->query($keyword, $topic_id));
@@ -128,11 +128,10 @@ abstract class base_group implements source_interface
$matches = preg_grep('/^' . preg_quote($keyword) . '.*/i', $groups['names']);
$group_ids = array_intersect($group_ids, array_flip($matches));
$names = [];
foreach ($group_ids as $group_id)
{
$group_rank = phpbb_get_user_rank($groups[$group_id], false);
$names[] = [
array_push($names, [
'name' => $groups[$group_id]['group_name'],
'type' => 'g',
'id' => $group_id,
@@ -141,7 +140,7 @@ abstract class base_group implements source_interface
'img' => phpbb_get_group_avatar($groups[$group_id]),
],
'rank' => $group_rank['title'],
];
]);
}
return $names;

View File

@@ -73,16 +73,15 @@ abstract class base_user implements source_interface
/**
* {@inheritdoc}
*/
public function get($keyword, $topic_id)
public function get(array &$names, $keyword, $topic_id)
{
$keyword = utf8_clean_string($keyword);
$result = $this->db->sql_query_limit($this->query($keyword, $topic_id), self::NAMES_BATCH_SIZE);
$names = [];
while ($row = $this->db->sql_fetchrow($result))
{
$user_rank = $this->user_loader->get_rank($row['user_id'], true);
$names[] = [
array_push($names, [
'name' => $row['username'],
'type' => 'u',
'id' => $row['user_id'],
@@ -92,7 +91,7 @@ abstract class base_user implements source_interface
],
'rank' => (isset($user_rank['rank_title'])) ? $user_rank['rank_title'] : '',
'priority' => $this->get_priority($row),
];
]);
}
$this->db->sql_freeresult($result);

View File

@@ -45,7 +45,6 @@ class friend extends base_user
]
],
'WHERE' => 'z.friend = 1 AND z.user_id = ' . (int) $this->user->data['user_id'] . '
AND u.user_id <> ' . ANONYMOUS . '
AND ' . $this->db->sql_in_set('u.user_type', [USER_NORMAL, USER_FOUNDER]) . '
AND u.username_clean ' . $this->db->sql_like_expression($keyword . $this->db->get_any_char()),
'ORDER_BY' => 'u.user_lastvisit DESC'

View File

@@ -19,9 +19,10 @@ interface source_interface
* Searches database for names to mention
* and returns and array of found items
*
* @param array $names Array of already fetched data with names
* @param string $keyword Search string
* @param int $topic_id Current topic ID
* @return array Array of names
*/
public function get($keyword, $topic_id);
public function get(array &$names, $keyword, $topic_id);
}

View File

@@ -28,7 +28,6 @@ class team extends base_user
TEAMPAGE_TABLE => 't',
],
'WHERE' => 'ug.group_id = t.group_id AND ug.user_id = u.user_id AND ug.user_pending = 0
AND u.user_id <> ' . ANONYMOUS . '
AND ' . $this->db->sql_in_set('u.user_type', [USER_NORMAL, USER_FOUNDER]) . '
AND u.username_clean ' . $this->db->sql_like_expression($keyword . $this->db->get_any_char()),
'ORDER_BY' => 'u.user_lastvisit DESC'

View File

@@ -31,7 +31,7 @@ class topic extends base_user
'ON' => 'u.user_id = p.poster_id'
]
],
'WHERE' => 'p.topic_id = ' . $topic_id . ' AND u.user_id <> ' . ANONYMOUS . '
'WHERE' => 'p.topic_id = ' . $topic_id . '
AND ' . $this->db->sql_in_set('u.user_type', [USER_NORMAL, USER_FOUNDER]) . '
AND u.username_clean ' . $this->db->sql_like_expression($keyword . $this->db->get_any_char()),
'ORDER_BY' => 'p.post_time DESC'

View File

@@ -25,8 +25,7 @@ class user extends base_user
'FROM' => [
USERS_TABLE => 'u',
],
'WHERE' => 'u.user_id <> ' . ANONYMOUS . '
AND ' . $this->db->sql_in_set('u.user_type', [USER_NORMAL, USER_FOUNDER]) . '
'WHERE' => $this->db->sql_in_set('u.user_type', [USER_NORMAL, USER_FOUNDER]) . '
AND u.username_clean ' . $this->db->sql_like_expression($keyword . $this->db->get_any_char()),
'ORDER_BY' => 'u.user_lastvisit DESC'
]);