1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace App\Repository; |
4
|
|
|
|
5
|
|
|
use App\Entity\Comment; |
6
|
|
|
use App\Pagination\PaginateRepositoryTrait; |
7
|
|
|
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository; |
8
|
|
|
use Doctrine\ORM\Tools\Pagination\Paginator; |
9
|
|
|
use InvalidArgumentException; |
10
|
|
|
use Symfony\Bridge\Doctrine\RegistryInterface; |
11
|
|
|
|
12
|
|
|
/** |
13
|
|
|
* @method Comment|null find($id, $lockMode = null, $lockVersion = null) |
14
|
|
|
* @method Comment|null findOneBy(array $criteria, array $orderBy = null) |
15
|
|
|
* @method Comment[] findAll() |
16
|
|
|
* @method Comment[] findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null) |
17
|
|
|
*/ |
18
|
|
|
class CommentRepository extends ServiceEntityRepository |
19
|
|
|
{ |
20
|
|
|
use PaginateRepositoryTrait; |
21
|
|
|
|
22
|
|
|
public function __construct(RegistryInterface $registry) |
23
|
|
|
{ |
24
|
|
|
parent::__construct($registry, Comment::class); |
25
|
|
|
} |
26
|
|
|
|
27
|
|
|
public function findLatestEdited(int $trickId, int $currentPage = 1) |
28
|
|
|
{ |
29
|
|
|
if ($currentPage < 1) { |
30
|
|
|
throw new InvalidArgumentException("Current page can not be lower than one"); |
31
|
|
|
} |
32
|
|
|
|
33
|
|
|
$query = $this->createQueryBuilder('c') |
34
|
|
|
->where('c.trick = :trickId') |
35
|
|
|
->setParameter('trickId', $trickId) |
36
|
|
|
->orderBy('c.createdAt', 'DESC') |
37
|
|
|
->getQuery(); |
38
|
|
|
|
39
|
|
|
$paginator = $this->paginate($query,Comment::NUMBER_OF_DISPLAYED_COMMENTS, $currentPage); |
40
|
|
|
|
41
|
|
|
return $paginator; |
42
|
|
|
} |
43
|
|
|
} |
44
|
|
|
|