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