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

CSurveyInvitationRepository   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 28
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 15
c 1
b 0
f 0
dl 0
loc 28
rs 10
wmc 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getUserPendingInvitations() 0 18 1
A __construct() 0 3 1
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