A bit more reasonable autocomplete
This commit is contained in:
parent
0f72ef3963
commit
9f5bdc3da0
2 changed files with 12 additions and 11 deletions
|
@ -154,7 +154,7 @@ $(function()
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
}
|
}
|
||||||
}).autocomplete({
|
}).autocomplete({
|
||||||
minLength: 0,
|
minLength: 1,
|
||||||
source: function(request, response)
|
source: function(request, response)
|
||||||
{
|
{
|
||||||
var term = extractLast(request.term);
|
var term = extractLast(request.term);
|
||||||
|
|
|
@ -10,25 +10,26 @@ class TagController
|
||||||
$this->context->subTitle = 'tags';
|
$this->context->subTitle = 'tags';
|
||||||
|
|
||||||
PrivilegesHelper::confirmWithException(Privilege::ListTags);
|
PrivilegesHelper::confirmWithException(Privilege::ListTags);
|
||||||
|
$suppliedFilter = InputHelper::get('filter');
|
||||||
|
|
||||||
$dbQuery = R::$f->begin();
|
$dbQuery = R::$f->begin();
|
||||||
$dbQuery->select('tag.*, COUNT(1) AS count');
|
$dbQuery->select('tag.*, COUNT(1) AS count');
|
||||||
$dbQuery->from('tag');
|
$dbQuery->from('tag');
|
||||||
$dbQuery->innerJoin('post_tag');
|
$dbQuery->innerJoin('post_tag');
|
||||||
$dbQuery->on('tag.id = post_tag.tag_id');
|
$dbQuery->on('tag.id = post_tag.tag_id');
|
||||||
$dbQuery->groupBy('tag.id');
|
|
||||||
$dbQuery->orderBy('LOWER(tag.name)')->asc();
|
|
||||||
$rows = $dbQuery->get();
|
|
||||||
$tags = R::convertToBeans('tag', $rows);
|
|
||||||
|
|
||||||
$suppliedFilter = InputHelper::get('filter');
|
|
||||||
if ($suppliedFilter)
|
if ($suppliedFilter)
|
||||||
{
|
{
|
||||||
$rows = array_filter($rows, function($row) use ($suppliedFilter)
|
if (strlen($suppliedFilter) >= 3)
|
||||||
{
|
$suppliedFilter = '%' . $suppliedFilter;
|
||||||
return strpos(strtolower($row['name']), strtolower($suppliedFilter)) !== false;
|
$suppliedFilter .= '%';
|
||||||
});
|
$dbQuery->where('LOWER(tag.name) LIKE LOWER(?)')->put($suppliedFilter);
|
||||||
}
|
}
|
||||||
|
$dbQuery->groupBy('tag.id');
|
||||||
|
$dbQuery->orderBy('LOWER(tag.name)')->asc();
|
||||||
|
if ($suppliedFilter)
|
||||||
|
$dbQuery->limit(15);
|
||||||
|
$rows = $dbQuery->get();
|
||||||
|
$tags = R::convertToBeans('tag', $rows);
|
||||||
|
|
||||||
$tags = [];
|
$tags = [];
|
||||||
$tagDistribution = [];
|
$tagDistribution = [];
|
||||||
|
|
Loading…
Reference in a new issue