From 57dc7c5fad31d558d9ddbf4415067f9c509383f7 Mon Sep 17 00:00:00 2001 From: Marcin Kurczewski Date: Tue, 30 Sep 2014 15:05:13 +0200 Subject: [PATCH] Added order:id support to post searching --- TODO | 1 - src/SearchServices/Filters/BasicFilter.php | 7 +------ src/SearchServices/Filters/PostFilter.php | 6 ++++++ src/SearchServices/Filters/UserFilter.php | 5 +++++ src/SearchServices/Parsers/PostSearchParser.php | 5 ++++- tests/Dao/UserDaoFilterTest.php | 2 +- 6 files changed, 17 insertions(+), 9 deletions(-) diff --git a/TODO b/TODO index c1049558..77383c93 100644 --- a/TODO +++ b/TODO @@ -25,7 +25,6 @@ everything related to posts: - special:disliked - special:fav - search order - - order:id - order:time - order:comment_count - order:comment_time diff --git a/src/SearchServices/Filters/BasicFilter.php b/src/SearchServices/Filters/BasicFilter.php index e8458095..9256d355 100644 --- a/src/SearchServices/Filters/BasicFilter.php +++ b/src/SearchServices/Filters/BasicFilter.php @@ -3,16 +3,11 @@ namespace Szurubooru\SearchServices\Filters; class BasicFilter implements IFilter { - private $order; + private $order = []; private $requirements = []; private $pageNumber; private $pageSize; - public function __construct() - { - $this->setOrder(['id' => self::ORDER_DESC]); - } - public function getOrder() { return $this->order; diff --git a/src/SearchServices/Filters/PostFilter.php b/src/SearchServices/Filters/PostFilter.php index bad1dd16..207cb979 100644 --- a/src/SearchServices/Filters/PostFilter.php +++ b/src/SearchServices/Filters/PostFilter.php @@ -3,6 +3,7 @@ namespace Szurubooru\SearchServices\Filters; class PostFilter extends BasicFilter implements IFilter { + const ORDER_ID = 'id'; const ORDER_FAV_TIME = 'lastFavTime'; const ORDER_FAV_COUNT = 'favCount'; const ORDER_TAG_COUNT = 'tagCount'; @@ -12,4 +13,9 @@ class PostFilter extends BasicFilter implements IFilter const REQUIREMENT_ID = 'id'; const REQUIREMENT_DATE = 'uploadTime'; const REQUIREMENT_HASH = 'name'; + + public function __construct() + { + $this->setOrder([self::ORDER_ID => self::ORDER_DESC]); + } } diff --git a/src/SearchServices/Filters/UserFilter.php b/src/SearchServices/Filters/UserFilter.php index 970e2087..3868a4c2 100644 --- a/src/SearchServices/Filters/UserFilter.php +++ b/src/SearchServices/Filters/UserFilter.php @@ -5,4 +5,9 @@ class UserFilter extends BasicFilter implements IFilter { const ORDER_NAME = 'name'; const ORDER_REGISTRATION_TIME = 'registrationTime'; + + public function __construct() + { + $this->setOrder([self::ORDER_NAME => self::ORDER_ASC]); + } } diff --git a/src/SearchServices/Parsers/PostSearchParser.php b/src/SearchServices/Parsers/PostSearchParser.php index d47bb325..d11d51db 100644 --- a/src/SearchServices/Parsers/PostSearchParser.php +++ b/src/SearchServices/Parsers/PostSearchParser.php @@ -34,7 +34,10 @@ class PostSearchParser extends AbstractSearchParser protected function getOrderColumn($token) { - if ($token === 'fav_time') + if ($token === 'id') + return \Szurubooru\SearchServices\Filters\PostFilter::ORDER_ID; + + elseif ($token === 'fav_time') return \Szurubooru\SearchServices\Filters\PostFilter::ORDER_FAV_TIME; elseif ($token === 'fav_count') diff --git a/tests/Dao/UserDaoFilterTest.php b/tests/Dao/UserDaoFilterTest.php index 14e82f10..abf8e3f5 100644 --- a/tests/Dao/UserDaoFilterTest.php +++ b/tests/Dao/UserDaoFilterTest.php @@ -70,7 +70,7 @@ class UserDaoFilterTest extends \Szurubooru\Tests\AbstractDatabaseTestCase public function testDefaultOrder() { list ($user1, $user2) = $this->prepareUsers(); - $this->doTestSorting(null, null, [$user2, $user1]); + $this->doTestSorting(null, null, [$user1, $user2]); } public function testOrderByNameAscending()