From e43f3b54d7da291fea0dff0d504464a93d2271d2 Mon Sep 17 00:00:00 2001 From: Marcin Kurczewski Date: Sat, 4 Oct 2014 16:44:57 +0200 Subject: [PATCH] Added various option support to post searching --- TODO | 5 ----- src/Dao/PostDao.php | 6 ++++++ src/SearchServices/Filters/PostFilter.php | 4 ++++ .../Parsers/PostSearchParser.php | 21 +++++++++++++++++++ 4 files changed, 31 insertions(+), 5 deletions(-) diff --git a/TODO b/TODO index 928eb5bd..49a7410d 100644 --- a/TODO +++ b/TODO @@ -6,13 +6,8 @@ everything related to posts: - better thumbnail loading - comment count - search filters - - comment:rr- - - comment_count: 3..5 - file_size:3K..5M - image_size:huge/large/medium/small - - search order - - order:comment_count - - order:comment_time - single post view - previous and next post (difficult) diff --git a/src/Dao/PostDao.php b/src/Dao/PostDao.php index 28830ead..b8bd9091 100644 --- a/src/Dao/PostDao.php +++ b/src/Dao/PostDao.php @@ -116,6 +116,12 @@ class PostDao extends AbstractDao implements ICrudDao $query->innerJoin('users favoritedBy ON favoritedBy.id = _fav.userId'); } + elseif ($requirement->getType() === \Szurubooru\SearchServices\Filters\PostFilter::REQUIREMENT_COMMENT) + { + $query->innerJoin('comments _comment ON _comment.postId = posts.id'); + $query->innerJoin('users commentedBy ON commentedBy.id = _comment.userId'); + } + elseif ($requirement->getType() === \Szurubooru\SearchServices\Filters\PostFilter::REQUIREMENT_UPLOADER) { $query->innerJoin('users uploader ON uploader.id = userId'); diff --git a/src/SearchServices/Filters/PostFilter.php b/src/SearchServices/Filters/PostFilter.php index a47e1a5f..e1be1fb7 100644 --- a/src/SearchServices/Filters/PostFilter.php +++ b/src/SearchServices/Filters/PostFilter.php @@ -10,6 +10,9 @@ class PostFilter extends BasicFilter implements IFilter const ORDER_SCORE = 'score'; const ORDER_LAST_EDIT_TIME = 'lastEditTime'; const ORDER_FILE_SIZE = 'originalFileSize'; + const ORDER_LAST_COMMENT_TIME = 'lastCommentTime'; + const ORDER_LAST_FAV_TIME = 'lastFavTime'; + const ORDER_LAST_FEATURE_TIME = 'lastFeatureTime'; const REQUIREMENT_TAG = 'tag'; const REQUIREMENT_ID = 'id'; @@ -21,6 +24,7 @@ class PostFilter extends BasicFilter implements IFilter const REQUIREMENT_UPLOADER = 'uploader.name'; const REQUIREMENT_SAFETY = 'safety'; const REQUIREMENT_FAVORITE = 'favoritedBy.name'; + const REQUIREMENT_COMMENT = 'commentedBy.name'; const REQUIREMENT_TYPE = 'contentType'; const REQUIREMENT_USER_SCORE = 'userScore'; diff --git a/src/SearchServices/Parsers/PostSearchParser.php b/src/SearchServices/Parsers/PostSearchParser.php index c29ec9f1..d7d06b85 100644 --- a/src/SearchServices/Parsers/PostSearchParser.php +++ b/src/SearchServices/Parsers/PostSearchParser.php @@ -56,6 +56,9 @@ class PostSearchParser extends AbstractSearchParser elseif ($token->getKey() === 'type') $this->addTypeRequirement($filter, $token); + elseif ($token->getKey() === 'comment') + $this->addCommentRequirement($filter, $token); + elseif ($token->getKey() === 'special' and $token->getValue() === 'liked' and $this->authService->isLoggedIn()) $this->addUserScoreRequirement($filter, $this->authService->getLoggedInUser()->getName(), 1, $token->isNegated()); @@ -100,6 +103,15 @@ class PostSearchParser extends AbstractSearchParser elseif ($token === 'random') return \Szurubooru\SearchServices\Filters\PostFilter::ORDER_RANDOM; + elseif ($token === 'feature_time') + return \Szurubooru\SearchServices\Filters\PostFilter::ORDER_LAST_FEATURE_TIME; + + elseif ($token === 'comment_time') + return \Szurubooru\SearchServices\Filters\PostFilter::ORDER_LAST_COMMENT_TIME; + + elseif ($token === 'fav_time') + return \Szurubooru\SearchServices\Filters\PostFilter::ORDER_LAST_FAV_TIME; + throw new \BadMethodCallException('Not supported'); } @@ -221,6 +233,15 @@ class PostSearchParser extends AbstractSearchParser }); } + private function addCommentRequirement($filter, $token) + { + $this->addRequirementFromToken( + $filter, + $token, + \Szurubooru\SearchServices\Filters\PostFilter::REQUIREMENT_COMMENT, + self::ALLOW_COMPOSITE); + } + private function addUserScoreRequirement($filter, $userName, $score, $isNegated) { $tokenValue = new \Szurubooru\SearchServices\Requirements\RequirementCompositeValue();