From c021c9a1c0b74fec9493a06dd3247a5ecfd5962f Mon Sep 17 00:00:00 2001 From: Marcin Kurczewski Date: Fri, 3 Oct 2014 13:43:09 +0200 Subject: [PATCH] Added type: support to post searching --- TODO | 1 - src/Helpers/EnumHelper.php | 5 +++++ src/SearchServices/Filters/PostFilter.php | 1 + src/SearchServices/Parsers/PostSearchParser.php | 16 ++++++++++++++++ 4 files changed, 22 insertions(+), 1 deletion(-) diff --git a/TODO b/TODO index 48e6aa79..88872da0 100644 --- a/TODO +++ b/TODO @@ -12,7 +12,6 @@ everything related to posts: - comment_count: 3..5 - file_size:3K..5M - image_size:huge/large/medium/small - - type:img/flash/yt/video - special:liked - special:disliked - special:fav diff --git a/src/Helpers/EnumHelper.php b/src/Helpers/EnumHelper.php index 368d8ba5..c31e476c 100644 --- a/src/Helpers/EnumHelper.php +++ b/src/Helpers/EnumHelper.php @@ -75,6 +75,11 @@ class EnumHelper return self::enumToString(self::$postTypeMap, $postType); } + public static function postTypeFromString($postTypeString) + { + return self::stringToEnum(self::$postTypeMap, $postTypeString); + } + public static function snapshotTypeFromString($snapshotTypeString) { return self::stringToEnum(self::$snapshotTypeMap, $snapshotTypeString); diff --git a/src/SearchServices/Filters/PostFilter.php b/src/SearchServices/Filters/PostFilter.php index 8516849e..f5b551ed 100644 --- a/src/SearchServices/Filters/PostFilter.php +++ b/src/SearchServices/Filters/PostFilter.php @@ -20,6 +20,7 @@ class PostFilter extends BasicFilter implements IFilter const REQUIREMENT_UPLOADER = 'uploader.name'; const REQUIREMENT_SAFETY = 'safety'; const REQUIREMENT_FAVORITE = 'favorite.name'; + const REQUIREMENT_TYPE = 'contentType'; public function __construct() { diff --git a/src/SearchServices/Parsers/PostSearchParser.php b/src/SearchServices/Parsers/PostSearchParser.php index 0ee88899..43975724 100644 --- a/src/SearchServices/Parsers/PostSearchParser.php +++ b/src/SearchServices/Parsers/PostSearchParser.php @@ -46,6 +46,9 @@ class PostSearchParser extends AbstractSearchParser elseif ($token->getKey() === 'fav') $this->addFavRequirement($filter, $token); + elseif ($token->getKey() === 'type') + $this->addTypeRequirement($filter, $token); + else throw new \BadMethodCallException('Not supported'); } @@ -178,6 +181,19 @@ class PostSearchParser extends AbstractSearchParser self::ALLOW_COMPOSITE); } + private function addTypeRequirement($filter, $token) + { + $this->addRequirementFromToken( + $filter, + $token, + \Szurubooru\SearchServices\Filters\PostFilter::REQUIREMENT_TYPE, + self::ALLOW_COMPOSITE, + function ($value) + { + return \Szurubooru\Helpers\EnumHelper::postTypeFromSTring($value); + }); + } + private function dateToTime($value) { $value = strtolower(trim($value));