Passed
Push — master ( 76abd2...ab5d59 )
by Julito
10:01
created

TemplatesRepository::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 1
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php
2
/* For licensing terms, see /license.txt */
3
4
namespace Chamilo\CoreBundle\Repository;
5
6
use Chamilo\CoreBundle\Entity\Course;
7
use Chamilo\CoreBundle\Entity\Templates;
8
use Chamilo\UserBundle\Entity\User;
9
use Doctrine\ORM\Query\Expr\Join;
10
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
11
use Doctrine\Common\Persistence\ManagerRegistry;
12
13
/**
14
 * TemplatesRepository class.
15
 */
16
class TemplatesRepository extends ServiceEntityRepository
17
{
18
    /**
19
     * TemplatesRepository constructor.
20
     *
21
     * @param ManagerRegistry $registry
22
     */
23
    public function __construct(ManagerRegistry $registry)
24
    {
25
        parent::__construct($registry, Templates::class);
26
    }
27
28
    /**
29
     * Get the course template for a user.
30
     *
31
     * @param Course $course
32
     * @param User   $user
33
     *
34
     * @return array
35
     */
36
    public function getCourseTemplates(Course $course, User $user)
37
    {
38
        $qb = $this->createQueryBuilder('t');
39
40
        $qb->select('t', 'd.path')
41
            ->innerJoin(
42
                'ChamiloCoreBundle:Course',
43
                'c',
44
                Join::WITH,
45
                $qb->expr()->eq('t.id', 'c.id')
46
            )
47
            ->innerJoin(
48
                'ChamiloCourseBundle:CDocument',
49
                'd',
50
                Join::WITH,
51
                $qb->expr()->eq('c.id', 'd.course')
52
            )
53
            ->where(
54
                $qb->expr()->eq('d.iid', 't.refDoc')
55
            )
56
            ->andWhere(
57
                $qb->expr()->eq('c.id', $course->getId())
58
            )
59
            ->andWhere(
60
                $qb->expr()->eq('t.userId', $user->getId())
61
            );
62
63
        return $qb->getQuery()->getResult();
64
    }
65
}
66