diff --git a/src/Dao/PostDao.php b/src/Dao/PostDao.php index 8d780a45..8c4bd72f 100644 --- a/src/Dao/PostDao.php +++ b/src/Dao/PostDao.php @@ -136,14 +136,28 @@ class PostDao extends AbstractDao implements ICrudDao elseif ($requirement->getType() === PostFilter::REQUIREMENT_FAVORITE) { - $query->innerJoin('favorites _fav', '_fav.postId = posts.id'); - $query->innerJoin('users favoritedBy', 'favoritedBy.id = _fav.userId'); + foreach ($requirement->getValue()->getValues() as $userName) + { + $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) { - $query->innerJoin('comments _comment', '_comment.postId = posts.id'); - $query->innerJoin('users commentedBy', 'commentedBy.id = _comment.userId'); + foreach ($requirement->getValue()->getValues() as $userName) + { + $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) diff --git a/src/SearchServices/Requirements/IRequirementValue.php b/src/SearchServices/Requirements/IRequirementValue.php index 884c0e7b..3fefa125 100644 --- a/src/SearchServices/Requirements/IRequirementValue.php +++ b/src/SearchServices/Requirements/IRequirementValue.php @@ -3,4 +3,5 @@ namespace Szurubooru\SearchServices\Requirements; interface IRequirementValue { + public function getValues(); } diff --git a/src/SearchServices/Requirements/RequirementRangedValue.php b/src/SearchServices/Requirements/RequirementRangedValue.php index dd543d34..678462d8 100644 --- a/src/SearchServices/Requirements/RequirementRangedValue.php +++ b/src/SearchServices/Requirements/RequirementRangedValue.php @@ -25,4 +25,9 @@ class RequirementRangedValue implements IRequirementValue { $this->maxValue = $maxValue; } + + public function getValues() + { + return range($this->minValue, $this->maxValue); + } } diff --git a/src/SearchServices/Requirements/RequirementSingleValue.php b/src/SearchServices/Requirements/RequirementSingleValue.php index 65215916..73cf9d7b 100644 --- a/src/SearchServices/Requirements/RequirementSingleValue.php +++ b/src/SearchServices/Requirements/RequirementSingleValue.php @@ -19,4 +19,9 @@ class RequirementSingleValue implements IRequirementValue { $this->value = $value; } + + public function getValues() + { + return [$this->value]; + } }