zend-blog-3-backend
40 строк · 963.0 Байт
1<?php
2
3namespace App\Repository;
4
5use App\Entity\Post;
6use App\Entity\ViewComment;
7use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
8use Doctrine\Persistence\ManagerRegistry;
9
10class ViewCommentRepository extends ServiceEntityRepository
11{
12use ListQueryTrait;
13
14/**
15* @param ManagerRegistry $registry
16*/
17public function __construct(ManagerRegistry $registry)
18{
19parent::__construct($registry, ViewComment::class);
20}
21
22/**
23* @param Post $post
24*
25* @return ViewComment[]
26*/
27public function getCommentsByPost(Post $post): array
28{
29$qb = $this->createQueryBuilder('c');
30
31$qb
32->where($qb->expr()->eq('c.post', ':post'))
33->andWhere($qb->expr()->eq('c.deleted', $qb->expr()->literal(false)))
34->setParameter('post', $post->getId())
35->orderBy('c.timeCreated')
36;
37
38return $qb->getQuery()->getResult();
39}
40}
41