|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Stu\Orm\Repository; |
|
4
|
|
|
|
|
5
|
|
|
use Couchbase\View; |
|
6
|
|
|
use Doctrine\ORM\EntityRepository; |
|
7
|
|
|
use Stu\Module\Control\ViewContext; |
|
8
|
|
|
use Stu\Orm\Entity\TutorialStep; |
|
9
|
|
|
use Stu\Orm\Entity\UserInterface; |
|
10
|
|
|
use Stu\Orm\Entity\UserTutorial; |
|
11
|
|
|
|
|
12
|
|
|
/** |
|
13
|
|
|
* @extends EntityRepository<TutorialStep> |
|
14
|
|
|
*/ |
|
15
|
|
|
final class TutorialStepRepository extends EntityRepository implements TutorialStepRepositoryInterface |
|
16
|
|
|
{ |
|
17
|
|
|
public function findByUserAndViewContext(UserInterface $user, ViewContext $viewContext): array |
|
18
|
|
|
{ |
|
19
|
|
|
|
|
20
|
|
|
$subquery = $this->getEntityManager()->createQuery( |
|
21
|
|
|
sprintf( |
|
22
|
|
|
'SELECT ts.id |
|
23
|
|
|
FROM %s ts |
|
24
|
|
|
JOIN %s ut WITH ts.id = ut.tutorial_step_id |
|
25
|
|
|
WHERE ut.user = :user |
|
26
|
|
|
AND ts.module = :module |
|
27
|
|
|
AND ts.view = :view', |
|
28
|
|
|
TutorialStep::class, |
|
29
|
|
|
UserTutorial::class |
|
30
|
|
|
) |
|
31
|
|
|
)->setParameters([ |
|
32
|
|
|
'user' => $user, |
|
33
|
|
|
'module' => $viewContext->getModule()->value, |
|
34
|
|
|
'view' => $viewContext->getViewIdentifier(), |
|
35
|
|
|
]); |
|
36
|
|
|
|
|
37
|
|
|
$result = $subquery->getOneOrNullResult(); |
|
38
|
|
|
|
|
39
|
|
|
if (!$result) { |
|
40
|
|
|
return []; |
|
41
|
|
|
} |
|
42
|
|
|
|
|
43
|
|
|
|
|
44
|
|
|
return $this->getEntityManager()->createQuery( |
|
45
|
|
|
sprintf( |
|
46
|
|
|
'SELECT ts FROM %s ts |
|
47
|
|
|
WHERE ts.module = :module |
|
48
|
|
|
AND ts.view = :view |
|
49
|
|
|
ORDER BY ts.sort ASC', |
|
50
|
|
|
TutorialStep::class |
|
51
|
|
|
) |
|
52
|
|
|
)->setParameters([ |
|
53
|
|
|
'module' => $viewContext->getModule()->value, |
|
54
|
|
|
'view' => $viewContext->getViewIdentifier(), |
|
55
|
|
|
])->getResult(); |
|
56
|
|
|
} |
|
57
|
|
|
|
|
58
|
|
|
public function findByViewContextAndSort(string $viewContext, int $sort): ?TutorialStep |
|
59
|
|
|
{ |
|
60
|
|
|
return $this->getEntityManager()->createQuery( |
|
61
|
|
|
sprintf('SELECT ts FROM %s ts |
|
62
|
|
|
WHERE ts.view = :view |
|
63
|
|
|
AND ts.sort = :sort', TutorialStep::class) |
|
64
|
|
|
)->setParameters([ |
|
65
|
|
|
'view' => $viewContext, |
|
66
|
|
|
'sort' => $sort |
|
67
|
|
|
])->getOneOrNullResult(); |
|
68
|
|
|
} |
|
69
|
|
|
|
|
70
|
|
|
public function findAllFirstSteps(): array |
|
71
|
|
|
{ |
|
72
|
|
|
return $this->getEntityManager() |
|
73
|
|
|
->createQuery( |
|
74
|
|
|
sprintf( |
|
75
|
|
|
'SELECT ts FROM %s ts WHERE ts.sort = :sort', |
|
76
|
|
|
TutorialStep::class |
|
77
|
|
|
) |
|
78
|
|
|
) |
|
79
|
|
|
->setParameter('sort', 1) |
|
80
|
|
|
->getResult(); |
|
81
|
|
|
} |
|
82
|
|
|
} |