This commit is contained in:
Marcin Kurczewski 2013-11-03 09:24:12 +01:00
parent e1c8139373
commit b093a090eb
2 changed files with 15 additions and 4 deletions

View file

@ -18,9 +18,20 @@ class TagController
$this->context->transport->tags = $tags;
if ($this->context->json)
{
$this->context->transport->tags = array_values(array_map(function($tag) {
return ['name' => $tag['name'], 'count' => $tag['post_count']];
}, $this->context->transport->tags));
usort($this->context->transport->tags, function($a, $b) {
return $a['count'] > $b['count'] ? -1 : 1;
});
}
else
{
uasort($this->context->transport->tags, function($a, $b) {
return strnatcasecmp($a['name'], $b['name']);
});
}
}
/**

View file

@ -16,6 +16,7 @@ class model_Tag_QueryBuilder implements AbstractQueryBuilder
->where('safety IN (' . R::genSlots($allowedSafety) . ')');
foreach ($allowedSafety as $s)
$dbQuery->put($s);
if ($query !== null)
{
$limitQuery = true;
@ -27,10 +28,9 @@ class model_Tag_QueryBuilder implements AbstractQueryBuilder
->like('LOWER(?)')
->put($query);
}
$dbQuery
->groupBy('tag.id')
->orderBy('LOWER(tag.name)')
->asc();
$dbQuery->groupBy('tag.id');
if ($limitQuery)
$dbQuery->limit(15);
}