From b093a090ebc59f5fda6cb4432877261fe0a31e12 Mon Sep 17 00:00:00 2001 From: Marcin Kurczewski Date: Sun, 3 Nov 2013 09:24:12 +0100 Subject: [PATCH] Closed #56 --- src/Controllers/TagController.php | 11 +++++++++++ src/Models/Model_Tag_QueryBuilder.php | 8 ++++---- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/src/Controllers/TagController.php b/src/Controllers/TagController.php index da741301..649d9ed9 100644 --- a/src/Controllers/TagController.php +++ b/src/Controllers/TagController.php @@ -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']); + }); + } } /** diff --git a/src/Models/Model_Tag_QueryBuilder.php b/src/Models/Model_Tag_QueryBuilder.php index 3344f608..89474792 100644 --- a/src/Models/Model_Tag_QueryBuilder.php +++ b/src/Models/Model_Tag_QueryBuilder.php @@ -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); }