1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace App\Repository; |
4
|
|
|
|
5
|
|
|
use App\Entity\UserLesson; |
6
|
|
|
use App\Model\LessonInterface; |
7
|
|
|
use App\Model\ModuleInterface; |
8
|
|
|
use App\Model\UserLessonInterface; |
9
|
|
|
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository; |
10
|
|
|
use Symfony\Bridge\Doctrine\RegistryInterface; |
11
|
|
|
use Symfony\Component\Security\Core\User\UserInterface; |
12
|
|
|
|
13
|
|
|
/** |
14
|
|
|
* @method UserLesson|null find($id, $lockMode = null, $lockVersion = null) |
15
|
|
|
* @method UserLesson|null findOneBy(array $criteria, array $orderBy = null) |
16
|
|
|
* @method UserLesson[] findAll() |
17
|
|
|
* @method UserLesson[] findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null) |
18
|
|
|
*/ |
19
|
|
|
class UserLessonRepository extends ServiceEntityRepository implements UserLessonRepositoryInterface |
20
|
|
|
{ |
21
|
|
|
public function __construct(RegistryInterface $registry) |
22
|
|
|
{ |
23
|
|
|
parent::__construct($registry, UserLesson::class); |
24
|
|
|
} |
25
|
|
|
|
26
|
|
|
public function getOneByUserAndLesson(?UserInterface $user, LessonInterface $lesson): ?UserLessonInterface |
27
|
|
|
{ |
28
|
|
|
if (null === $user) { |
29
|
|
|
return null; |
30
|
|
|
} |
31
|
|
|
|
32
|
|
|
return $this->createQueryBuilder('ul') |
33
|
|
|
->where('ul.lesson = :lesson') |
34
|
|
|
->andWhere('ul.user = :user') |
35
|
|
|
->setParameters(['user' => $user, 'lesson' => $lesson]) |
36
|
|
|
->getQuery() |
37
|
|
|
->getOneOrNullResult() |
38
|
|
|
; |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
public function getCompletedByUserAndModule(UserInterface $user, ModuleInterface $module): array |
42
|
|
|
{ |
43
|
|
|
return $this->createQueryBuilder('ul') |
44
|
|
|
->leftJoin('ul.lesson', 'l') |
45
|
|
|
->andWhere('ul.user = :user') |
46
|
|
|
->andWhere('l.module = :module') |
47
|
|
|
->andWhere('ul.completed = true') |
48
|
|
|
->setParameters(['user' => $user, 'module' => $module]) |
49
|
|
|
->getQuery() |
50
|
|
|
->getResult() |
51
|
|
|
; |
52
|
|
|
} |
53
|
|
|
} |
54
|
|
|
|