mirror of
https://github.com/phpbb/phpbb.git
synced 2025-08-25 09:30:46 +02:00
[ticket/13713] Introduce priorities based sorting
PHPBB3-13713
This commit is contained in:
@@ -54,7 +54,7 @@ class mention
|
||||
|
||||
foreach ($this->mention_sources as $source)
|
||||
{
|
||||
$names = array_merge($names, $source->get($keyword, $topic_id));
|
||||
$names += $source->get($keyword, $topic_id);
|
||||
}
|
||||
|
||||
return new JsonResponse(array_values($names));
|
||||
|
@@ -131,7 +131,7 @@ abstract class base_group implements source_interface
|
||||
foreach ($group_ids as $group_id)
|
||||
{
|
||||
$group_rank = phpbb_get_user_rank($groups[$group_id], false);
|
||||
$names['g' . $group_id] = [
|
||||
$names[] = [
|
||||
'name' => $groups[$group_id]['group_name'],
|
||||
'type' => 'g',
|
||||
'id' => $group_id,
|
||||
|
@@ -15,6 +15,9 @@ namespace phpbb\mention\source;
|
||||
|
||||
abstract class base_user implements source_interface
|
||||
{
|
||||
/** @var int */
|
||||
const NAMES_BATCH_SIZE = 100;
|
||||
|
||||
/** @var \phpbb\db\driver\driver_interface */
|
||||
protected $db;
|
||||
|
||||
@@ -56,19 +59,30 @@ abstract class base_user implements source_interface
|
||||
*/
|
||||
abstract protected function query($keyword, $topic_id);
|
||||
|
||||
/**
|
||||
* Returns the priority of the currently selected name
|
||||
*
|
||||
* @param array $row Array of fetched user data
|
||||
* @return int Priority (defaults to 1)
|
||||
*/
|
||||
public function get_priority($row)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function get($keyword, $topic_id)
|
||||
{
|
||||
$keyword = utf8_clean_string($keyword);
|
||||
$result = $this->db->sql_query_limit($this->query($keyword, $topic_id), $this->config['mention_names_limit']);
|
||||
$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['u' . $row['user_id']] = [
|
||||
$names[] = [
|
||||
'name' => $row['username'],
|
||||
'type' => 'u',
|
||||
'id' => $row['user_id'],
|
||||
@@ -77,6 +91,7 @@ abstract class base_user implements source_interface
|
||||
'img' => $this->user_loader->get_avatar($row['user_id'], true),
|
||||
],
|
||||
'rank' => (isset($user_rank['rank_title'])) ? $user_rank['rank_title'] : '',
|
||||
'priority' => $this->get_priority($row),
|
||||
];
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user