Fixed searching for favs and comments
This commit is contained in:
parent
d3fb910249
commit
4578f7a7a4
4 changed files with 29 additions and 4 deletions
|
@ -136,14 +136,28 @@ class PostDao extends AbstractDao implements ICrudDao
|
||||||
|
|
||||||
elseif ($requirement->getType() === PostFilter::REQUIREMENT_FAVORITE)
|
elseif ($requirement->getType() === PostFilter::REQUIREMENT_FAVORITE)
|
||||||
{
|
{
|
||||||
$query->innerJoin('favorites _fav', '_fav.postId = posts.id');
|
foreach ($requirement->getValue()->getValues() as $userName)
|
||||||
$query->innerJoin('users favoritedBy', 'favoritedBy.id = _fav.userId');
|
{
|
||||||
|
$userId = $this->userDao->findByName($userName)->getId();
|
||||||
|
$sql = 'EXISTS (SELECT 1 FROM favorites f WHERE f.postId = posts.id AND f.userId = ?)';
|
||||||
|
if ($requirement->isNegated())
|
||||||
|
$sql = 'NOT ' . $sql;
|
||||||
|
$query->where($sql, [$userId]);
|
||||||
|
}
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
elseif ($requirement->getType() === PostFilter::REQUIREMENT_COMMENT)
|
elseif ($requirement->getType() === PostFilter::REQUIREMENT_COMMENT)
|
||||||
{
|
{
|
||||||
$query->innerJoin('comments _comment', '_comment.postId = posts.id');
|
foreach ($requirement->getValue()->getValues() as $userName)
|
||||||
$query->innerJoin('users commentedBy', 'commentedBy.id = _comment.userId');
|
{
|
||||||
|
$userId = $this->userDao->findByName($userName)->getId();
|
||||||
|
$sql = 'EXISTS (SELECT 1 FROM comments c WHERE c.postId = posts.id AND c.userId = ?)';
|
||||||
|
if ($requirement->isNegated())
|
||||||
|
$sql = 'NOT ' . $sql;
|
||||||
|
$query->where($sql, [$userId]);
|
||||||
|
}
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
elseif ($requirement->getType() === PostFilter::REQUIREMENT_UPLOADER)
|
elseif ($requirement->getType() === PostFilter::REQUIREMENT_UPLOADER)
|
||||||
|
|
|
@ -3,4 +3,5 @@ namespace Szurubooru\SearchServices\Requirements;
|
||||||
|
|
||||||
interface IRequirementValue
|
interface IRequirementValue
|
||||||
{
|
{
|
||||||
|
public function getValues();
|
||||||
}
|
}
|
||||||
|
|
|
@ -25,4 +25,9 @@ class RequirementRangedValue implements IRequirementValue
|
||||||
{
|
{
|
||||||
$this->maxValue = $maxValue;
|
$this->maxValue = $maxValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function getValues()
|
||||||
|
{
|
||||||
|
return range($this->minValue, $this->maxValue);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,4 +19,9 @@ class RequirementSingleValue implements IRequirementValue
|
||||||
{
|
{
|
||||||
$this->value = $value;
|
$this->value = $value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function getValues()
|
||||||
|
{
|
||||||
|
return [$this->value];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue