mirror of
https://github.com/phpbb/phpbb.git
synced 2025-08-29 02:59:52 +02:00
[ticket/13713] Fix case for phpBB directory
PHPBB3-13713
This commit is contained in:
105
phpBB/phpbb/mention/source/group.php
Normal file
105
phpBB/phpbb/mention/source/group.php
Normal file
@@ -0,0 +1,105 @@
|
||||
<?php
|
||||
/**
|
||||
*
|
||||
* This file is part of the phpBB Forum Software package.
|
||||
*
|
||||
* @copyright (c) phpBB Limited <https://www.phpbb.com>
|
||||
* @license GNU General Public License, version 2 (GPL-2.0)
|
||||
*
|
||||
* For full copyright and license information, please see
|
||||
* the docs/CREDITS.txt file.
|
||||
*
|
||||
*/
|
||||
|
||||
namespace phpbb\mention\source;
|
||||
|
||||
abstract class group implements source_interface
|
||||
{
|
||||
/** @var \phpbb\db\driver\driver_interface */
|
||||
protected $db;
|
||||
|
||||
/** @var \phpbb\group\helper */
|
||||
protected $helper;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*/
|
||||
public function __construct(\phpbb\db\driver\driver_interface $db, \phpbb\group\helper $helper)
|
||||
{
|
||||
$this->db = $db;
|
||||
$this->helper = $helper;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns data for all board groups
|
||||
*
|
||||
* @return array Array of groups' data
|
||||
*/
|
||||
protected function get_groups()
|
||||
{
|
||||
static $groups = null;
|
||||
|
||||
if (is_null($groups))
|
||||
{
|
||||
$query = $this->db->sql_build_query('SELECT', [
|
||||
'SELECT' => 'g.*',
|
||||
'FROM' => [
|
||||
GROUPS_TABLE => 'g',
|
||||
],
|
||||
]);
|
||||
$res = $this->db->sql_query($query);
|
||||
|
||||
$groups = [];
|
||||
while ($row = $this->db->sql_fetchrow($res))
|
||||
{
|
||||
$group_name = $this->helper->get_name($row['group_name']);
|
||||
$groups['names'][$row['group_id']] = $group_name;
|
||||
$groups[$row['group_id']] = $row;
|
||||
$groups[$row['group_id']]['group_name'] = $group_name;
|
||||
}
|
||||
}
|
||||
return $groups;
|
||||
}
|
||||
|
||||
/**
|
||||
* Builds a query for getting group IDs based on user input
|
||||
*
|
||||
* @param string $keyword Search string
|
||||
* @param int $topic_id Current topic ID
|
||||
* @return string Query ready for execution
|
||||
*/
|
||||
abstract protected function query($keyword, $topic_id);
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function get($keyword, $topic_id)
|
||||
{
|
||||
// Grab all group IDs
|
||||
$res = $this->db->sql_query($this->query($keyword, $topic_id));
|
||||
|
||||
$group_ids = [];
|
||||
while ($row = $this->db->sql_fetchrow($res))
|
||||
{
|
||||
$group_ids[] = $row['group_id'];
|
||||
}
|
||||
|
||||
// Grab group data
|
||||
$groups = $this->get_groups();
|
||||
|
||||
$matches = preg_grep('/^' . $keyword . '.*/i', $groups['names']);
|
||||
$group_ids = array_intersect($group_ids, array_flip($matches));
|
||||
|
||||
$names = [];
|
||||
foreach ($group_ids as $group_id)
|
||||
{
|
||||
$names['g' . $group_id] = [
|
||||
'name' => $groups[$group_id]['group_name'],
|
||||
'param' => 'group_id',
|
||||
'id' => $group_id,
|
||||
];
|
||||
}
|
||||
|
||||
return $names;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user