|
@@ -9,36 +9,40 @@ use Logipro\Phoenix\Entity\SequenceItem\ActivityPackage;
|
9
|
9
|
use Logipro\Phoenix\Entity\SequenceItem\SequenceItem;
|
10
|
10
|
use Logipro\Phoenix\Exception\PhoenixException;
|
11
|
11
|
use Logipro\Phoenix\Package\Common\AbstractPackageFile;
|
12
|
|
-use Symfony\Component\DependencyInjection\ContainerAwareInterface;
|
13
|
|
-use Symfony\Component\DependencyInjection\ContainerAwareTrait;
|
14
|
|
-use Symfony\Component\DependencyInjection\ContainerInterface;
|
15
|
12
|
use Logipro\Phoenix\Entity\Session\Session;
|
16
|
13
|
use Symfony\Component\Security\Core\Security;
|
17
|
14
|
use Logipro\Phoenix\Entity\ProgramItem;
|
18
|
15
|
use Doctrine\Common\Collections\ArrayCollection;
|
|
16
|
+use Logipro\Bundle\SCORMBundle\Services\ScormEngine;
|
|
17
|
+use Symfony\Component\Translation\TranslatorInterface;
|
|
18
|
+use Doctrine\ORM\EntityManagerInterface;
|
19
|
19
|
|
20
|
20
|
/**
|
21
|
21
|
* Service de duplication des entités.
|
22
|
22
|
*/
|
23
|
|
-class EntityDuplicator implements ContainerAwareInterface
|
|
23
|
+class EntityDuplicator
|
24
|
24
|
{
|
25
|
|
- use ContainerAwareTrait;
|
26
|
|
-
|
27
|
25
|
private $security;
|
28
|
26
|
private $fileUploader;
|
|
27
|
+ private $entityManager;
|
|
28
|
+ private $translator;
|
|
29
|
+ private $scormEngine;
|
29
|
30
|
|
30
|
31
|
/**
|
31
|
32
|
* Constructeur.
|
32
|
|
- * @param ContainerInterface $container
|
33
|
33
|
*/
|
34
|
34
|
public function __construct(
|
35
|
|
- ContainerInterface $container,
|
36
|
35
|
Security $security,
|
37
|
|
- FileUploader $fileUploader
|
|
36
|
+ FileUploader $fileUploader,
|
|
37
|
+ EntityManagerInterface $entityManager,
|
|
38
|
+ TranslatorInterface $translator,
|
|
39
|
+ ScormEngine $scormEngine
|
38
|
40
|
) {
|
39
|
|
- $this->setContainer($container);
|
40
|
41
|
$this->security = $security;
|
41
|
42
|
$this->fileUploader = $fileUploader;
|
|
43
|
+ $this->entityManager = $entityManager;
|
|
44
|
+ $this->translator = $translator;
|
|
45
|
+ $this->scormEngine = $scormEngine;
|
42
|
46
|
}
|
43
|
47
|
|
44
|
48
|
/**
|
|
@@ -49,29 +53,7 @@ class EntityDuplicator implements ContainerAwareInterface
|
49
|
53
|
*/
|
50
|
54
|
public function duplicateLearningPath(LearningPath $learningPath, Session $session = null, bool $isTemplate = false): LearningPath
|
51
|
55
|
{
|
52
|
|
- $em = $this->getDoctrine()->getManager();
|
53
|
|
-
|
54
|
|
- $newLearningPath = null;
|
55
|
|
-
|
56
|
|
- // Si c'est une duplication de template
|
57
|
|
- if ($isTemplate) {
|
58
|
|
- $title = '[copie] ' . $learningPath->getTitle();
|
59
|
|
- $newLearningPath = $this->cloneLearningPath($learningPath, true);
|
60
|
|
- $newLearningPath->setTitle($title);
|
61
|
|
- } else {
|
62
|
|
- $newLearningPath = $this->cloneLearningPath($learningPath);
|
63
|
|
- }
|
64
|
|
-
|
65
|
|
- $autor = $this->security->getUser();
|
66
|
|
- $newLearningPath->setCreatingUser($autor);
|
67
|
|
-
|
68
|
|
- if ($session) {
|
69
|
|
- $newLearningPath->setSession($session);
|
70
|
|
- $session->setLearningPath($newLearningPath);
|
71
|
|
- }
|
72
|
|
-
|
73
|
|
- $em->persist($newLearningPath);
|
74
|
|
- $em->flush();
|
|
56
|
+ $newLearningPath = $this->cloneLearningPath($learningPath, $session, $isTemplate);
|
75
|
57
|
|
76
|
58
|
// Duplication des cours au niveau du moteur SCORM
|
77
|
59
|
$this->duplicateScormCoursesFromPaths($learningPath, $newLearningPath);
|
|
@@ -79,7 +61,7 @@ class EntityDuplicator implements ContainerAwareInterface
|
79
|
61
|
return $newLearningPath;
|
80
|
62
|
}
|
81
|
63
|
|
82
|
|
- private function cloneLearningPath(LearningPath $learningPath, bool $isTemplate = false): LearningPath
|
|
64
|
+ protected function cloneLearningPath(LearningPath $learningPath, Session $session = null, bool $isTemplate = false): LearningPath
|
83
|
65
|
{
|
84
|
66
|
//FIXME Peut-on copier un parcours qui n'est pas un gabarit ?
|
85
|
67
|
if (!$learningPath->isTemplate()) {
|
|
@@ -89,6 +71,9 @@ class EntityDuplicator implements ContainerAwareInterface
|
89
|
71
|
// Clonage du parcours (et de ses éléments enfants en cascade)
|
90
|
72
|
$pathCopy = clone $learningPath;
|
91
|
73
|
|
|
74
|
+ $autor = $this->security->getUser();
|
|
75
|
+ $pathCopy->setCreatingUser($autor);
|
|
76
|
+
|
92
|
77
|
// Copie les séquences
|
93
|
78
|
$sequences = new ArrayCollection();
|
94
|
79
|
foreach ($learningPath->getSequences() as $sequence) {
|
|
@@ -112,10 +97,22 @@ class EntityDuplicator implements ContainerAwareInterface
|
112
|
97
|
$pathCopy->setTemplate($learningPath);
|
113
|
98
|
$pathCopy->setIsTemplate($isTemplate);
|
114
|
99
|
|
|
100
|
+ if ($isTemplate) {
|
|
101
|
+ $pathCopy->setTitle('[copie] ' . $learningPath->getTitle());
|
|
102
|
+ }
|
|
103
|
+
|
|
104
|
+ if ($session) {
|
|
105
|
+ $pathCopy->setSession($session);
|
|
106
|
+ $session->setLearningPath($pathCopy);
|
|
107
|
+ }
|
|
108
|
+
|
|
109
|
+ $this->entityManager->persist($pathCopy);
|
|
110
|
+ $this->entityManager->flush();
|
|
111
|
+
|
115
|
112
|
return $pathCopy;
|
116
|
113
|
}
|
117
|
114
|
|
118
|
|
- private function cloneSequence(Sequence $sequence): Sequence
|
|
115
|
+ protected function cloneSequence(Sequence $sequence): Sequence
|
119
|
116
|
{
|
120
|
117
|
$sequenceCopy = clone $sequence;
|
121
|
118
|
// Copie les éléments
|
|
@@ -144,13 +141,13 @@ class EntityDuplicator implements ContainerAwareInterface
|
144
|
141
|
return $sequenceCopy;
|
145
|
142
|
}
|
146
|
143
|
|
147
|
|
- private function cloneProgramItem(ProgramItem $programItem): ProgramItem
|
|
144
|
+ protected function cloneProgramItem(ProgramItem $programItem): ProgramItem
|
148
|
145
|
{
|
149
|
146
|
// FIXME à corriger
|
150
|
147
|
return clone $programItem;
|
151
|
148
|
}
|
152
|
149
|
|
153
|
|
- private function cloneSequenceItem(SequenceItem $sequenceItem): SequenceItem
|
|
150
|
+ protected function cloneSequenceItem(SequenceItem $sequenceItem): SequenceItem
|
154
|
151
|
{
|
155
|
152
|
// FIXME à corriger
|
156
|
153
|
return clone $sequenceItem;
|
|
@@ -168,14 +165,13 @@ class EntityDuplicator implements ContainerAwareInterface
|
168
|
165
|
{
|
169
|
166
|
// Vérification de l'existance des parcours
|
170
|
167
|
if (empty($originalPath) || empty($newPath)) {
|
171
|
|
- throw new PhoenixException($this->container->get('translator')->trans('exception_duplicator_no_learning_path'));
|
|
168
|
+ throw new PhoenixException($this->translator->trans('exception_duplicator_no_learning_path'));
|
172
|
169
|
}
|
173
|
170
|
|
174
|
|
- $em = $this->getDoctrine()->getManager();
|
175
|
|
- $sequenceRepository = $em->getRepository(Sequence::class);
|
|
171
|
+ $sequenceRepository = $this->entityManager->getRepository(Sequence::class);
|
176
|
172
|
|
177
|
173
|
// Récupération du service ScormEngine
|
178
|
|
- $scormEngine = $this->container->get('scorm.services.engine');
|
|
174
|
+ $scormEngine = $this->scormEngine;
|
179
|
175
|
|
180
|
176
|
// On récupère les séquences par repository avec classement croissant des id
|
181
|
177
|
$originalSequences = $sequenceRepository->findBy(array('learningPath' => $originalPath), array('sequenceId' => 'asc'));
|
|
@@ -183,7 +179,7 @@ class EntityDuplicator implements ContainerAwareInterface
|
183
|
179
|
|
184
|
180
|
// Vérification de l'existance des séquences
|
185
|
181
|
if (empty($originalSequences) || empty($newSequences)) {
|
186
|
|
- throw new PhoenixException($this->container->get('translator')->trans('exception_duplicator_no_sequences'));
|
|
182
|
+ throw new PhoenixException($this->translator->trans('exception_duplicator_no_sequences'));
|
187
|
183
|
}
|
188
|
184
|
|
189
|
185
|
// Pour chaque Sequence
|
|
@@ -197,7 +193,7 @@ class EntityDuplicator implements ContainerAwareInterface
|
197
|
193
|
|
198
|
194
|
// Vérification de l'existance des items
|
199
|
195
|
if (empty($originalItems) || empty($newItems)) {
|
200
|
|
- throw new PhoenixException($this->container->get('translator')->trans('exception_duplicator_no_items'));
|
|
196
|
+ throw new PhoenixException($this->translator->trans('exception_duplicator_no_items'));
|
201
|
197
|
}
|
202
|
198
|
|
203
|
199
|
// Pour chaque item
|
|
@@ -208,24 +204,10 @@ class EntityDuplicator implements ContainerAwareInterface
|
208
|
204
|
$new = $newItems[$j];
|
209
|
205
|
$response = $scormEngine->duplicateCourse($original->getSequenceItemId(), $new->getSequenceItemId());
|
210
|
206
|
if (400 == $response['code']) {
|
211
|
|
- throw new PhoenixException($this->container->get('translator')->trans('exception_duplicator_engine_course'));
|
|
207
|
+ throw new PhoenixException($this->translator->trans('exception_duplicator_engine_course'));
|
212
|
208
|
}
|
213
|
209
|
}
|
214
|
210
|
}
|
215
|
211
|
}
|
216
|
212
|
}
|
217
|
|
-
|
218
|
|
- /**
|
219
|
|
- *
|
220
|
|
- * @throws \LogicException
|
221
|
|
- * @return ManagerRegistry
|
222
|
|
- */
|
223
|
|
- protected function getDoctrine(): ManagerRegistry
|
224
|
|
- {
|
225
|
|
- if (!$this->container->has('doctrine')) {
|
226
|
|
- throw new \LogicException('The DoctrineBundle is not registered in your application. Try running "composer require symfony/orm-pack".');
|
227
|
|
- }
|
228
|
|
-
|
229
|
|
- return $this->container->get('doctrine');
|
230
|
|
- }
|
231
|
213
|
}
|