Passed
Push — master ( 414a0d...d40d17 )
by Julito
08:35
created

CSurveyInvitationRepository::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 3
rs 10
1
<?php
2
3
declare(strict_types=1);
4
5
/* For licensing terms, see /license.txt */
6
7
namespace Chamilo\CourseBundle\Repository;
8
9
use Chamilo\CoreBundle\Entity\User;
10
use Chamilo\CoreBundle\Repository\ResourceRepository;
11
use Chamilo\CourseBundle\Entity\CSurveyInvitation;
12
use Datetime;
13
use Doctrine\Common\Collections\Criteria;
14
use Doctrine\Persistence\ManagerRegistry;
15
16
final class CSurveyInvitationRepository extends ResourceRepository
17
{
18
    public function __construct(ManagerRegistry $registry)
19
    {
20
        parent::__construct($registry, CSurveyInvitation::class);
21
    }
22
23
    /**
24
     * @return CSurveyInvitation[]
25
     */
26
    public function getUserPendingInvitations(User $user)
27
    {
28
        $qb = $this->createQueryBuilder('i');
29
        $qb
30
            ->select('i')
31
            ->innerJoin('i.user', 'u')
32
            ->innerJoin('i.survey', 's')
33
            ->andWhere('i.user = :u')
34
            ->andWhere('s.availFrom <= :now AND s.availTill >= :now')
35
            ->andWhere('s.answered = 0')
36
            ->setParameters([
37
                'now' => new Datetime(),
38
                'u' => $user,
39
            ])
40
            ->orderBy('s.availTill', Criteria::ASC)
41
        ;
42
43
        return $qb->getQuery()->getResult();
44
    }
45
}
46