From c124f89b8bac867a348aba78ed46b1d4e4bd1a6b Mon Sep 17 00:00:00 2001 From: Marcin Kurczewski Date: Wed, 1 Oct 2014 14:34:49 +0200 Subject: [PATCH] Added fav: support to post searching --- TODO | 1 - src/Dao/PostDao.php | 5 +++++ src/SearchServices/Filters/PostFilter.php | 1 + src/SearchServices/Parsers/PostSearchParser.php | 11 +++++++++++ 4 files changed, 17 insertions(+), 1 deletion(-) diff --git a/TODO b/TODO index 2dcfb7d2..5b7cb0cb 100644 --- a/TODO +++ b/TODO @@ -12,7 +12,6 @@ everything related to posts: - search filters - comment:rr- - comment_count: 3..5 - - fav:rr- - file_size:3K..5M - image_size:huge/large/medium/small - type:img/flash/yt/video diff --git a/src/Dao/PostDao.php b/src/Dao/PostDao.php index 43870e96..83be8011 100644 --- a/src/Dao/PostDao.php +++ b/src/Dao/PostDao.php @@ -110,6 +110,11 @@ class PostDao extends AbstractDao implements ICrudDao return; } + elseif ($requirement->getType() === \Szurubooru\SearchServices\Filters\PostFilter::REQUIREMENT_FAVORITE) + { + $query->innerJoin('favorites _fav ON _fav.postId = posts.id INNER JOIN users favorite ON favorite.id = _fav.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 167fdc68..8516849e 100644 --- a/src/SearchServices/Filters/PostFilter.php +++ b/src/SearchServices/Filters/PostFilter.php @@ -19,6 +19,7 @@ class PostFilter extends BasicFilter implements IFilter const REQUIREMENT_SCORE = 'score'; const REQUIREMENT_UPLOADER = 'uploader.name'; const REQUIREMENT_SAFETY = 'safety'; + const REQUIREMENT_FAVORITE = 'favorite.name'; public function __construct() { diff --git a/src/SearchServices/Parsers/PostSearchParser.php b/src/SearchServices/Parsers/PostSearchParser.php index ee8d31b1..0ee88899 100644 --- a/src/SearchServices/Parsers/PostSearchParser.php +++ b/src/SearchServices/Parsers/PostSearchParser.php @@ -43,6 +43,9 @@ class PostSearchParser extends AbstractSearchParser elseif ($token->getKey() === 'safety') $this->addSafetyRequirement($filter, $token); + elseif ($token->getKey() === 'fav') + $this->addFavRequirement($filter, $token); + else throw new \BadMethodCallException('Not supported'); } @@ -166,6 +169,14 @@ class PostSearchParser extends AbstractSearchParser }); } + private function addFavRequirement($filter, $token) + { + $this->addRequirementFromToken( + $filter, + $token, + \Szurubooru\SearchServices\Filters\PostFilter::REQUIREMENT_FAVORITE, + self::ALLOW_COMPOSITE); + } private function dateToTime($value) {