From 0cfb7b821d07e58b28d2d8c54227483e4c335fb9 Mon Sep 17 00:00:00 2001 From: Marcin Kurczewski Date: Tue, 30 Sep 2014 15:39:51 +0200 Subject: [PATCH] Added uploader: support to post searching --- TODO | 1 - src/Dao/PostDao.php | 5 +++++ src/SearchServices/Filters/PostFilter.php | 1 + src/SearchServices/Parsers/PostSearchParser.php | 12 ++++++++++++ 4 files changed, 18 insertions(+), 1 deletion(-) diff --git a/TODO b/TODO index 945e630b..51095c91 100644 --- a/TODO +++ b/TODO @@ -11,7 +11,6 @@ everything related to posts: - add warning if no posts were found - search filters - safety:safe/sketchy/unsafe - - submit:rr- - comment:rr- - comment_count: 3..5 - fav:rr- diff --git a/src/Dao/PostDao.php b/src/Dao/PostDao.php index ee68d59f..43870e96 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_UPLOADER) + { + $query->innerJoin('users uploader ON uploader.id = userId'); + } + parent::decorateQueryFromRequirement($query, $requirement); } diff --git a/src/SearchServices/Filters/PostFilter.php b/src/SearchServices/Filters/PostFilter.php index ed85ec84..7d6a4506 100644 --- a/src/SearchServices/Filters/PostFilter.php +++ b/src/SearchServices/Filters/PostFilter.php @@ -17,6 +17,7 @@ class PostFilter extends BasicFilter implements IFilter const REQUIREMENT_TAG_COUNT = 'tagCount'; const REQUIREMENT_FAV_COUNT = 'favCount'; const REQUIREMENT_SCORE = 'score'; + const REQUIREMENT_UPLOADER = 'uploader.name'; public function __construct() { diff --git a/src/SearchServices/Parsers/PostSearchParser.php b/src/SearchServices/Parsers/PostSearchParser.php index 3e0347e3..1275da86 100644 --- a/src/SearchServices/Parsers/PostSearchParser.php +++ b/src/SearchServices/Parsers/PostSearchParser.php @@ -37,6 +37,9 @@ class PostSearchParser extends AbstractSearchParser elseif ($token->getKey() === 'score') $this->addScoreRequirement($filter, $token); + elseif ($token->getKey() === 'uploader') + $this->addUploaderRequirement($filter, $token); + else throw new \BadMethodCallException('Not supported'); } @@ -138,6 +141,15 @@ class PostSearchParser extends AbstractSearchParser self::ALLOW_COMPOSITE | self::ALLOW_RANGES); } + private function addUploaderRequirement($filter, $token) + { + $this->addRequirementFromToken( + $filter, + $token, + \Szurubooru\SearchServices\Filters\PostFilter::REQUIREMENT_UPLOADER, + self::ALLOW_COMPOSITE); + } + private function dateToTime($value) { $value = strtolower(trim($value));