ModuleRepository::getAllForCourse()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 11
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 9
c 2
b 0
f 0
dl 0
loc 11
rs 9.9666
cc 1
nc 1
nop 1
1
<?php
2
3
namespace App\Repository;
4
5
use App\Entity\Module;
6
use App\Model\CourseInterface;
7
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
8
use Symfony\Bridge\Doctrine\RegistryInterface;
9
10
/**
11
 * @method Module|null find($id, $lockMode = null, $lockVersion = null)
12
 * @method Module|null findOneBy(array $criteria, array $orderBy = null)
13
 * @method Module[]    findAll()
14
 * @method Module[]    findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null)
15
 */
16
class ModuleRepository extends ServiceEntityRepository implements ModuleRepositoryInterface
17
{
18
    public function __construct(RegistryInterface $registry)
19
    {
20
        parent::__construct($registry, Module::class);
21
    }
22
23
    public function getAllForCourse(CourseInterface $course): array
24
    {
25
        return $this->createQueryBuilder('m')
26
            ->addSelect('l')
27
            ->where('m.course = :course')
28
            ->setParameter('course', $course)
29
            ->orderBy('m.position', 'ASC')
30
            ->leftJoin('m.lessons', 'l')
31
            ->addOrderBy('l.position', 'ASC')
32
            ->getQuery()
33
            ->getResult()
34
            ;
35
    }
36
}
37