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; $this->context->transport->tags = $tags;
if ($this->context->json) if ($this->context->json)
{
$this->context->transport->tags = array_values(array_map(function($tag) { $this->context->transport->tags = array_values(array_map(function($tag) {
return ['name' => $tag['name'], 'count' => $tag['post_count']]; return ['name' => $tag['name'], 'count' => $tag['post_count']];
}, $this->context->transport->tags)); }, $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) . ')'); ->where('safety IN (' . R::genSlots($allowedSafety) . ')');
foreach ($allowedSafety as $s) foreach ($allowedSafety as $s)
$dbQuery->put($s); $dbQuery->put($s);
if ($query !== null) if ($query !== null)
{ {
$limitQuery = true; $limitQuery = true;
@ -27,10 +28,9 @@ class model_Tag_QueryBuilder implements AbstractQueryBuilder
->like('LOWER(?)') ->like('LOWER(?)')
->put($query); ->put($query);
} }
$dbQuery
->groupBy('tag.id') $dbQuery->groupBy('tag.id');
->orderBy('LOWER(tag.name)')
->asc();
if ($limitQuery) if ($limitQuery)
$dbQuery->limit(15); $dbQuery->limit(15);
} }