Added fav: support to post searching

This commit is contained in:
Marcin Kurczewski 2014-10-01 14:34:49 +02:00
parent 97a1c52018
commit c124f89b8b
4 changed files with 17 additions and 1 deletions

1
TODO
View file

@ -12,7 +12,6 @@ everything related to posts:
- search filters - search filters
- comment:rr- - comment:rr-
- comment_count: 3..5 - comment_count: 3..5
- fav:rr-
- file_size:3K..5M - file_size:3K..5M
- image_size:huge/large/medium/small - image_size:huge/large/medium/small
- type:img/flash/yt/video - type:img/flash/yt/video

View file

@ -110,6 +110,11 @@ class PostDao extends AbstractDao implements ICrudDao
return; 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) elseif ($requirement->getType() === \Szurubooru\SearchServices\Filters\PostFilter::REQUIREMENT_UPLOADER)
{ {
$query->innerJoin('users uploader ON uploader.id = userId'); $query->innerJoin('users uploader ON uploader.id = userId');

View file

@ -19,6 +19,7 @@ class PostFilter extends BasicFilter implements IFilter
const REQUIREMENT_SCORE = 'score'; const REQUIREMENT_SCORE = 'score';
const REQUIREMENT_UPLOADER = 'uploader.name'; const REQUIREMENT_UPLOADER = 'uploader.name';
const REQUIREMENT_SAFETY = 'safety'; const REQUIREMENT_SAFETY = 'safety';
const REQUIREMENT_FAVORITE = 'favorite.name';
public function __construct() public function __construct()
{ {

View file

@ -43,6 +43,9 @@ class PostSearchParser extends AbstractSearchParser
elseif ($token->getKey() === 'safety') elseif ($token->getKey() === 'safety')
$this->addSafetyRequirement($filter, $token); $this->addSafetyRequirement($filter, $token);
elseif ($token->getKey() === 'fav')
$this->addFavRequirement($filter, $token);
else else
throw new \BadMethodCallException('Not supported'); 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) private function dateToTime($value)
{ {