Completed
Push — master ( 14d075...b15cae )
by Paweł
12s
created

LessonRepository   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 30
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 18
dl 0
loc 30
rs 10
c 0
b 0
f 0
wmc 3

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A getOneById() 0 10 1
A getByModule() 0 10 1
1
<?php
2
3
namespace App\Repository;
4
5
use App\Entity\Lesson;
6
use App\Model\LessonInterface;
7
use App\Model\ModuleInterface;
8
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
9
use Symfony\Bridge\Doctrine\RegistryInterface;
10
11
/**
12
 * @method Lesson|null find($id, $lockMode = null, $lockVersion = null)
13
 * @method Lesson|null findOneBy(array $criteria, array $orderBy = null)
14
 * @method Lesson[]    findAll()
15
 * @method Lesson[]    findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null)
16
 */
17
class LessonRepository extends ServiceEntityRepository implements LessonRepositoryInterface
18
{
19
    public function __construct(RegistryInterface $registry)
20
    {
21
        parent::__construct($registry, Lesson::class);
22
    }
23
24
    public function getOneById(string $id): ?LessonInterface
25
    {
26
        return $this->createQueryBuilder('l')
27
            ->where('l.id = :id')
28
            ->leftJoin('l.module', 'm')
29
            ->leftJoin('m.course', 'c')
30
            ->andWhere('c.visible != false')
31
            ->setParameter('id', $id)
32
            ->getQuery()
33
            ->getOneOrNullResult()
34
            ;
35
    }
36
37
    public function getByModule(ModuleInterface $module): array
38
    {
39
        return $this->createQueryBuilder('l')
40
            ->where('l.module = :module')
41
            ->leftJoin('l.module', 'm')
42
            ->leftJoin('m.course', 'c')
43
            ->andWhere('c.visible != false')
44
            ->setParameter('module', $module)
45
            ->getQuery()
46
            ->getResult()
47
            ;
48
    }
49
}
50