add murph - add most of the previous blog pages
This commit is contained in:
parent
40ed84dea3
commit
38bec1c0fa
152 changed files with 14834 additions and 220 deletions
65
src/Repository/Blog/PostRepositoryQuery.php
Normal file
65
src/Repository/Blog/PostRepositoryQuery.php
Normal file
|
|
@ -0,0 +1,65 @@
|
|||
<?php
|
||||
|
||||
namespace App\Repository\Blog;
|
||||
|
||||
use App\Core\Repository\RepositoryQuery;
|
||||
use App\Entity\Blog\Category;
|
||||
use App\Entity\User;
|
||||
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);
|
||||
}
|
||||
|
||||
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 published()
|
||||
{
|
||||
return $this
|
||||
->andWhere('.status = 1')
|
||||
->andWhere('.publishedAt <= :now')
|
||||
->setParameter(':now', (new \DateTime('now'))->format('Y-m-d H:i:s'));
|
||||
}
|
||||
|
||||
public function useFilters(array $filters)
|
||||
{
|
||||
foreach ($filters as $name => $value) {
|
||||
if ($value === null) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (is_int($value)) {
|
||||
$this->andWhere('.'.$name.' = :'.$name);
|
||||
$this->setParameter(':'.$name, $value);
|
||||
} elseif (is_string($value)) {
|
||||
$this->andWhere('.'.$name.' LIKE :'.$name);
|
||||
$this->setParameter(':'.$name, '%'.$value.'%');
|
||||
} else {
|
||||
if ($name === 'category') {
|
||||
$this->inCategory($value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue