|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace Stu\Orm\Repository; |
|
6
|
|
|
|
|
7
|
|
|
use Doctrine\ORM\EntityRepository; |
|
8
|
|
|
use Stu\Module\Control\ViewContext; |
|
9
|
|
|
use Stu\Orm\Entity\TutorialStep; |
|
10
|
|
|
use Stu\Orm\Entity\UserTutorial; |
|
11
|
|
|
use Stu\Orm\Entity\UserTutorialInterface; |
|
12
|
|
|
use Stu\Orm\Entity\UserInterface; |
|
13
|
|
|
|
|
14
|
|
|
/** |
|
15
|
|
|
* @extends EntityRepository<UserTutorial> |
|
16
|
|
|
*/ |
|
17
|
|
|
final class UserTutorialRepository extends EntityRepository implements UserTutorialRepositoryInterface |
|
18
|
|
|
{ |
|
19
|
|
|
public function prototype(): UserTutorialInterface |
|
20
|
|
|
{ |
|
21
|
|
|
return new UserTutorial(); |
|
22
|
|
|
} |
|
23
|
|
|
|
|
24
|
|
|
public function save(UserTutorialInterface $userTutorial): void |
|
25
|
|
|
{ |
|
26
|
|
|
$em = $this->getEntityManager(); |
|
27
|
|
|
$em->persist($userTutorial); |
|
28
|
|
|
$em->flush(); |
|
29
|
|
|
} |
|
30
|
|
|
|
|
31
|
|
|
public function delete(UserTutorialInterface $userTutorial): void |
|
32
|
|
|
{ |
|
33
|
|
|
$em = $this->getEntityManager(); |
|
34
|
|
|
$em->remove($userTutorial); |
|
35
|
|
|
$em->flush(); |
|
36
|
|
|
} |
|
37
|
|
|
|
|
38
|
|
|
public function truncateByUser(UserInterface $user): void |
|
39
|
|
|
{ |
|
40
|
|
|
$this->getEntityManager() |
|
41
|
|
|
->createQuery( |
|
42
|
|
|
sprintf( |
|
43
|
|
|
'DELETE FROM %s ut WHERE ut.user = :user', |
|
44
|
|
|
UserTutorial::class |
|
45
|
|
|
) |
|
46
|
|
|
) |
|
47
|
|
|
->setParameters([ |
|
48
|
|
|
'user' => $user |
|
49
|
|
|
]) |
|
50
|
|
|
->execute(); |
|
51
|
|
|
} |
|
52
|
|
|
|
|
53
|
|
|
public function findByUserAndViewContext(UserInterface $user, ViewContext $viewContext): ?UserTutorial |
|
54
|
|
|
{ |
|
55
|
|
|
return $this->getEntityManager()->createQuery( |
|
56
|
|
|
sprintf( |
|
57
|
|
|
'SELECT ut FROM %s ut |
|
58
|
|
|
JOIN %s ts |
|
59
|
|
|
WITH ts.id = ut.tutorial_step_id |
|
60
|
|
|
WHERE ut.user = :user |
|
61
|
|
|
AND ts.module = :module |
|
62
|
|
|
AND ts.view = :view', |
|
63
|
|
|
UserTutorial::class, |
|
64
|
|
|
TutorialStep::class |
|
65
|
|
|
) |
|
66
|
|
|
)->setParameters([ |
|
67
|
|
|
'user' => $user, |
|
68
|
|
|
'module' => $viewContext->getModule()->value, |
|
69
|
|
|
'view' => $viewContext->getViewIdentifier(), |
|
70
|
|
|
])->getOneOrNullResult(); |
|
71
|
|
|
} |
|
72
|
|
|
} |
|
73
|
|
|
|