45 lines
965 B
PHP
45 lines
965 B
PHP
<?php
|
|
|
|
namespace App\Repository\Blog;
|
|
|
|
use App\Entity\Blog\Category;
|
|
use App\Repository\RepositoryQuery;
|
|
use Knp\Component\Pager\PaginatorInterface;
|
|
use App\Entity\User;
|
|
|
|
/**
|
|
* class PostRepositoryQuery.
|
|
*
|
|
* @author Simon Vieille <simon@deblan.fr>
|
|
*/
|
|
class PostRepositoryQuery extends RepositoryQuery
|
|
{
|
|
public function __construct(PostRepository $repository, PaginatorInterface $paginator)
|
|
{
|
|
parent::__construct($repository, 'p', $paginator);
|
|
}
|
|
|
|
public function inCategory(Category $category)
|
|
{
|
|
$c = 'c'.mt_rand();
|
|
|
|
$this
|
|
->innerJoin('p.categories', $c)
|
|
->andWhere($c.'.id = :category')
|
|
->setParameter(':category', $category->getId())
|
|
;
|
|
|
|
return $this;
|
|
}
|
|
|
|
public function filterByAuthor(User $user)
|
|
{
|
|
$this
|
|
->andWhere('.author = :author')
|
|
->setParameter(':author', $user->getId())
|
|
;
|
|
|
|
return $this;
|
|
}
|
|
}
|