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
|
|
|
|