tinternet.net/src/Repository/Blog/PostRepositoryQuery.php

34 lines
739 B
PHP
Raw Normal View History

<?php
namespace App\Repository\Blog;
2021-03-17 12:44:02 +01:00
use App\Entity\Blog\Category;
use App\Repository\RepositoryQuery;
2021-03-17 12:44:02 +01:00
use Knp\Component\Pager\PaginatorInterface;
/**
* class PostRepositoryQuery.
*
* @author Simon Vieille <simon@deblan.fr>
*/
class PostRepositoryQuery extends RepositoryQuery
{
public function __construct(PostRepository $repository, PaginatorInterface $paginator)
{
parent::__construct($repository, 'p', $paginator);
}
2021-03-17 12:44:02 +01:00
public function inCategory(Category $category)
{
$c = 'c'.mt_rand();
$this
->innerJoin('p.categories', $c)
->andWhere($c.'.id = :category')
->setParameter(':category', $category->getId())
;
return $this;
}
}