-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTagRepository.php
More file actions
59 lines (50 loc) · 1.66 KB
/
Copy pathTagRepository.php
File metadata and controls
59 lines (50 loc) · 1.66 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
<?php
declare(strict_types=1);
namespace Light\Blog\Repository;
use Doctrine\ORM\Tools\Pagination\Paginator as DoctrinePaginator;
use Light\App\Repository\AbstractRepository;
use Light\Blog\Entity\Post;
use Light\Blog\Entity\Tag;
use Light\Blog\Enum\PostStatusEnum;
class TagRepository extends AbstractRepository
{
/**
* @return array<Tag>
*/
public function getTags(): array
{
$qb = $this->getQueryBuilder()
->select('tags')
->from(Tag::class, 'tags')
->orderBy('tags.name', 'ASC');
return $qb->getQuery()->getResult();
}
public function getTagResource(string $slug): ?Tag
{
$qb = $this->getQueryBuilder()
->select('tags')
->from(Tag::class, 'tags')
->where('tags.slug = :slug')
->setParameter('slug', $slug);
return $qb->getQuery()->getOneOrNullResult();
}
/**
* @param array<string, mixed> $params
* @return DoctrinePaginator<Post>
*/
public function getTagPost(Tag $tag, array $params): DoctrinePaginator
{
$qb = $this->getQueryBuilder()
->select('articles')
->from(Post::class, 'articles')
->innerJoin('articles.postTags', 'postTags')
->where('postTags.tag = :tag')
->andWhere('articles.status = :published')
->setParameter('tag', $tag)
->setParameter('published', PostStatusEnum::Published)
->orderBy('articles.postDate', $params['dir'])
->setFirstResult($params['offset'])
->setMaxResults($params['limit']);
return new DoctrinePaginator($qb->getQuery());
}
}