Browse Source

Retrait de l'utilisation du container dans le code

Mael ETIENNE 2 years ago
parent
commit
1804e4b217

+ 23
- 35
ClientAPI/ApiScorm2004.php View File

@@ -19,24 +19,27 @@ use Logipro\Bundle\SCORMBundle\Entity\Scorm2004\Scorm2004ObjectiveProgressInform
19 19
 use Logipro\Bundle\SCORMBundle\LearningModels\DOMSCORM2004;
20 20
 use Logipro\Bundle\SCORMBundle\Tools\TimeTools;
21 21
 use Logipro\Bundle\SCORMBundle\Tools\UnicodeTools;
22
-use Symfony\Component\DependencyInjection\ContainerInterface;
23
-use Symfony\Component\DependencyInjection\ContainerAwareTrait;
24
-use Symfony\Component\DependencyInjection\ContainerAwareInterface;
22
+use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface;
25 23
 use Symfony\Component\Routing\Generator\UrlGenerator;
24
+use Symfony\Component\Routing\RouterInterface;
26 25
 
27
-class ApiScorm2004 implements ContainerAwareInterface
26
+class ApiScorm2004
28 27
 {
29
-    use ContainerAwareTrait;
28
+    protected $router;
30 29
 
31
-    public function __construct(ContainerInterface $container)
30
+    protected $parameters;
31
+
32
+    protected $em;
33
+    
34
+    public function __construct(RouterInterface $router, ParameterBagInterface $parameters, EntityManagerInterface $em)
32 35
     {
33
-        $this->setContainer($container);
36
+        $this->router = $router;
37
+        $this->parameters = $parameters;
38
+        $this->em = $em;
34 39
     }
35 40
 
36 41
     public function getAPI(DOMSCORM2004 $dom, string $registrationKey, string $organization, string $item)
37 42
     {
38
-        $em = $this->getDoctrine()->getManager();
39
-
40 43
         $debugMode = true;
41 44
 
42 45
         // DATA
@@ -55,7 +58,7 @@ class ApiScorm2004 implements ContainerAwareInterface
55 58
         }
56 59
 
57 60
         // ESSAI
58
-        $registrationAttemptRepository = $em->getRepository(RegistrationAttempt::class);
61
+        $registrationAttemptRepository = $this->em->getRepository(RegistrationAttempt::class);
59 62
         $registrationAttempt = $registrationAttemptRepository->findOneBy(array('registration' => $registration), array('registrationAttemptId' => 'desc'));
60 63
         if (!$registrationAttempt) {
61 64
             return;
@@ -69,18 +72,18 @@ class ApiScorm2004 implements ContainerAwareInterface
69 72
         $learnerId = $learner->getLearnerId();
70 73
 
71 74
         // TRACK
72
-        $trackRepository = $em->getRepository(Scorm2004Track:: class);
75
+        $trackRepository = $this->em->getRepository(Scorm2004Track:: class);
73 76
         $track = $trackRepository->findOneBy(array('organizationId' => $organization, 'registrationAttempt' => $registrationAttempt));
74 77
         if (!$track) {
75 78
             return;
76 79
         }
77 80
 
78 81
         // MAP ITEM/TRACK
79
-        $mapTrackItemRepository = $em->getRepository(Scorm2004MapTrackItem:: class);
82
+        $mapTrackItemRepository = $this->em->getRepository(Scorm2004MapTrackItem:: class);
80 83
         $mapTrackItem = $mapTrackItemRepository->findOneBy(array('scorm2004Track' => $track, 'item_identifier' => $item));
81 84
 
82 85
         // Progress Information
83
-        $attemptInfoRepository = $em->getRepository(Scorm2004AttemptProgressInformation:: class);
86
+        $attemptInfoRepository = $this->em->getRepository(Scorm2004AttemptProgressInformation:: class);
84 87
         $attemptProgressInfo = $attemptInfoRepository->findOneBy(array('scorm2004Track' => $track, 'item_identifier' => $item), array('attempt_id' => 'desc'));
85 88
 
86 89
         //Nom de l'apprenant
@@ -177,7 +180,7 @@ class ApiScorm2004 implements ContainerAwareInterface
177 180
         //============================ Scaled Score : cmi.score.scaled  ==================================================//
178 181
         // Le sco est responsable de determiner le scaled score.
179 182
         // le mappage pour le score.scaled est fait avec measure_status et normalized_measure.
180
-        $objectiveInfoRepository = $em->getRepository(Scorm2004ObjectiveProgressInformation::class);
183
+        $objectiveInfoRepository = $this->em->getRepository(Scorm2004ObjectiveProgressInformation::class);
181 184
         $primaryInfo = null;
182 185
         if (!empty($primaryObjective)) {
183 186
             $primaryInfo = $objectiveInfoRepository->findLocalInfoByObjectiveAndAttempt($primaryObjective, $attemptProgressInfo, $track, true, $dom);
@@ -276,7 +279,7 @@ class ApiScorm2004 implements ContainerAwareInterface
276 279
         //                 RECUPERATION DES INTERACTION + OBJECTIFS DES INTERACTION                        //
277 280
         //=================================================================================================//
278 281
         // on recupère les interactions.
279
-        $interactionRepository = $em->getRepository(Scorm2004Interaction::class);
282
+        $interactionRepository = $this->em->getRepository(Scorm2004Interaction::class);
280 283
         $interactions = $interactionRepository->findBy(array('scorm2004Track' => $track, 'scorm2004AttemptProgressInformation' => $attemptProgressInfo));
281 284
 
282 285
         $interactionList = array(); // TABLE QUI VA CONTENIR TOUTES LES INTERACTIONS
@@ -439,7 +442,7 @@ class ApiScorm2004 implements ContainerAwareInterface
439 442
         // On recupère les données de data Map.
440 443
         $arrayDataMap = array();
441 444
         $dataMaps = $dom->getDataMap($item);
442
-        $noteRepository = $em->getRepository(Scorm2004Note::class);
445
+        $noteRepository = $this->em->getRepository(Scorm2004Note::class);
443 446
 
444 447
         if (!empty($dataMaps)) {
445 448
             foreach ($dataMaps as $dataMap) {
@@ -475,7 +478,7 @@ class ApiScorm2004 implements ContainerAwareInterface
475 478
         //=================================================================================================//
476 479
         //                  RECUPERATION DES COMMENTAIRES (comments_from_learner).                         //
477 480
         //=================================================================================================//
478
-        $commentRepository = $em->getRepository(Scorm2004Comment::class);
481
+        $commentRepository = $this->em->getRepository(Scorm2004Comment::class);
479 482
         $learnerComments = $commentRepository->findBy(array('scorm2004Track' => $track, 'resourceIdentifier' => $item, 'learner' => $learner));
480 483
 
481 484
         $arrayLearnerComments = array();
@@ -517,7 +520,7 @@ class ApiScorm2004 implements ContainerAwareInterface
517 520
         //================================================//
518 521
 // DEFINIR COMMENT ON FAIT LES COMMITS
519 522
         
520
-        $url = $this->container->get('router')->generate('logipro_scorm_2004_commit', [], UrlGenerator::ABSOLUTE_URL);
523
+        $url = $this->router->generate('logipro_scorm_2004_commit', [], UrlGenerator::ABSOLUTE_URL);
521 524
         $ajaxURL = $this->jsEscape($url);
522 525
 
523 526
         //=================================================================================================//
@@ -533,7 +536,7 @@ EOT;
533 536
         $apiString .= $cmiStructure;
534 537
         $apiString .= $scorm2004;
535 538
 
536
-        $ajaxCallbackPath = $this->container->getParameter('logipro_scorm.ajax_callback');
539
+        $ajaxCallbackPath = $this->parameters->get('logipro_scorm.ajax_callback');
537 540
         $ajaxCallback = file_get_contents($ajaxCallbackPath);
538 541
         if (!empty($ajaxCallback)) {
539 542
             $apiString .= $ajaxCallback;
@@ -880,25 +883,10 @@ EOT;
880 883
      */
881 884
     protected function requireRegistration(string $registrationKey)
882 885
     {
883
-        $em = $this->getDoctrine()->getManager();
884
-        $repository = $em->getRepository(Registration::class);
886
+        $repository = $this->em->getRepository(Registration::class);
885 887
 
886 888
         $registration = $repository->findOneBy(array('registrationKey' => $registrationKey));
887 889
 
888 890
         return $registration;
889 891
     }
890
-
891
-    /**
892
-     *
893
-     * @throws \LogicException
894
-     * @return ManagerRegistry
895
-     */
896
-    protected function getDoctrine(): ManagerRegistry
897
-    {
898
-        if (!$this->container->has('doctrine')) {
899
-            throw new \LogicException('The DoctrineBundle is not registered in your application. Try running "composer require symfony/orm-pack".');
900
-        }
901
-
902
-        return $this->container->get('doctrine');
903
-    }
904 892
 }

+ 0
- 14
Controller/ExampleController.php View File

@@ -1,14 +0,0 @@
1
-<?php
2
-
3
-namespace Logipro\Bundle\SCORMBundle\ExampleBundle\Controller;
4
-
5
-use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
6
-
7
-class ExampleController extends AbstractController
8
-{
9
-    public function view()
10
-    {
11
-        //return $this->render('@LogiproExample/Example/example.html.twig');
12
-        return Response('coucou');
13
-    }
14
-}

+ 1
- 1
Controller/Track2004Controller.php View File

@@ -370,7 +370,7 @@ class Track2004Controller extends AbstractController
370 370
         // Récupération des modifications du lecteur pour la réponse ajax
371 371
         $packageFolder = $this->container->getParameter('logipro_scorm.package_folder');
372 372
         $dom = $registrationAttempt->getDOM($packageFolder);
373
-        $playerView = new Scorm2004PlayerView($this->container, $dom, $track, $registrationKey, $organization, $item);
373
+        $playerView = new Scorm2004PlayerView($dom, $track, $registrationKey, $organization, $item);
374 374
         $response = $playerView->getNavResponse();
375 375
 
376 376
         return $this->json($response);

+ 3
- 5
DependencyInjection/LogiproSCORMExtension.php View File

@@ -17,16 +17,14 @@ class LogiproSCORMExtension extends Extension
17 17
         $configuration = new Configuration();
18 18
         $config = $this->processConfiguration($configuration, $configs);
19 19
 
20
+        // Définition des paramètres spécifiques au bundle
21
+        // Les params sont récupérés dans le fichier de config de l'appli cliente
20 22
         $container->setParameter('logipro_scorm.package_folder', $config['package_folder']);
21 23
         $container->setParameter('logipro_scorm.content_folder', $config['content_folder']);
22 24
         $container->setParameter('logipro_scorm.content_url_prefix', $config['content_url_prefix']);
23 25
         $container->setParameter('logipro_scorm.ajax_callback', $config['ajax_callback']);
24 26
 
25
-        $definition = $container->getDefinition('Logipro\Bundle\SCORMBundle\Services\ScormEngine');
26
-        $definition->replaceArgument(0, $config['package_folder']);
27
-        $definition->replaceArgument(1, $config['content_folder']);
28
-        $definition->replaceArgument(2, $config['content_url_prefix']);
29
-
27
+        // Définition dynamique de l'argument du service à partir du param
30 28
         $managerDefinition = $container->getDefinition('Logipro\Bundle\SCORMBundle\Services\Scorm2004ObjectiveProgressInfoManager');
31 29
         $managerDefinition->replaceArgument(1, $config['package_folder']);
32 30
     }

+ 15
- 15
LearningModels/SCORM2004/SequencingNavigation/DeliveryRequest.php View File

@@ -2,11 +2,12 @@
2 2
 
3 3
 namespace Logipro\Bundle\SCORMBundle\LearningModels\SCORM2004\SequencingNavigation;
4 4
 
5
+use Doctrine\ORM\EntityManagerInterface;
5 6
 use Logipro\Bundle\SCORMBundle\Entity\Scorm2004\Scorm2004MapTrackItem;
6 7
 use Logipro\Bundle\SCORMBundle\Entity\Scorm2004\Scorm2004AttemptProgressInformation;
7 8
 use Logipro\Bundle\SCORMBundle\Entity\Scorm2004\Scorm2004ObjectiveProgressInformation;
8 9
 use Logipro\Bundle\SCORMBundle\LearningModels\SCORM2004\SequencingNavigation\SeqNavRequest;
9
-use Symfony\Component\DependencyInjection\ContainerInterface;
10
+use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface;
10 11
 
11 12
 class DeliveryRequest extends SeqNavRequest
12 13
 {
@@ -20,13 +21,14 @@ class DeliveryRequest extends SeqNavRequest
20 21
     /**
21 22
      * Constructeur
22 23
      *
23
-     * @param ContainerInterface $container
24
+     * @param ParameterBagInterface $parameters : Service
25
+     * @param EntityManagerInterface $em : Service
24 26
      * @param string $deliveryItem
25 27
      * @param string $registrationId
26 28
      */
27
-    public function __construct(ContainerInterface $container, string $deliveryItem, string $registrationId)
29
+    public function __construct(ParameterBagInterface $parameters, EntityManagerInterface $em, string $deliveryItem, string $registrationId)
28 30
     {
29
-        parent::__construct($container, '', $registrationId, '');
31
+        parent::__construct($parameters, $em, '', $registrationId, '');
30 32
         // Initialisation des variables de l'instance
31 33
         $this->deliveryItem = $deliveryItem;
32 34
         $this->checkDeliveryItem();
@@ -72,8 +74,7 @@ class DeliveryRequest extends SeqNavRequest
72 74
      */
73 75
     public function processDelivery(): void
74 76
     {
75
-        $em = $this->getDoctrine()->getManager();
76
-        $scorm2004MapTrackItemRepository = $em->getRepository(Scorm2004MapTrackItem::class);
77
+        $scorm2004MapTrackItemRepository = $this->em->getRepository(Scorm2004MapTrackItem::class);
77 78
         
78 79
         // Vérifier qu'un item ne soit pas déjà actif
79 80
         $mapTrackCurrentItem = $scorm2004MapTrackItemRepository->findOneBy(array('item_identifier' => $this->currentItem, 'scorm2004Track' => $this->scorm2004Track));
@@ -125,7 +126,7 @@ class DeliveryRequest extends SeqNavRequest
125 126
                         $attemptProgress->setScorm2004Track($this->scorm2004Track);
126 127
                         $attemptProgress->setItemIdentifier($item);
127 128
                         
128
-                        $em->persist($attemptProgress);
129
+                        $this->em->persist($attemptProgress);
129 130
 
130 131
                     // COMPORTEMENT HORS NORME
131 132
                         // Dans le cas d'un nouvel essais, on RAZ certains attributs relatif au item et au track
@@ -145,7 +146,7 @@ class DeliveryRequest extends SeqNavRequest
145 146
                             $objectiveProgress->setScorm2004Track($this->scorm2004Track);
146 147
                             
147 148
                             // Mise à jours des informations de l'objectif
148
-                            $em->persist($objectiveProgress);
149
+                            $this->em->persist($objectiveProgress);
149 150
                         }
150 151
                     }
151 152
                 }
@@ -153,10 +154,10 @@ class DeliveryRequest extends SeqNavRequest
153 154
                 // activation de l'item
154 155
                 $mapTrackItem->setIsActive(true);
155 156
             }
156
-            $em->persist($mapTrackItem);
157
+            $this->em->persist($mapTrackItem);
157 158
         }
158 159
         //die();
159
-        $em->flush();
160
+        $this->em->flush();
160 161
 
161 162
         $this->currentItem = $this->deliveryItem;
162 163
         $this->suspendedItem = null;
@@ -180,8 +181,7 @@ class DeliveryRequest extends SeqNavRequest
180 181
      */
181 182
     protected function clearSuspendedItem($identifiedItem)
182 183
     {
183
-        $em = $this->getDoctrine()->getManager();
184
-        $scorm2004MapTrackItemRepository = $em->getRepository(Scorm2004MapTrackItem::class);
184
+        $scorm2004MapTrackItemRepository = $this->em->getRepository(Scorm2004MapTrackItem::class);
185 185
         
186 186
         if ($this->suspendedItem) {
187 187
             $commonItem = $this->domScorm2004->findCommonAncestor($identifiedItem, $this->suspendedItem);
@@ -196,7 +196,7 @@ class DeliveryRequest extends SeqNavRequest
196 196
                     // Si l'item est terminal (n'a pas d'enfant) on annule sa suspension
197 197
                     if (empty($children)) {
198 198
                         $mapTrackItem->setIsSuspended(false);
199
-                        $em->persist($mapTrackItem);
199
+                        $this->em->persist($mapTrackItem);
200 200
                     } else {
201 201
                         // Si l'item ne possède aucun enfant suspendu, on annule sa suspension
202 202
                         $suspension = false;
@@ -211,13 +211,13 @@ class DeliveryRequest extends SeqNavRequest
211 211
 
212 212
                         if (!$suspension) {
213 213
                             $mapTrackItem->setIsSuspended(false);
214
-                            $em->persist($mapTrackItem);
214
+                            $this->em->persist($mapTrackItem);
215 215
                         }
216 216
                     }
217 217
                 }
218 218
             }
219 219
 
220
-            $em->flush();
220
+            $this->em->flush();
221 221
 
222 222
             $this->suspendedItem = null;
223 223
             $this->updateTrack2004();

+ 10
- 14
LearningModels/SCORM2004/SequencingNavigation/NavigationRequest.php View File

@@ -2,11 +2,12 @@
2 2
 
3 3
 namespace Logipro\Bundle\SCORMBundle\LearningModels\SCORM2004\SequencingNavigation;
4 4
 
5
+use Doctrine\ORM\EntityManagerInterface;
5 6
 use Logipro\Bundle\SCORMBundle\Entity\Scorm2004\Scorm2004MapTrackItem;
6 7
 use Logipro\Bundle\SCORMBundle\LearningModels\SCORM2004\SequencingNavigation\SeqNavRequest;
7 8
 use Logipro\Bundle\SCORMBundle\LearningModels\SCORM2004\SequencingNavigation\SequencingRequest;
8 9
 use Logipro\Bundle\SCORMBundle\LearningModels\SCORM2004\SequencingNavigation\TerminationRequest;
9
-use Symfony\Component\DependencyInjection\ContainerInterface;
10
+use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface;
10 11
 
11 12
 class NavigationRequest extends SeqNavRequest
12 13
 {
@@ -42,14 +43,15 @@ class NavigationRequest extends SeqNavRequest
42 43
     /**
43 44
      * Constructeur
44 45
      *
45
-     * @param ContainerInterface $container
46
+     * @param ParameterBagInterface $parameters : Service
47
+     * @param EntityManagerInterface $em : Service
46 48
      * @param string $navigationRequest
47 49
      * @param string $registrationKey
48 50
      * @param string $targetItemId
49 51
      */
50
-    public function __construct(ContainerInterface $container, string $navigationRequest, string $registrationKey, ?string $targetItemId = '')
52
+    public function __construct(ParameterBagInterface $parameters, EntityManagerInterface $em, string $navigationRequest, string $registrationKey, ?string $targetItemId = '')
51 53
     {
52
-        parent::__construct($container, $navigationRequest, $registrationKey, $targetItemId);
54
+        parent::__construct($parameters, $em, $navigationRequest, $registrationKey, $targetItemId);
53 55
 
54 56
         // Initialisation des variables de l'instance
55 57
         $this->terminationRequest = null;
@@ -152,8 +154,6 @@ class NavigationRequest extends SeqNavRequest
152 154
      */
153 155
     protected function processContinue(): void
154 156
     {
155
-        $em = $this->getDoctrine()->getManager();
156
-
157 157
         // Vérifier que la session d'activité aie bien été initiée (cad qu'il existe un plannode courant)
158 158
         if (!$this->currentItem) {
159 159
 //@TODO mettre en place les var de langue
@@ -172,7 +172,7 @@ class NavigationRequest extends SeqNavRequest
172 172
                 $this->sequencingRequest = SequencingRequest::SEQUENCING_CONTINUE;
173 173
 
174 174
                 // Terminer l'activité en cours si ce n'est pas déjà fait
175
-                $scorm2004MapTrackItemRepository = $em->getRepository(Scorm2004MapTrackItem::class);
175
+                $scorm2004MapTrackItemRepository = $this->em->getRepository(Scorm2004MapTrackItem::class);
176 176
                 $mapTrackItem = $scorm2004MapTrackItemRepository->findOneBy(array('item_identifier' => $this->currentItem, 'scorm2004Track' => $this->scorm2004Track));
177 177
         
178 178
                 if ($mapTrackItem->getIsActive()) {
@@ -193,8 +193,6 @@ class NavigationRequest extends SeqNavRequest
193 193
      */
194 194
     protected function processPrevious(): void
195 195
     {
196
-        $em = $this->getDoctrine()->getManager();
197
-
198 196
         // Vérifier que la session de planNode aie bien été initiée (cad qu'il existe un plannode courant)
199 197
         if (!$this->currentItem) {
200 198
 //@TODO mettre en place les var de langue
@@ -214,7 +212,7 @@ class NavigationRequest extends SeqNavRequest
214 212
                 $this->sequencingRequest = SequencingRequest::SEQUENCING_PREVIOUS;
215 213
 
216 214
                 // Terminer l'activité en cours si ce n'est pas déjà fait
217
-                $scorm2004MapTrackItemRepository = $em->getRepository(Scorm2004MapTrackItem::class);
215
+                $scorm2004MapTrackItemRepository = $this->em->getRepository(Scorm2004MapTrackItem::class);
218 216
                 $mapTrackItem = $scorm2004MapTrackItemRepository->findOneBy(array('item_identifier' => $this->currentItem, 'scorm2004Track' => $this->scorm2004Track));
219 217
                 if ($mapTrackItem->getIsActive()) {
220 218
                     $this->terminationRequest = TerminationRequest::TERMINATION_EXIT;
@@ -251,8 +249,7 @@ class NavigationRequest extends SeqNavRequest
251 249
      */
252 250
     protected function processChoice(): void
253 251
     {
254
-        $em = $this->getDoctrine()->getManager();
255
-        $scorm2004MapTrackItemRepository = $em->getRepository(Scorm2004MapTrackItem::class);
252
+        $scorm2004MapTrackItemRepository = $this->em->getRepository(Scorm2004MapTrackItem::class);
256 253
 
257 254
         // Vérifier l'existence du noeud cible
258 255
         if ($this->targetItem) {
@@ -363,8 +360,7 @@ class NavigationRequest extends SeqNavRequest
363 360
      */
364 361
     protected function processQuit(): void
365 362
     {
366
-        $em = $this->getDoctrine()->getManager();
367
-        $scorm2004MapTrackItemRepository = $em->getRepository(Scorm2004MapTrackItem::class);
363
+        $scorm2004MapTrackItemRepository = $this->em->getRepository(Scorm2004MapTrackItem::class);
368 364
 
369 365
         // Vérifier que la session aie bien été initiée
370 366
         if ($this->currentItem) {

+ 10
- 10
LearningModels/SCORM2004/SequencingNavigation/NavigationRequestValidator.php View File

@@ -2,11 +2,12 @@
2 2
 
3 3
 namespace Logipro\Bundle\SCORMBundle\LearningModels\SCORM2004\SequencingNavigation;
4 4
 
5
+use Doctrine\ORM\EntityManagerInterface;
5 6
 use Logipro\Bundle\SCORMBundle\Entity\Scorm2004\Scorm2004MapTrackItem;
6 7
 use Logipro\Bundle\SCORMBundle\Entity\Scorm2004\Scorm2004AttemptProgressInformation;
7 8
 use Logipro\Bundle\SCORMBundle\Entity\Scorm2004\Scorm2004ObjectiveProgressInformation;
8 9
 use Logipro\Bundle\SCORMBundle\LearningModels\SCORM2004\SequencingNavigation\SeqNavRequest;
9
-use Symfony\Component\DependencyInjection\ContainerInterface;
10
+use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface;
10 11
 
11 12
 /**
12 13
  * Validation des requetes de navigation
@@ -31,14 +32,15 @@ class NavigationRequestValidator extends SeqNavRequest
31 32
     /**
32 33
      * Constructeur
33 34
      *
34
-     * @param ContainerInterface $container
35
+     * @param ParameterBagInterface $parameters : Service
36
+     * @param EntityManagerInterface $em : Service
35 37
      * @param string $request : identifiant requete
36 38
      * @param string $registrationKey : identifiant de l'inscription
37 39
      * @param string $targetItemId
38 40
      */
39
-    public function __construct(ContainerInterface $container, string $registrationKey)
41
+    public function __construct(ParameterBagInterface $parameters, EntityManagerInterface $em, string $registrationKey)
40 42
     {
41
-        parent::__construct($container, '', $registrationKey, '');
43
+        parent::__construct($parameters, $em, '', $registrationKey, '');
42 44
 
43 45
         // arbre applati de l'ensemble des items de la formation
44 46
         $root = $this->scorm2004Track->getOrganizationId();
@@ -156,10 +158,9 @@ class NavigationRequestValidator extends SeqNavRequest
156 158
      */
157 159
     public function defineTableOfContent($currentItem): array
158 160
     {
159
-        $em = $this->getDoctrine()->getManager();
160
-        $scorm2004MapTrackItemRepository = $em->getRepository(Scorm2004MapTrackItem::class);
161
-        $scorm2004AttemptProgressInformationRepository = $em->getRepository(Scorm2004AttemptProgressInformation::class);
162
-        $scorm2004ObjectiveProgressInformationRepository = $em->getRepository(Scorm2004ObjectiveProgressInformation::class);
161
+        $scorm2004MapTrackItemRepository = $this->em->getRepository(Scorm2004MapTrackItem::class);
162
+        $scorm2004AttemptProgressInformationRepository = $this->em->getRepository(Scorm2004AttemptProgressInformation::class);
163
+        $scorm2004ObjectiveProgressInformationRepository = $this->em->getRepository(Scorm2004ObjectiveProgressInformation::class);
163 164
         
164 165
         $toc = array();
165 166
 
@@ -395,8 +396,7 @@ class NavigationRequestValidator extends SeqNavRequest
395 396
      */
396 397
     protected function getNextItemFromTreeTraversalFlow($identifiedItem, $traversalDirection, $previousDirection, $considerChildren)
397 398
     {
398
-        $em = $this->getDoctrine()->getManager();
399
-        $scorm2004MapTrackItemRepository = $em->getRepository(Scorm2004MapTrackItem::class);
399
+        $scorm2004MapTrackItemRepository = $this->em->getRepository(Scorm2004MapTrackItem::class);
400 400
         
401 401
         $reversedDirection = false;
402 402
 

+ 63
- 99
LearningModels/SCORM2004/SequencingNavigation/SeqNavRequest.php View File

@@ -12,9 +12,7 @@ use Logipro\Bundle\SCORMBundle\Entity\Scorm2004\Scorm2004ObjectiveProgressInform
12 12
 use Logipro\Bundle\SCORMBundle\Entity\Scorm2004\Scorm2004Track;
13 13
 use Logipro\Bundle\SCORMBundle\LearningModels\DOMSCORM;
14 14
 use Logipro\Bundle\SCORMBundle\LearningModels\DOMSCORM2004;
15
-use Symfony\Component\DependencyInjection\ContainerAwareInterface;
16
-use Symfony\Component\DependencyInjection\ContainerAwareTrait;
17
-use Symfony\Component\DependencyInjection\ContainerInterface;
15
+use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface;
18 16
 
19 17
 include_once(__DIR__.'/Scorm2004Const.php');
20 18
 
@@ -23,10 +21,8 @@ include_once(__DIR__.'/Scorm2004Const.php');
23 21
  * de navigation, terminaison, sequencage, livraison
24 22
  *
25 23
  */
26
-class SeqNavRequest implements ContainerAwareInterface
24
+class SeqNavRequest
27 25
 {
28
-    use ContainerAwareTrait;
29
-
30 26
     /**
31 27
      * type de la requete en cours
32 28
      *
@@ -82,18 +78,25 @@ class SeqNavRequest implements ContainerAwareInterface
82 78
      * @var DOMSCORM2004
83 79
      */
84 80
     protected $domScorm2004;
81
+
82
+    protected $params;
83
+
84
+    protected $em;
85 85
     
86 86
     /**
87 87
      * Constructeur
88 88
      *
89
-     * @param ContainerInterface $container
89
+     * @param ParameterBagInterface $parameters : Service
90
+     * @param EntityManagerInterface $em : Service
90 91
      * @param string $request : identifiant requete
91 92
      * @param string $registrationKey : identifiant de l'inscription
92 93
      * @param string $targetItemId
93 94
      */
94
-    public function __construct(ContainerInterface $container, string $request, string $registrationKey, ?string $targetItemId)
95
+    public function __construct(ParameterBagInterface $parameters, EntityManagerInterface $em, string $request, string $registrationKey, ?string $targetItemId)
95 96
     {
96
-        $this->setContainer($container);
97
+        // Récupération des service
98
+        $this->params = $parameters;
99
+        $this->em = $em;
97 100
 
98 101
         // Initialisation des variables de l'instance
99 102
         $this->request = $request;
@@ -101,8 +104,6 @@ class SeqNavRequest implements ContainerAwareInterface
101 104
         $this->exception = null;
102 105
         $this->targetItem = $targetItemId;
103 106
 
104
-        $em = $this->getDoctrine()->getManager();
105
-
106 107
         // Récupération de l'inscription
107 108
         $registration  = $this->requireRegistration($registrationKey);
108 109
 
@@ -112,7 +113,7 @@ class SeqNavRequest implements ContainerAwareInterface
112 113
         }
113 114
 
114 115
         // Récupération de l'essai Moteur
115
-        $attemptRepository = $em->getRepository(RegistrationAttempt::class);
116
+        $attemptRepository = $this->em->getRepository(RegistrationAttempt::class);
116 117
         $currentAttempt = $attemptRepository->findOneBy(array('registration' => $registration), array('registrationAttemptId' => 'desc'));
117 118
 
118 119
         if (!$currentAttempt) {
@@ -122,13 +123,13 @@ class SeqNavRequest implements ContainerAwareInterface
122 123
 
123 124
         // Construction du parser
124 125
         // On récupère le paquet à partir de l'inscription
125
-        $packageFolder = $this->container->getParameter('logipro_scorm.package_folder');
126
+        $packageFolder = $this->params->get('logipro_scorm.package_folder');
126 127
         $this->domScorm2004 = $currentAttempt->getDOM($packageFolder);
127 128
 
128 129
         // Récupération de l'organization consultée
129 130
 
130 131
         // Récupération du trackScorm2004 lié à l'essai moteur en cours
131
-        $scorm2004TrackRepository = $em->getRepository(Scorm2004Track::class);
132
+        $scorm2004TrackRepository = $this->em->getRepository(Scorm2004Track::class);
132 133
         $this->scorm2004Track = $scorm2004TrackRepository->findOneBy(array('registrationAttempt' => $currentAttempt));
133 134
 
134 135
         if (!$this->scorm2004Track) {
@@ -147,13 +148,11 @@ class SeqNavRequest implements ContainerAwareInterface
147 148
     */
148 149
     protected function updateTrack2004(): void
149 150
     {
150
-        $em = $this->getDoctrine()->getManager();
151
-
152 151
         $this->scorm2004Track->setCurrentItemRef($this->currentItem);
153 152
         $this->scorm2004Track->setSuspendedItemRef($this->suspendedItem);
154 153
 
155
-        $em->persist($this->scorm2004Track);
156
-        $em->flush();
154
+        $this->em->persist($this->scorm2004Track);
155
+        $this->em->flush();
157 156
     }
158 157
 
159 158
     /**
@@ -185,10 +184,8 @@ class SeqNavRequest implements ContainerAwareInterface
185 184
      */
186 185
     protected function endAttempt($identifiedItemId): void
187 186
     {
188
-        $em = $this->getDoctrine()->getManager();
189
-
190 187
         // Récupération des informations de mapping concerant cet item pour le track2004 en cours
191
-        $scorm2004MapTrackItemRepository = $em->getRepository(Scorm2004MapTrackItem::class);
188
+        $scorm2004MapTrackItemRepository = $this->em->getRepository(Scorm2004MapTrackItem::class);
192 189
         $mapTrackItem = $scorm2004MapTrackItemRepository->findOneBy(array('item_identifier' => $identifiedItemId, 'scorm2004Track' => $this->scorm2004Track));
193 190
 
194 191
         // Récupération des enfants de l'item
@@ -196,7 +193,7 @@ class SeqNavRequest implements ContainerAwareInterface
196 193
         
197 194
         // si l'item est terminal (n'a pas d'enfants)
198 195
         if (empty($children)) {
199
-            $scorm2004AttemptProgressInformationRepository = $em->getRepository(Scorm2004AttemptProgressInformation::class);
196
+            $scorm2004AttemptProgressInformationRepository = $this->em->getRepository(Scorm2004AttemptProgressInformation::class);
200 197
             $itemLastAttempt = $scorm2004AttemptProgressInformationRepository->findOneBy(array('item_identifier' => $identifiedItemId, 'scorm2004Track' => $this->scorm2004Track), array('attempt_id' => 'desc'));
201 198
 
202 199
             if ($itemLastAttempt) {
@@ -211,8 +208,8 @@ class SeqNavRequest implements ContainerAwareInterface
211 208
                             $itemLastAttempt->setProgressStatus(true);
212 209
                             $itemLastAttempt->setCompletionStatus(true);
213 210
                             // Mise à jour des informations de l'essai
214
-                            $em->persist($itemLastAttempt);
215
-                            $em->flush();
211
+                            $this->em->persist($itemLastAttempt);
212
+                            $this->em->flush();
216 213
                         }
217 214
                     }
218 215
 
@@ -223,7 +220,7 @@ class SeqNavRequest implements ContainerAwareInterface
223 220
                         $rollupObjective = $this->domScorm2004->getPrimaryObjective($identifiedItemId);
224 221
                         if ($rollupObjective) {
225 222
                             // Récupération des informations de l'objectif de rollup (contenant les infos mappées si existantes)
226
-                            $scorm2004ObjectiveProgressInformationRepository = $em->getRepository(Scorm2004ObjectiveProgressInformation::class);
223
+                            $scorm2004ObjectiveProgressInformationRepository = $this->em->getRepository(Scorm2004ObjectiveProgressInformation::class);
227 224
                             $objectiveInformationsRead = $scorm2004ObjectiveProgressInformationRepository->findLocalInfoByObjectiveAndAttempt($rollupObjective, $itemLastAttempt, $this->scorm2004Track, true, $this->domScorm2004);
228 225
                             if ($objectiveInformationsRead) {
229 226
                                 $objectiveProgressStatus = $objectiveInformationsRead->getProgressStatus();
@@ -233,7 +230,7 @@ class SeqNavRequest implements ContainerAwareInterface
233 230
                                     $objectiveInformationsWrite->setProgressStatus(true);
234 231
                                     $objectiveInformationsWrite->setSatisfiedStatus(true);
235 232
                                     // mise à jour
236
-                                    $em->persist($objectiveInformationsWrite);
233
+                                    $this->em->persist($objectiveInformationsWrite);
237 234
                                 }
238 235
                             }
239 236
                         }
@@ -265,8 +262,8 @@ class SeqNavRequest implements ContainerAwareInterface
265 262
         // AJOUT DE COMPORTEMENT HORS PSEUDOCODE
266 263
 
267 264
         // ce bean doit etre mis à jour
268
-        $em->persist($mapTrackItem);
269
-        $em->flush();
265
+        $this->em->persist($mapTrackItem);
266
+        $this->em->flush();
270 267
 
271 268
         // Application du processus de rollup
272 269
         $this->evaluateOverallRollup($identifiedItemId);
@@ -322,8 +319,6 @@ class SeqNavRequest implements ContainerAwareInterface
322 319
      */
323 320
     protected function evaluateMeasureRollup($identifiedItemId): void
324 321
     {
325
-        $em = $this->getDoctrine()->getManager();
326
-        
327 322
         $totalWeightedMeasure = 0.0;
328 323
         $validData = false;
329 324
         $countedMeasures = 0.0;
@@ -332,8 +327,8 @@ class SeqNavRequest implements ContainerAwareInterface
332 327
         $targetObjective = $this->domScorm2004->getPrimaryObjective($identifiedItemId);
333 328
 
334 329
         if ($targetObjective) {
335
-            $scorm2004ObjectiveProgressInformationRepository = $em->getRepository(Scorm2004ObjectiveProgressInformation::class);
336
-            $scorm2004AttemptProgressInformationRepository = $em->getRepository(Scorm2004AttemptProgressInformation::class);
330
+            $scorm2004ObjectiveProgressInformationRepository = $this->em->getRepository(Scorm2004ObjectiveProgressInformation::class);
331
+            $scorm2004AttemptProgressInformationRepository = $this->em->getRepository(Scorm2004AttemptProgressInformation::class);
337 332
 
338 333
             // Récupération de l'essai en cours pour la mise à jour des objectifs
339 334
             $itemLastAttempt = $scorm2004AttemptProgressInformationRepository->findOneBy(array('item_identifier' => $identifiedItemId, 'scorm2004Track' => $this->scorm2004Track), array('attempt_id' => 'desc'));
@@ -390,8 +385,8 @@ class SeqNavRequest implements ContainerAwareInterface
390 385
                 }
391 386
 
392 387
                 // Mise à jour de l'objectif
393
-                $em->persist($targetObjectiveInformationsWrite);
394
-                $em->flush();
388
+                $this->em->persist($targetObjectiveInformationsWrite);
389
+                $this->em->flush();
395 390
             }
396 391
         }
397 392
     }
@@ -405,8 +400,7 @@ class SeqNavRequest implements ContainerAwareInterface
405 400
      */
406 401
     protected function evaluateCompletionMeasureRollup($identifiedItemId): void
407 402
     {
408
-        $em = $this->getDoctrine()->getManager();
409
-        $scorm2004AttemptProgressInformationRepository = $em->getRepository(Scorm2004AttemptProgressInformation::class);
403
+        $scorm2004AttemptProgressInformationRepository = $this->em->getRepository(Scorm2004AttemptProgressInformation::class);
410 404
 
411 405
         $totalWeightedMeasure = 0.0;
412 406
         $validData = false;
@@ -454,8 +448,8 @@ class SeqNavRequest implements ContainerAwareInterface
454 448
         }
455 449
 
456 450
         // Mise à jour de l'attempt
457
-        $em->persist($itemLastAttempt);
458
-        $em->flush();
451
+        $this->em->persist($itemLastAttempt);
452
+        $this->em->flush();
459 453
     }
460 454
 
461 455
     /**
@@ -468,9 +462,8 @@ class SeqNavRequest implements ContainerAwareInterface
468 462
      */
469 463
     protected function evaluateObjectiveRollupUsingMeasure($identifiedItemId): ?bool
470 464
     {
471
-        $em = $this->getDoctrine()->getManager();
472
-        $scorm2004AttemptProgressInformationRepository = $em->getRepository(Scorm2004AttemptProgressInformation::class);
473
-        $scorm2004ObjectiveProgressInformationRepository = $em->getRepository(Scorm2004ObjectiveProgressInformation::class);
465
+        $scorm2004AttemptProgressInformationRepository = $this->em->getRepository(Scorm2004AttemptProgressInformation::class);
466
+        $scorm2004ObjectiveProgressInformationRepository = $this->em->getRepository(Scorm2004ObjectiveProgressInformation::class);
474 467
 
475 468
         // Récupération de l'essai en cours pour la mise à jour des objectifs
476 469
         $itemLastAttempt = $scorm2004AttemptProgressInformationRepository->findOneBy(array('item_identifier' => $identifiedItemId, 'scorm2004Track' => $this->scorm2004Track), array('attempt_id' => 'desc'));
@@ -513,8 +506,8 @@ class SeqNavRequest implements ContainerAwareInterface
513 506
                     }
514 507
 
515 508
                     // Mise à jour de l'objective
516
-                    $em->persist($objectiveInformationsWrite);
517
-                    $em->flush();
509
+                    $this->em->persist($objectiveInformationsWrite);
510
+                    $this->em->flush();
518 511
 
519 512
                     //La méthode a été appliquée
520 513
                     return true;
@@ -536,8 +529,6 @@ class SeqNavRequest implements ContainerAwareInterface
536 529
      */
537 530
     protected function evaluateObjectiveRollupUsingRules($identifiedItemId): void
538 531
     {
539
-        $em = $this->getDoctrine()->getManager();
540
-
541 532
         $rollupRules = $this->domScorm2004->getRollupRules($identifiedItemId);
542 533
         // Tri des règles en fonction des actions désirées
543 534
         $notSatisfiedRollupRules = array();
@@ -581,7 +572,7 @@ class SeqNavRequest implements ContainerAwareInterface
581 572
         if ($targetObjective) {
582 573
             // Récupération de l'essai en cours pour la mise à jour des objectifs
583 574
 
584
-            $scorm2004AttemptProgressInformationRepository = $em->getRepository(Scorm2004AttemptProgressInformation::class);
575
+            $scorm2004AttemptProgressInformationRepository = $this->em->getRepository(Scorm2004AttemptProgressInformation::class);
585 576
             $itemLastAttempt = $scorm2004AttemptProgressInformationRepository->findOneBy(array('item_identifier' => $identifiedItemId, 'scorm2004Track' => $this->scorm2004Track), array('attempt_id' => 'desc'));
586 577
 
587 578
             if (!$itemLastAttempt) {
@@ -590,7 +581,7 @@ class SeqNavRequest implements ContainerAwareInterface
590 581
             }
591 582
 
592 583
             // Récupération des informations de l'objectif de rollup (contenant les infos mappées si existantes)
593
-            $scorm2004ObjectiveProgressInformationRepository = $em->getRepository(Scorm2004ObjectiveProgressInformation::class);
584
+            $scorm2004ObjectiveProgressInformationRepository = $this->em->getRepository(Scorm2004ObjectiveProgressInformation::class);
594 585
             $objectiveInformationsWrite = $scorm2004ObjectiveProgressInformationRepository->findLocalInfoByObjectiveAndAttempt($targetObjective, $itemLastAttempt, $this->scorm2004Track, false);
595 586
             if ($objectiveInformationsWrite) {
596 587
                 if ($this->checkRollupRule($identifiedItemId, $notSatisfiedRollupRules)) {
@@ -604,8 +595,8 @@ class SeqNavRequest implements ContainerAwareInterface
604 595
                 }
605 596
 
606 597
                 // Mise à jour des infos de l'objectif
607
-                $em->persist($objectiveInformationsWrite);
608
-                $em->flush();
598
+                $this->em->persist($objectiveInformationsWrite);
599
+                $this->em->flush();
609 600
             }
610 601
         }
611 602
     }
@@ -620,9 +611,7 @@ class SeqNavRequest implements ContainerAwareInterface
620 611
      */
621 612
     public function evaluateItemProgressRollupUsingMeasure($identifiedItemId): bool
622 613
     {
623
-        $em = $this->getDoctrine()->getManager();
624
-        
625
-        $scorm2004AttemptProgressInformationRepository = $em->getRepository(Scorm2004AttemptProgressInformation::class);
614
+        $scorm2004AttemptProgressInformationRepository = $this->em->getRepository(Scorm2004AttemptProgressInformation::class);
626 615
         $itemLastAttempt = $scorm2004AttemptProgressInformationRepository->findOneBy(array('item_identifier' => $identifiedItemId, 'scorm2004Track' => $this->scorm2004Track), array('attempt_id' => 'desc'));
627 616
 
628 617
         if ($itemLastAttempt) {
@@ -640,8 +629,8 @@ class SeqNavRequest implements ContainerAwareInterface
640 629
                 }
641 630
 
642 631
                 // Mise à jour des informations de l'essai
643
-                $em->persist($itemLastAttempt);
644
-                $em->flush();
632
+                $this->em->persist($itemLastAttempt);
633
+                $this->em->flush();
645 634
 
646 635
                 // La méthode a été appliquée
647 636
                 return true;
@@ -661,8 +650,6 @@ class SeqNavRequest implements ContainerAwareInterface
661 650
      */
662 651
     protected function evaluateItemProgressRollupUsingRules($identifiedItemId): void
663 652
     {
664
-        $em = $this->getDoctrine()->getManager();
665
-
666 653
         $rollupRules = $this->domScorm2004->getRollupRules($identifiedItemId);
667 654
         // Tri des règles en fonction des actions désirées
668 655
         $incompleteRollupRules = array();
@@ -699,7 +686,7 @@ class SeqNavRequest implements ContainerAwareInterface
699 686
             $incompleteRollupRules[] = $defaultIncompletedRule;
700 687
         }
701 688
 
702
-        $scorm2004AttemptProgressInformationRepository = $em->getRepository(Scorm2004AttemptProgressInformation::class);
689
+        $scorm2004AttemptProgressInformationRepository = $this->em->getRepository(Scorm2004AttemptProgressInformation::class);
703 690
         $itemLastAttempt = $scorm2004AttemptProgressInformationRepository->findOneBy(array('item_identifier' => $identifiedItemId, 'scorm2004Track' => $this->scorm2004Track), array('attempt_id' => 'desc'));
704 691
 
705 692
         if ($itemLastAttempt) {
@@ -715,8 +702,8 @@ class SeqNavRequest implements ContainerAwareInterface
715 702
             }
716 703
 
717 704
             // Mise à jour des informations de l'essai
718
-            $em->persist($itemLastAttempt);
719
-            $em->flush();
705
+            $this->em->persist($itemLastAttempt);
706
+            $this->em->flush();
720 707
         }
721 708
     }
722 709
 
@@ -830,8 +817,7 @@ class SeqNavRequest implements ContainerAwareInterface
830 817
      */
831 818
     public function checkItemForRollup($item, $action): bool
832 819
     {
833
-        $em = $this->getDoctrine()->getManager();
834
-        $scorm2004MapTrackItemRepository = $em->getRepository(Scorm2004MapTrackItem::class);
820
+        $scorm2004MapTrackItemRepository = $this->em->getRepository(Scorm2004MapTrackItem::class);
835 821
         $mapTrackItem = $scorm2004MapTrackItemRepository->findOneBy(array('item_identifier' => $item, 'scorm2004Track' => $this->scorm2004Track));
836 822
 
837 823
         $included = false;
@@ -991,9 +977,8 @@ class SeqNavRequest implements ContainerAwareInterface
991 977
      */
992 978
     protected function evaluateSequencingCondition($item, $ruleCondition): string
993 979
     {
994
-        $em = $this->getDoctrine()->getManager();
995
-        $scorm2004MapTrackItemRepository = $em->getRepository(Scorm2004MapTrackItem::class);
996
-        $scorm2004ObjectiveProgressInformationRepository = $em->getRepository(Scorm2004ObjectiveProgressInformation::class);
980
+        $scorm2004MapTrackItemRepository = $this->em->getRepository(Scorm2004MapTrackItem::class);
981
+        $scorm2004ObjectiveProgressInformationRepository = $this->em->getRepository(Scorm2004ObjectiveProgressInformation::class);
997 982
 
998 983
         $objective = null;
999 984
         $objectiveId = null;
@@ -1177,12 +1162,11 @@ class SeqNavRequest implements ContainerAwareInterface
1177 1162
      */
1178 1163
     protected function evaluateUniqueRollupCondition($item, $rollupCondition): string
1179 1164
     {
1180
-        $em = $this->getDoctrine()->getManager();
1181
-        $scorm2004MapTrackItemRepository = $em->getRepository(Scorm2004MapTrackItem::class);
1182
-        $scorm2004ObjectiveProgressInformationRepository = $em->getRepository(Scorm2004ObjectiveProgressInformation::class);
1165
+        $scorm2004MapTrackItemRepository = $this->em->getRepository(Scorm2004MapTrackItem::class);
1166
+        $scorm2004ObjectiveProgressInformationRepository = $this->em->getRepository(Scorm2004ObjectiveProgressInformation::class);
1183 1167
 
1184 1168
         // On récupère l'attempt en cours du noeud testé
1185
-        $scorm2004AttemptProgressInformationRepository = $em->getRepository(Scorm2004AttemptProgressInformation::class);
1169
+        $scorm2004AttemptProgressInformationRepository = $this->em->getRepository(Scorm2004AttemptProgressInformation::class);
1186 1170
         $itemLastAttempt = $scorm2004AttemptProgressInformationRepository->findOneBy(array('item_identifier' => $item, 'scorm2004Track' => $this->scorm2004Track), array('attempt_id' => 'desc'));
1187 1171
 
1188 1172
         if (!$itemLastAttempt) {
@@ -1318,9 +1302,8 @@ class SeqNavRequest implements ContainerAwareInterface
1318 1302
      */
1319 1303
     protected function checkLimitConditions($item): bool
1320 1304
     {
1321
-        $em = $this->getDoctrine()->getManager();
1322
-        $scorm2004MapTrackItemRepository = $em->getRepository(Scorm2004MapTrackItem::class);
1323
-        $scorm2004AttemptProgressInformationRepository = $em->getRepository(Scorm2004AttemptProgressInformation::class);
1305
+        $scorm2004MapTrackItemRepository = $this->em->getRepository(Scorm2004MapTrackItem::class);
1306
+        $scorm2004AttemptProgressInformationRepository = $this->em->getRepository(Scorm2004AttemptProgressInformation::class);
1324 1307
 
1325 1308
         $sequencingTracked = $this->domScorm2004->getSequencingAttribute('imsss:deliveryControls', 'tracked', $item);
1326 1309
         // l'item doit être suivi afin d'évaluer les conditions limites
@@ -1421,8 +1404,7 @@ class SeqNavRequest implements ContainerAwareInterface
1421 1404
      */
1422 1405
     public function getAvailableChildren($item): array
1423 1406
     {
1424
-        $em = $this->getDoctrine()->getManager();
1425
-        $scorm2004MapTrackItemRepository = $em->getRepository(Scorm2004MapTrackItem::class);
1407
+        $scorm2004MapTrackItemRepository = $this->em->getRepository(Scorm2004MapTrackItem::class);
1426 1408
         
1427 1409
         $availableChildren = array();
1428 1410
         
@@ -1515,8 +1497,7 @@ class SeqNavRequest implements ContainerAwareInterface
1515 1497
      */
1516 1498
     protected function randomlySelectChildren($identifiedItem, $selectionCount): void
1517 1499
     {
1518
-        $em = $this->getDoctrine()->getManager();
1519
-        $scorm2004MapTrackItemRepository = $em->getRepository(Scorm2004MapTrackItem::class);
1500
+        $scorm2004MapTrackItemRepository = $this->em->getRepository(Scorm2004MapTrackItem::class);
1520 1501
         
1521 1502
         $children = $this->domScorm2004->getChildren($identifiedItem);
1522 1503
 
@@ -1545,7 +1526,7 @@ class SeqNavRequest implements ContainerAwareInterface
1545 1526
                         $mapTrackChild = $scorm2004MapTrackItemRepository->findOneBy(array('item_identifier' => $nonAvailableChild, 'scorm2004Track' => $this->scorm2004Track));
1546 1527
                         $mapTrackChild->setAvailableOrder(-1);
1547 1528
 
1548
-                        $em->persist($mapTrackChild);
1529
+                        $this->em->persist($mapTrackChild);
1549 1530
                     }
1550 1531
                 }
1551 1532
 
@@ -1556,10 +1537,10 @@ class SeqNavRequest implements ContainerAwareInterface
1556 1537
                     $mapTrackChild = $scorm2004MapTrackItemRepository->findOneBy(array('item_identifier' => $child, 'scorm2004Track' => $this->scorm2004Track));
1557 1538
                     $mapTrackChild->setAvailableOrder($key);
1558 1539
                     
1559
-                    $em->persist($mapTrackChild);
1540
+                    $this->em->persist($mapTrackChild);
1560 1541
                 }
1561 1542
 
1562
-                $em->flush();
1543
+                $this->em->flush();
1563 1544
             }
1564 1545
         }
1565 1546
     }
@@ -1573,8 +1554,7 @@ class SeqNavRequest implements ContainerAwareInterface
1573 1554
      */
1574 1555
     protected function randomlyOrderChildren($identifiedItem): void
1575 1556
     {
1576
-        $em = $this->getDoctrine()->getManager();
1577
-        $scorm2004MapTrackItemRepository = $em->getRepository(Scorm2004MapTrackItem::class);
1557
+        $scorm2004MapTrackItemRepository = $this->em->getRepository(Scorm2004MapTrackItem::class);
1578 1558
         
1579 1559
         $children = $this->domScorm2004->getChildren($identifiedItem);
1580 1560
 
@@ -1588,9 +1568,9 @@ class SeqNavRequest implements ContainerAwareInterface
1588 1568
                         $mapTrackChild = $scorm2004MapTrackItemRepository->findOneBy(array('item_identifier' => $child, 'scorm2004Track' => $this->scorm2004Track));
1589 1569
                         $mapTrackChild->setAvailableOrder($key);
1590 1570
                         
1591
-                        $em->persist($mapTrackChild);
1571
+                        $this->em->persist($mapTrackChild);
1592 1572
                     }
1593
-                    $em->flush();
1573
+                    $this->em->flush();
1594 1574
                 }
1595 1575
             }
1596 1576
         }
@@ -1675,21 +1655,6 @@ class SeqNavRequest implements ContainerAwareInterface
1675 1655
     }
1676 1656
 
1677 1657
     // SYMFONY
1678
-
1679
-    /**
1680
-     *
1681
-     * @throws \LogicException
1682
-     * @return ManagerRegistry
1683
-     */
1684
-    protected function getDoctrine(): ManagerRegistry
1685
-    {
1686
-        if (!$this->container->has('doctrine')) {
1687
-            throw new \LogicException('The DoctrineBundle is not registered in your application. Try running "composer require symfony/orm-pack".');
1688
-        }
1689
-
1690
-        return $this->container->get('doctrine');
1691
-    }
1692
-
1693 1658
     /**
1694 1659
      * Retourne l'inscription
1695 1660
      *
@@ -1698,8 +1663,7 @@ class SeqNavRequest implements ContainerAwareInterface
1698 1663
      */
1699 1664
     protected function requireRegistration(string $registrationKey): ?Registration
1700 1665
     {
1701
-        $em = $this->getDoctrine()->getManager();
1702
-        $repository = $em->getRepository(Registration::class);
1666
+        $repository = $this->em->getRepository(Registration::class);
1703 1667
 
1704 1668
         $registration = $repository->findOneBy(array('registrationKey' => $registrationKey));
1705 1669
 

+ 12
- 14
LearningModels/SCORM2004/SequencingNavigation/SequencingRequest.php View File

@@ -2,9 +2,10 @@
2 2
 
3 3
 namespace Logipro\Bundle\SCORMBundle\LearningModels\SCORM2004\SequencingNavigation;
4 4
 
5
+use Doctrine\ORM\EntityManagerInterface;
5 6
 use Logipro\Bundle\SCORMBundle\Entity\Scorm2004\Scorm2004MapTrackItem;
6 7
 use Logipro\Bundle\SCORMBundle\LearningModels\SCORM2004\SequencingNavigation\SeqNavRequest;
7
-use Symfony\Component\DependencyInjection\ContainerInterface;
8
+use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface;
8 9
 
9 10
 class SequencingRequest extends SeqNavRequest
10 11
 {
@@ -42,14 +43,15 @@ class SequencingRequest extends SeqNavRequest
42 43
     /**
43 44
      * Constructeur
44 45
      *
45
-     * @param ContainerInterface $container
46
+     * @param ParameterBagInterface $parameters : Service
47
+     * @param EntityManagerInterface $em : Service
46 48
      * @param string $sequencingRequest
47 49
      * @param string $registrationId
48 50
      * @param string $targetItemId
49 51
      */
50
-    public function __construct(ContainerInterface $container, string $sequencingRequest, string $registrationId, ?string $targetItemId = '')
52
+    public function __construct(ParameterBagInterface $parameters, EntityManagerInterface $em, string $sequencingRequest, string $registrationId, ?string $targetItemId = '')
51 53
     {
52
-        parent::__construct($container, $sequencingRequest, $registrationId, $targetItemId);
54
+        parent::__construct($parameters, $em, $sequencingRequest, $registrationId, $targetItemId);
53 55
 
54 56
         // Initialisation des variables de l'instance
55 57
         $this->deliveryRequest = null;
@@ -248,8 +250,7 @@ class SequencingRequest extends SeqNavRequest
248 250
      */
249 251
     protected function processChoice(): void
250 252
     {
251
-        $em = $this->getDoctrine()->getManager();
252
-        $scorm2004MapTrackItemRepository = $em->getRepository(Scorm2004MapTrackItem::class);
253
+        $scorm2004MapTrackItemRepository = $this->em->getRepository(Scorm2004MapTrackItem::class);
253 254
         
254 255
         // L'item ciblé doit être valide
255 256
         if (!$this->targetItem) {
@@ -526,8 +527,7 @@ class SequencingRequest extends SeqNavRequest
526 527
      */
527 528
     protected function processRetry(): void
528 529
     {
529
-        $em = $this->getDoctrine()->getManager();
530
-        $scorm2004MapTrackItemRepository = $em->getRepository(Scorm2004MapTrackItem::class);
530
+        $scorm2004MapTrackItemRepository = $this->em->getRepository(Scorm2004MapTrackItem::class);
531 531
 
532 532
         // Vérifier que la session d'activité aie bien été initiée
533 533
         if (!$this->currentItem) {
@@ -586,8 +586,7 @@ class SequencingRequest extends SeqNavRequest
586 586
      */
587 587
     protected function processExit(): void
588 588
     {
589
-        $em = $this->getDoctrine()->getManager();
590
-        $scorm2004MapTrackItemRepository = $em->getRepository(Scorm2004MapTrackItem::class);
589
+        $scorm2004MapTrackItemRepository = $this->em->getRepository(Scorm2004MapTrackItem::class);
591 590
 
592 591
         // Vérifier que la session d'activité aie bien été initiée
593 592
         if (!$this->currentItem) {
@@ -646,8 +645,7 @@ class SequencingRequest extends SeqNavRequest
646 645
      */
647 646
     protected function getNextItemFromTreeTraversalFlow($identifiedItem, $traversalDirection, $previousDirection, $considerChildren): array
648 647
     {
649
-        $em = $this->getDoctrine()->getManager();
650
-        $scorm2004MapTrackItemRepository = $em->getRepository(Scorm2004MapTrackItem::class);
648
+        $scorm2004MapTrackItemRepository = $this->em->getRepository(Scorm2004MapTrackItem::class);
651 649
 
652 650
         $reversedDirection = false;
653 651
 
@@ -675,9 +673,9 @@ class SequencingRequest extends SeqNavRequest
675 673
             foreach ($availableSiblings as $key => $sibling) {
676 674
                 $mapTrackSibling = $scorm2004MapTrackItemRepository->findOneBy(array('item_identifier' => $sibling, 'scorm2004Track' => $this->scorm2004Track));
677 675
                 $mapTrackSibling->setAvailableOrder($key);
678
-                $em->persist($mapTrackSibling);
676
+                $this->em->persist($mapTrackSibling);
679 677
             }
680
-            $em->flush();
678
+            $this->em->flush();
681 679
         }
682 680
 
683 681
         $response = array(

+ 18
- 22
LearningModels/SCORM2004/SequencingNavigation/TerminationRequest.php View File

@@ -2,10 +2,11 @@
2 2
 
3 3
 namespace Logipro\Bundle\SCORMBundle\LearningModels\SCORM2004\SequencingNavigation;
4 4
 
5
+use Doctrine\ORM\EntityManagerInterface;
5 6
 use Logipro\Bundle\SCORMBundle\Entity\Scorm2004\Scorm2004MapTrackItem;
6 7
 use Logipro\Bundle\SCORMBundle\LearningModels\SCORM2004\SequencingNavigation\SeqNavRequest;
7 8
 use Logipro\Bundle\SCORMBundle\LearningModels\SCORM2004\SequencingNavigation\SequencingRequest;
8
-use Symfony\Component\DependencyInjection\ContainerInterface;
9
+use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface;
9 10
 
10 11
 class TerminationRequest extends SeqNavRequest
11 12
 {
@@ -28,13 +29,14 @@ class TerminationRequest extends SeqNavRequest
28 29
     /**
29 30
      * Constructeur
30 31
      *
31
-     * @param ContainerInterface $container
32
+     * @param ParameterBagInterface $parameters : Service
33
+     * @param EntityManagerInterface $em : Service
32 34
      * @param string $terminationRequest
33 35
      * @param string $registrationKey
34 36
      */
35
-    public function __construct(ContainerInterface $container, string $terminationRequest, string $registrationKey)
37
+    public function __construct(ParameterBagInterface $parameters, EntityManagerInterface $em, string $terminationRequest, string $registrationKey)
36 38
     {
37
-        parent::__construct($container, $terminationRequest, $registrationKey, '');
39
+        parent::__construct($parameters, $em, $terminationRequest, $registrationKey, '');
38 40
 
39 41
         // Initialisation des variables de l'instance
40 42
         $this->sequencingRequest = null;
@@ -50,8 +52,7 @@ class TerminationRequest extends SeqNavRequest
50 52
      */
51 53
     protected function globalProcess(): void
52 54
     {
53
-        $em = $this->getDoctrine()->getManager();
54
-        $scorm2004MapTrackItemRepository = $em->getRepository(Scorm2004MapTrackItem::class);
55
+        $scorm2004MapTrackItemRepository = $this->em->getRepository(Scorm2004MapTrackItem::class);
55 56
         
56 57
         // Vérifier que la session d'activité aie déjà été initiée
57 58
         // sinon il n'y a rien à terminer
@@ -163,8 +164,7 @@ class TerminationRequest extends SeqNavRequest
163 164
      */
164 165
     protected function processExitAll(): void
165 166
     {
166
-        $em = $this->getDoctrine()->getManager();
167
-        $scorm2004MapTrackItemRepository = $em->getRepository(Scorm2004MapTrackItem::class);
167
+        $scorm2004MapTrackItemRepository = $this->em->getRepository(Scorm2004MapTrackItem::class);
168 168
         
169 169
         // Si le noeud courant est toujours actif
170 170
         // on lui applique le processus de terminaison
@@ -193,8 +193,7 @@ class TerminationRequest extends SeqNavRequest
193 193
      */
194 194
     protected function processSuspendAll(): void
195 195
     {
196
-        $em = $this->getDoctrine()->getManager();
197
-        $scorm2004MapTrackItemRepository = $em->getRepository(Scorm2004MapTrackItem::class);
196
+        $scorm2004MapTrackItemRepository = $this->em->getRepository(Scorm2004MapTrackItem::class);
198 197
         
199 198
         // Si l'activité courante est active ou suspendue
200 199
         // elle devient l'activité suspendue
@@ -230,9 +229,9 @@ class TerminationRequest extends SeqNavRequest
230 229
             $mapTrackItem->setIsActive(false);
231 230
             $mapTrackItem->setIsSuspended(true);
232 231
             
233
-            $em->persist($mapTrackItem);
232
+            $this->em->persist($mapTrackItem);
234 233
         }
235
-        $em->flush();
234
+        $this->em->flush();
236 235
 
237 236
         $this->currentItem = $treeRoot;
238 237
         $this->updateTrack2004();
@@ -248,14 +247,13 @@ class TerminationRequest extends SeqNavRequest
248 247
      */
249 248
     protected function processAbandon(): void
250 249
     {
251
-        $em = $this->getDoctrine()->getManager();
252
-        $scorm2004MapTrackItemRepository = $em->getRepository(Scorm2004MapTrackItem::class);
250
+        $scorm2004MapTrackItemRepository = $this->em->getRepository(Scorm2004MapTrackItem::class);
253 251
 
254 252
         $mapTrackCurrentItem = $scorm2004MapTrackItemRepository->findOneBy(array('item_identifier' => $this->currentItem, 'scorm2004Track' => $this->scorm2004Track));
255 253
         $mapTrackCurrentItem->setIsActive(false);
256 254
         
257
-        $em->persist($mapTrackCurrentItem);
258
-        $em->flush();
255
+        $this->em->persist($mapTrackCurrentItem);
256
+        $this->em->flush();
259 257
 
260 258
         $this->validationState = true;
261 259
     }
@@ -267,8 +265,7 @@ class TerminationRequest extends SeqNavRequest
267 265
      */
268 266
     protected function processAbandonAll(): void
269 267
     {
270
-        $em = $this->getDoctrine()->getManager();
271
-        $scorm2004MapTrackItemRepository = $em->getRepository(Scorm2004MapTrackItem::class);
268
+        $scorm2004MapTrackItemRepository = $this->em->getRepository(Scorm2004MapTrackItem::class);
272 269
 
273 270
         $treeRoot = $this->scorm2004Track->getOrganizationId();
274 271
         $path = $this->domScorm2004->getDirectPath($this->currentItem, $treeRoot);
@@ -283,9 +280,9 @@ class TerminationRequest extends SeqNavRequest
283 280
             
284 281
             $mapTrackItem->setIsActive(false);
285 282
             
286
-            $em->persist($mapTrackItem);
283
+            $this->em->persist($mapTrackItem);
287 284
         }
288
-        $em->flush();
285
+        $this->em->flush();
289 286
 
290 287
         $this->currentItem = $treeRoot;
291 288
         $this->updateTrack2004();
@@ -342,8 +339,7 @@ class TerminationRequest extends SeqNavRequest
342 339
      */
343 340
     protected function evaluatePostConditionRules(): ?array
344 341
     {
345
-        $em = $this->getDoctrine()->getManager();
346
-        $scorm2004MapTrackItemRepository = $em->getRepository(Scorm2004MapTrackItem::class);
342
+        $scorm2004MapTrackItemRepository = $this->em->getRepository(Scorm2004MapTrackItem::class);
347 343
         
348 344
         // on ne peut pas appliquer de règle de post condition sur un item suspendu
349 345
         $mapTrackCurrentItem = $scorm2004MapTrackItemRepository->findOneBy(array('item_identifier' => $this->currentItem, 'scorm2004Track' => $this->scorm2004Track));

+ 50
- 61
Player/SCORM2004/Scorm2004PlayerLogic.php View File

@@ -18,20 +18,32 @@ use Logipro\Bundle\SCORMBundle\LearningModels\SCORM2004\SequencingNavigation\Nav
18 18
 use Logipro\Bundle\SCORMBundle\LearningModels\SCORM2004\SequencingNavigation\SeqNavRequest;
19 19
 use Logipro\Bundle\SCORMBundle\LearningModels\SCORM2004\SequencingNavigation\SequencingRequest;
20 20
 use Logipro\Bundle\SCORMBundle\LearningModels\SCORM2004\SequencingNavigation\TerminationRequest;
21
-use Symfony\Component\DependencyInjection\ContainerInterface;
22
-use Symfony\Component\DependencyInjection\ContainerAwareTrait;
23
-use Symfony\Component\DependencyInjection\ContainerAwareInterface;
21
+use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface;
22
+use Symfony\Component\Routing\RouterInterface;
24 23
 
25 24
 /**
26 25
  * Classe traitant la logique nécessaire à l'affichage du lecteur
27 26
  * en SCORM2004
28 27
  */
29
-class Scorm2004PlayerLogic implements ContainerAwareInterface
28
+class Scorm2004PlayerLogic
30 29
 {
31
-    use ContainerAwareTrait;
30
+    /**
31
+     * Service de routing
32
+     * Necessaire pour l'API
33
+     * @var RouterInterface
34
+     */
35
+    protected $router;
36
+    
37
+    protected $parameters;
32 38
 
33
-    public function __construct()
39
+    protected $em;
40
+    
41
+    public function __construct(RouterInterface $router, ParameterBagInterface $parameters, EntityManagerInterface $em)
34 42
     {
43
+        // Récupération des services
44
+        $this->router = $router;
45
+        $this->parameters = $parameters;
46
+        $this->em = $em;
35 47
     }
36 48
 
37 49
     /**
@@ -55,7 +67,7 @@ class Scorm2004PlayerLogic implements ContainerAwareInterface
55 67
             'nav' => '',
56 68
             'target' => ''
57 69
         );
58
-        $packageFolder = $this->container->getParameter('logipro_scorm.package_folder');
70
+        $packageFolder = $this->parameters->get('logipro_scorm.package_folder');
59 71
         $dom = $zipFile->getDOM($packageFolder);
60 72
 
61 73
         // On décrypte et désérialise les infos si fournies
@@ -105,10 +117,8 @@ class Scorm2004PlayerLogic implements ContainerAwareInterface
105 117
 
106 118
         // Si pas de requete de navigation, cas d'une nouvelle entrée sur une organisation
107 119
         if (empty($dataArray['nav'])) {
108
-            $em = $this->getDoctrine()->getManager();
109
-            
110 120
             // Récupération du track
111
-            $trackRepository = $em->getRepository(Scorm2004Track::class);
121
+            $trackRepository = $this->em->getRepository(Scorm2004Track::class);
112 122
             $track = $trackRepository->findOneBy(array('registrationAttempt' => $attempt), array('track_id' => 'desc'));
113 123
 
114 124
             // Si pas de track, création du track
@@ -118,7 +128,7 @@ class Scorm2004PlayerLogic implements ContainerAwareInterface
118 128
 
119 129
             
120 130
             $suspendedItem = $track->getSuspendedItemRef();
121
-            $navigationValidator = new NavigationRequestValidator($this->container, $registrationKey);
131
+            $navigationValidator = new NavigationRequestValidator($this->parameters, $this->em, $registrationKey);
122 132
             
123 133
             // Si il existe un item suspendu au niveau du track
124 134
             if ($suspendedItem) {
@@ -132,15 +142,15 @@ class Scorm2004PlayerLogic implements ContainerAwareInterface
132 142
                 // On vérifie qu'il n'y ai pas d'item courrant résultant d'une déconnexion sauvage
133 143
                 /* if ($track->getCurrentItemRef()) {
134 144
                     $track->setCurrentItemRef('');
135
-                    $em->persist($track);
136
-                    $em->flush();
145
+                    $this->em->persist($track);
146
+                    $this->em->flush();
137 147
                 } */
138 148
             } else {
139 149
                 // Aucune possibilité aux vues de l'état du system
140 150
                 // On propose la liste de sélection des items (item spécifique au moteur)
141 151
                 $track->setCurrentItemRef($track->getOrganizationId());
142
-                $em->persist($track);
143
-                $em->flush();
152
+                $this->em->persist($track);
153
+                $this->em->flush();
144 154
                 
145 155
 // TODO SELECTION ITEM
146 156
                 // return SelectionItem;
@@ -170,13 +180,11 @@ class Scorm2004PlayerLogic implements ContainerAwareInterface
170 180
      */
171 181
     protected function createTrack(DOMSCORM2004 $dom, string $registrationKey, RegistrationAttempt $attempt, array $dataArray)
172 182
     {
173
-        $em = $this->getDoctrine()->getManager();
174
-        
175 183
         $track = new Scorm2004Track();
176 184
         $track->setRegistrationAttempt($attempt);
177 185
         $track->setOrganizationId($dataArray['org']);
178
-        $em->persist($track);
179
-        $em->flush();
186
+        $this->em->persist($track);
187
+        $this->em->flush();
180 188
 
181 189
         // ajout d'un mapping pour chaque item de l'organisation
182 190
         $items = $dom->getFlatTree($dataArray['org']);
@@ -186,7 +194,7 @@ class Scorm2004PlayerLogic implements ContainerAwareInterface
186 194
             $map->setItemIdentifier($item);
187 195
             $map->setScorm2004Track($track);
188 196
 
189
-            $em->persist($map);
197
+            $this->em->persist($map);
190 198
 
191 199
             // récupération des objectifs globaux liés à l'item pour la suite de l'initialisation
192 200
             $itemObjectives = $dom->getObjectives($item);
@@ -209,7 +217,7 @@ class Scorm2004PlayerLogic implements ContainerAwareInterface
209 217
         if ($dom->getIsGlobalToSystem($dataArray['org']) === 'true') {
210 218
             $registration = $this->requireRegistration($registrationKey);
211 219
             $learner = $registration->getLearner();
212
-            $objectiveInfoRepository = $em->getRepository(Scorm2004ObjectiveProgressInformation::class);
220
+            $objectiveInfoRepository = $this->em->getRepository(Scorm2004ObjectiveProgressInformation::class);
213 221
 
214 222
             foreach ($globalObjectives as $global) {
215 223
                 $objectiveInfo = $objectiveInfoRepository->findOneBy(array('objectiveIdentifier' => $global, 'learner' => $learner));
@@ -219,7 +227,7 @@ class Scorm2004PlayerLogic implements ContainerAwareInterface
219 227
                     $objectiveInfo->setLearner($learner);
220 228
                     $objectiveInfo->setIsPrimary(false);
221 229
 
222
-                    $em->persist($objectiveInfo);
230
+                    $this->em->persist($objectiveInfo);
223 231
                 }
224 232
             }
225 233
         } else {
@@ -229,14 +237,14 @@ class Scorm2004PlayerLogic implements ContainerAwareInterface
229 237
                 $objectiveInfo->setScorm2004Track($track);
230 238
                 $objectiveInfo->setIsPrimary(false);
231 239
                 
232
-                $em->persist($objectiveInfo);
240
+                $this->em->persist($objectiveInfo);
233 241
             }
234 242
         }
235 243
         
236
-        $em->flush();
244
+        $this->em->flush();
237 245
 
238 246
         // Définition des availableChildren pour chaque item (necessite que toutes les tables de mappage soit créées au préalable)
239
-        $seqNavRequest = new SeqNavRequest($this->container, '', $registrationKey, '');
247
+        $seqNavRequest = new SeqNavRequest($this->parameters, $this->em, '', $registrationKey, '');
240 248
         foreach ($items as $item => $index) {
241 249
             $seqNavRequest->defineAvailableChildren($item, true);
242 250
         }
@@ -256,8 +264,6 @@ class Scorm2004PlayerLogic implements ContainerAwareInterface
256 264
      */
257 265
     protected function processOverallSequencing(DOMSCORM2004 $dom, array $data, RegistrationAttempt $attempt)
258 266
     {
259
-        $em = $this->getDoctrine()->getManager();
260
-
261 267
         $registrationKey = $data['regKey'];
262 268
         $organization = $data['org'];
263 269
         $currentItem = $data['current'];
@@ -265,7 +271,7 @@ class Scorm2004PlayerLogic implements ContainerAwareInterface
265 271
         $targetItem = $data['target'];
266 272
             
267 273
         // Récupération du track
268
-        $trackRepository = $em->getRepository(Scorm2004Track::class);
274
+        $trackRepository = $this->em->getRepository(Scorm2004Track::class);
269 275
         $track = $trackRepository->findOneBy(array('registrationAttempt' => $attempt), array('track_id' => 'desc'));
270 276
 
271 277
         if (!$track) {
@@ -285,14 +291,14 @@ class Scorm2004PlayerLogic implements ContainerAwareInterface
285 291
             if ($currentItem != $currentRef) {
286 292
                 if ($currentRef) {
287 293
                     $track->setCurrentItemRef('');
288
-                    $em->persist($track);
289
-                    $em->flush();
294
+                    $this->em->persist($track);
295
+                    $this->em->flush();
290 296
                 }
291 297
             }
292 298
         }
293 299
 
294 300
         /*** Traitement de la requete de navigation ***/
295
-        $processedNavRequest = new NavigationRequest($this->container, $navigationRequest, $registrationKey, $targetItem);
301
+        $processedNavRequest = new NavigationRequest($this->parameters, $this->em, $navigationRequest, $registrationKey, $targetItem);
296 302
 
297 303
         // Si la requete de navigation est invalide
298 304
         if (!$processedNavRequest->getValidationState()) {
@@ -317,7 +323,7 @@ class Scorm2004PlayerLogic implements ContainerAwareInterface
317 323
 
318 324
         /*** Traitement de la requete de terminaison ***/
319 325
         if ($terminationRequest) {
320
-            $processedTerminationRequest = new TerminationRequest($this->container, $terminationRequest, $registrationKey);
326
+            $processedTerminationRequest = new TerminationRequest($this->parameters, $this->em, $terminationRequest, $registrationKey);
321 327
 
322 328
             // on test la validité du processus de terminaison
323 329
             if (!$processedTerminationRequest->getValidationState()) {
@@ -347,7 +353,7 @@ class Scorm2004PlayerLogic implements ContainerAwareInterface
347 353
 
348 354
         /*** Traitement de la requete de sequencage ***/
349 355
         if ($sequencingRequest) {
350
-            $processedSequencingRequest = new SequencingRequest($this->container, $sequencingRequest, $registrationKey, $targetItem);
356
+            $processedSequencingRequest = new SequencingRequest($this->parameters, $this->em, $sequencingRequest, $registrationKey, $targetItem);
351 357
 
352 358
             // on test la validité du processus de sequencage
353 359
             if (!$processedSequencingRequest->getValidationState()) {
@@ -368,8 +374,8 @@ class Scorm2004PlayerLogic implements ContainerAwareInterface
368 374
             if ($processedSequencingRequest->getEndSequencingSession()) {
369 375
                 // L'activité courante devient non définie
370 376
                 $track->setCurrentItemRef('');
371
-                $em->persist($track);
372
-                $em->flush();
377
+                $this->em->persist($track);
378
+                $this->em->flush();
373 379
 
374 380
                 // retour à la page d'acceuil de la formation
375 381
                 $response = array(
@@ -384,8 +390,8 @@ class Scorm2004PlayerLogic implements ContainerAwareInterface
384 390
             if ($navigationRequest == NavigationRequest::NAVIGATION_EXIT || $navigationRequest == NavigationRequest::NAVIGATION_ABANDON) {
385 391
                 // l'item racine (l'organisation) devient l'item courant
386 392
                 $track->setCurrentItemRef($organization);
387
-                $em->persist($track);
388
-                $em->flush();
393
+                $this->em->persist($track);
394
+                $this->em->flush();
389 395
 
390 396
 // TODO
391 397
                 // Affichage du lecteur sur le Item de sélection (le Item racine)
@@ -402,7 +408,7 @@ class Scorm2004PlayerLogic implements ContainerAwareInterface
402 408
         /*** traitement de la livraison ***/
403 409
         if ($deliveryItem) {
404 410
             // Vérification des conditions de livraison
405
-            $processedDeliveryRequest = new DeliveryRequest($this->container, $deliveryItem, $registrationKey);
411
+            $processedDeliveryRequest = new DeliveryRequest($this->parameters, $this->em, $deliveryItem, $registrationKey);
406 412
 
407 413
             // on test la validité du processus de livraison
408 414
             if (!$processedDeliveryRequest->getValidationState()) {
@@ -421,7 +427,7 @@ class Scorm2004PlayerLogic implements ContainerAwareInterface
421 427
             }
422 428
 
423 429
             // La livraison est possible, on récupère les données nécessaires au lecteur
424
-            $playerView = new Scorm2004PlayerView($this->container, $dom, $track, $registrationKey, $organization, $deliveryItem);
430
+            $playerView = new Scorm2004PlayerView($this->router, $this->parameters, $this->em, $dom, $track, $registrationKey, $organization, $deliveryItem);
425 431
             $response = $playerView->getResponse();
426 432
 
427 433
             return $response;
@@ -435,26 +441,24 @@ class Scorm2004PlayerLogic implements ContainerAwareInterface
435 441
      */
436 442
     protected function suspendAfterError(Scorm2004Track $track)
437 443
     {
438
-        $em = $this->getDoctrine()->getManager();
439
-        
440 444
         // passage de l'item courant en item suspendu
441 445
         $currentItem = $track->getCurrentItemRef();
442 446
 
443 447
         $track->setCurrentItemRef('');
444 448
         $track->setSuspendedItemRef($currentItem);
445
-        $em->persist($track);
449
+        $this->em->persist($track);
446 450
 
447 451
         // mise en suspension des items actifs
448
-        $mapTrackItemRepository = $em->getRepository(Scorm2004MapTrackItem::class);
452
+        $mapTrackItemRepository = $this->em->getRepository(Scorm2004MapTrackItem::class);
449 453
         $activeMapItems = $mapTrackItemRepository->findBy(array('scorm2004Track' => $track, 'is_active' => true));
450 454
 
451 455
         foreach ($activeMapItems as $mapItem) {
452 456
             $mapItem->setIsActive(false);
453 457
             $mapItem->setIsSuspended(true);
454
-            $em->persist($mapItem);
458
+            $this->em->persist($mapItem);
455 459
         }
456 460
 
457
-        $em->flush();
461
+        $this->em->flush();
458 462
     }
459 463
 
460 464
     /**
@@ -466,25 +470,10 @@ class Scorm2004PlayerLogic implements ContainerAwareInterface
466 470
      */
467 471
     protected function requireRegistration(string $registrationKey)
468 472
     {
469
-        $em = $this->getDoctrine()->getManager();
470
-        $repository = $em->getRepository(Registration::class);
473
+        $repository = $this->em->getRepository(Registration::class);
471 474
 
472 475
         $registration = $repository->findOneBy(array('registrationKey' => $registrationKey));
473 476
 
474 477
         return $registration;
475 478
     }
476
-
477
-    /**
478
-     *
479
-     * @throws \LogicException
480
-     * @return ManagerRegistry
481
-     */
482
-    protected function getDoctrine(): ManagerRegistry
483
-    {
484
-        if (!$this->container->has('doctrine')) {
485
-            throw new \LogicException('The DoctrineBundle is not registered in your application. Try running "composer require symfony/orm-pack".');
486
-        }
487
-
488
-        return $this->container->get('doctrine');
489
-    }
490 479
 }

+ 18
- 28
Player/SCORM2004/Scorm2004PlayerView.php View File

@@ -11,18 +11,21 @@ use Logipro\Bundle\SCORMBundle\LearningModels\DOMSCORM2004;
11 11
 use Logipro\Bundle\SCORMBundle\LearningModels\SCORM2004\SequencingNavigation\NavigationRequest;
12 12
 use Logipro\Bundle\SCORMBundle\LearningModels\SCORM2004\SequencingNavigation\NavigationRequestValidator;
13 13
 use Logipro\Bundle\SCORMBundle\LearningModels\SCORM2004\SequencingNavigation\Scorm2004Const;
14
-use Symfony\Component\DependencyInjection\ContainerInterface;
15
-use Symfony\Component\DependencyInjection\ContainerAwareTrait;
16
-use Symfony\Component\DependencyInjection\ContainerAwareInterface;
14
+use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface;
15
+use Symfony\Component\Routing\RouterInterface;
17 16
 
18 17
 /**
19 18
  * Classe les données nécessaire à l'affichage du lecteur
20 19
  * en SCORM2004
21 20
  */
22
-class Scorm2004PlayerView implements ContainerAwareInterface
21
+class Scorm2004PlayerView
23 22
 {
24
-    use ContainerAwareTrait;
23
+    protected $router;
24
+    
25
+    protected $parameters;
25 26
 
27
+    protected $em;
28
+    
26 29
     protected $response;
27 30
 
28 31
     protected $dom;
@@ -39,9 +42,12 @@ class Scorm2004PlayerView implements ContainerAwareInterface
39 42
 
40 43
     protected $tocValidations;
41 44
 
42
-    public function __construct(ContainerInterface $container, DOMSCORM2004 $dom, Scorm2004Track $track, string $registrationKey, string $organization, string $item)
45
+    public function __construct(RouterInterface $router, ParameterBagInterface $parameters, EntityManagerInterface $em, DOMSCORM2004 $dom, Scorm2004Track $track, string $registrationKey, string $organization, string $item)
43 46
     {
44
-        $this->setContainer($container);
47
+        // Récupération des services
48
+        $this->router = $router;
49
+        $this->parameters = $parameters;
50
+        $this->em = $em;
45 51
 
46 52
         $this->dom = $dom;
47 53
         $this->track = $track;
@@ -142,7 +148,7 @@ class Scorm2004PlayerView implements ContainerAwareInterface
142 148
         }
143 149
 
144 150
         // Controle de l'état relatif aux requetes de type 'previous' et 'continue' en fonction de l'état du system
145
-        $navigationRequestValidator = new NavigationRequestValidator($this->container, $this->registrationKey);
151
+        $navigationRequestValidator = new NavigationRequestValidator($this->parameters, $this->em, $this->registrationKey);
146 152
         $this->navUIControls[SCORM2004_HIDE_LMS_UI_PREVIOUS]['enable'] = $navigationRequestValidator->checkPreviousValidity($this->item);
147 153
         $this->navUIControls[SCORM2004_HIDE_LMS_UI_CONTINUE]['enable'] = $navigationRequestValidator->checkContinueValidity($this->item);
148 154
     }
@@ -168,7 +174,7 @@ class Scorm2004PlayerView implements ContainerAwareInterface
168 174
     protected function getToc()
169 175
     {
170 176
         // Récupération de l'état des plannodes pour une requete de type 'choice' en fonction de l'état du system
171
-        $navigationRequestValidator = new NavigationRequestValidator($this->container, $this->registrationKey);
177
+        $navigationRequestValidator = new NavigationRequestValidator($this->parameters, $this->em, $this->registrationKey);
172 178
         $this->tocValidations = $navigationRequestValidator->defineTableOfContent($this->item);
173 179
         
174 180
         $response = array();
@@ -176,8 +182,7 @@ class Scorm2004PlayerView implements ContainerAwareInterface
176 182
         // Récupération des enfants disponibles
177 183
         $children = $this->dom->getChildren($this->organization);
178 184
 
179
-        $em = $this->getDoctrine()->getManager();
180
-        $scorm2004MapTrackItemRepository = $em->getRepository(Scorm2004MapTrackItem::class);
185
+        $scorm2004MapTrackItemRepository = $this->em->getRepository(Scorm2004MapTrackItem::class);
181 186
 
182 187
         if (!empty($children)) {
183 188
             foreach ($children as $child) {
@@ -228,8 +233,7 @@ class Scorm2004PlayerView implements ContainerAwareInterface
228 233
         // Récupération des enfants disponibles uniquement
229 234
         $children = $this->dom->getChildren($item);
230 235
         $availableChildren = array();
231
-        $em = $this->getDoctrine()->getManager();
232
-        $scorm2004MapTrackItemRepository = $em->getRepository(Scorm2004MapTrackItem::class);
236
+        $scorm2004MapTrackItemRepository = $this->em->getRepository(Scorm2004MapTrackItem::class);
233 237
         foreach ($children as $child) {
234 238
             $mapTrackItem = $scorm2004MapTrackItemRepository->findOneBy(array('item_identifier' => $child, 'scorm2004Track' => $this->track));
235 239
             if ($mapTrackItem && $mapTrackItem->getAvailableOrder() !== -1) {
@@ -320,23 +324,9 @@ class Scorm2004PlayerView implements ContainerAwareInterface
320 324
      */
321 325
     protected function getApi() : string
322 326
     {
323
-        $apiScorm2004 = new ApiScorm2004($this->container);
327
+        $apiScorm2004 = new ApiScorm2004($this->router, $this->parameters, $this->em);
324 328
         $api = $apiScorm2004->getAPI($this->dom, $this->registrationKey, $this->organization, $this->item);
325 329
 
326 330
         return $api;
327 331
     }
328
-
329
-    /**
330
-     *
331
-     * @throws \LogicException
332
-     * @return ManagerRegistry
333
-     */
334
-    protected function getDoctrine(): ManagerRegistry
335
-    {
336
-        if (!$this->container->has('doctrine')) {
337
-            throw new \LogicException('The DoctrineBundle is not registered in your application. Try running "composer require symfony/orm-pack".');
338
-        }
339
-
340
-        return $this->container->get('doctrine');
341
-    }
342 332
 }

+ 3
- 3
Resources/config/services.xml View File

@@ -5,10 +5,10 @@
5 5
 
6 6
     <services>
7 7
         <service id="Logipro\Bundle\SCORMBundle\Services\ScormEngine" class="Logipro\Bundle\SCORMBundle\Services\ScormEngine" public="true">
8
-            <argument></argument> <!-- will be filled in with package_folder dynamically -->
9
-            <argument></argument> <!-- will be filled in with content_folder dynamically -->
10
-            <argument></argument> <!-- will be filled in with content_url_prefix dynamically -->
8
+            <argument type="service" id="router.default"/>
9
+            <argument type="service" id="parameter_bag"/>
11 10
             <argument type="service" id="session"/>
11
+            <argument type="service" id="Doctrine\ORM\EntityManagerInterface"/>
12 12
         </service>
13 13
         <service id="scorm.services.engine" alias="Logipro\Bundle\SCORMBundle\Services\ScormEngine" public="true" />
14 14
 

+ 92
- 132
Services/ScormEngine.php View File

@@ -18,21 +18,31 @@ use Logipro\Bundle\SCORMBundle\LearningModels\DOMSCORM2004;
18 18
 use Logipro\Bundle\SCORMBundle\Package\Common\PackageTypeDetector;
19 19
 use Logipro\Bundle\SCORMBundle\Player\SCORM2004\Scorm2004PlayerLogic;
20 20
 use Logipro\Bundle\SCORMBundle\Package\PackageValidator;
21
-use Symfony\Component\DependencyInjection\ContainerInterface;
22
-use Symfony\Component\DependencyInjection\ContainerAwareTrait;
21
+use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface;
23 22
 use Symfony\Component\DependencyInjection\Reference;
24
-use Symfony\Component\DependencyInjection\ContainerAwareInterface;
25 23
 use Symfony\Component\HttpFoundation\Cookie;
26 24
 use Symfony\Component\HttpFoundation\Request;
27 25
 use Symfony\Component\HttpFoundation\Response;
28 26
 use Symfony\Component\HttpFoundation\Session\SessionInterface;
27
+use Symfony\Component\Routing\RouterInterface;
29 28
 
30 29
 /**
31 30
  * Service de communication du moteur
32 31
  */
33
-class ScormEngine implements ContainerAwareInterface
32
+class ScormEngine
34 33
 {
35
-    use ContainerAwareTrait;
34
+    /**
35
+     * Service de routing
36
+     * Necessaire pour l'API
37
+     * @var RouterInterface
38
+     */
39
+    protected $router;
40
+
41
+    /**
42
+     * Service permettant d'accéder aux paramètres du container
43
+     * @var ParameterBagInterface
44
+     */
45
+    protected $parameters;
36 46
 
37 47
     protected $packageFolder;
38 48
 
@@ -49,6 +59,11 @@ class ScormEngine implements ContainerAwareInterface
49 59
      */
50 60
     protected $session;
51 61
 
62
+    /**
63
+     * @var EntityManagerInterface
64
+     */
65
+    protected $em;
66
+
52 67
     /**
53 68
      * la response est créée ou modifiée pour inserer un cookie dans le header
54 69
      * lors de la lecture du paquet (ce cookie est uniquement utilisé dans un mecanisme de
@@ -58,12 +73,18 @@ class ScormEngine implements ContainerAwareInterface
58 73
      */
59 74
     private $response;
60 75
 
61
-    public function __construct(string $packageFolder, string $contentFolder, string $contentUrlPrefix, SessionInterface $session)
76
+    public function __construct(RouterInterface $router, ParameterBagInterface $parameters, SessionInterface $session, EntityManagerInterface $em)
62 77
     {
63
-        $this->packageFolder = $packageFolder;
64
-        $this->contentFolder = $contentFolder;
65
-        $this->contentUrlPrefix = $contentUrlPrefix;
78
+        // Récupération des services
79
+        $this->router = $router;
80
+        $this->parameters = $parameters;
66 81
         $this->session = $session;
82
+        $this->em = $em;
83
+
84
+        // Définitions des params
85
+        $this->packageFolder = $this->parameters->get('logipro_scorm.package_folder');
86
+        $this->contentFolder = $this->parameters->get('logipro_scorm.content_folder');
87
+        $this->contentUrlPrefix = $this->parameters->get('logipro_scorm.content_url_prefix');
67 88
     }
68 89
 
69 90
     // COURS
@@ -130,11 +151,8 @@ class ScormEngine implements ContainerAwareInterface
130 151
             // Récupération de la signature du zip
131 152
             $hash = md5_file($zipPath);
132 153
 
133
-            // Récupération de l'entity manager
134
-            $em = $this->getDoctrine()->getManager();
135
-
136 154
             // Test de l'existence de la signature
137
-            $repository = $em->getRepository(ZipFile::class);
155
+            $repository = $this->em->getRepository(ZipFile::class);
138 156
             $zipFile = $repository->findOneBy(['zipFileprint' => $hash]);
139 157
             $response['metadata']['isAlreadyExisting'] = !empty($zipFile);
140 158
 
@@ -168,8 +186,8 @@ class ScormEngine implements ContainerAwareInterface
168 186
                 $zipFile->setStandard($validation['standard']);
169 187
                 $zipFile->setImportStatus(ZipFile::IMPORT_STATUS_PROCESSING);
170 188
 
171
-                $em->persist($zipFile);
172
-                $em->flush();
189
+                $this->em->persist($zipFile);
190
+                $this->em->flush();
173 191
 
174 192
                 // Une fois l'objet ZipFile créé, on l'extrait
175 193
                 $zipFile->extractZipFile($this->packageFolder, $this->contentFolder);
@@ -180,7 +198,7 @@ class ScormEngine implements ContainerAwareInterface
180 198
             $course = new Course();
181 199
             $course->setCourseKey($courseKey);
182 200
             $course->setVersionRule($versioningRule);
183
-            $em->persist($course);
201
+            $this->em->persist($course);
184 202
 
185 203
             // Métadonées du cours
186 204
             $response['course']['courseKey'] = $course->getCourseKey();
@@ -191,9 +209,9 @@ class ScormEngine implements ContainerAwareInterface
191 209
             $mapping->setCourse($course);
192 210
             $mapping->setZipFile($zipFile);
193 211
             $mapping->setVersion($response['course']['maxVersion']);
194
-            $em->persist($mapping);
212
+            $this->em->persist($mapping);
195 213
 
196
-            $em->flush();
214
+            $this->em->flush();
197 215
 
198 216
             $response['isSuccessfullyCreated'] = true;
199 217
         }
@@ -263,11 +281,8 @@ class ScormEngine implements ContainerAwareInterface
263 281
             // Récupération de la signature du zip
264 282
             $hash = md5_file($zipPath);
265 283
 
266
-            // Récupération de l'entity manager
267
-            $em = $this->getDoctrine()->getManager();
268
-
269 284
             // Test de l'existence de la signature
270
-            $repository = $em->getRepository(ZipFile::class);
285
+            $repository = $this->em->getRepository(ZipFile::class);
271 286
             $zipFile = $repository->findOneBy(['zipFileprint' => $hash]);
272 287
             $response['metadata']['isAlreadyExisting'] = !empty($zipFile);
273 288
 
@@ -301,7 +316,7 @@ class ScormEngine implements ContainerAwareInterface
301 316
                 $zipFile->setStandard($validation['standard']);
302 317
                 $zipFile->setImportStatus(ZipFile::IMPORT_STATUS_PROCESSING);
303 318
 
304
-                $em->persist($zipFile);
319
+                $this->em->persist($zipFile);
305 320
 
306 321
                 // Une fois l'objet ZipFile créé, on l'extrait
307 322
                 $zipFile->extractZipFile($this->packageFolder, $this->contentFolder);
@@ -313,7 +328,7 @@ class ScormEngine implements ContainerAwareInterface
313 328
             $newMaxVersion = $course->getMaxVersion();
314 329
             $newMaxVersion++;
315 330
             $course->setMaxVersion($newMaxVersion);
316
-            $em->persist($course);
331
+            $this->em->persist($course);
317 332
 
318 333
             // Métadonées du cours
319 334
             $response['course']['courseKey'] = $course->getCourseKey();
@@ -324,9 +339,9 @@ class ScormEngine implements ContainerAwareInterface
324 339
             $mapping->setCourse($course);
325 340
             $mapping->setZipFile($zipFile);
326 341
             $mapping->setVersion($newMaxVersion);
327
-            $em->persist($mapping);
342
+            $this->em->persist($mapping);
328 343
 
329
-            $em->flush();
344
+            $this->em->flush();
330 345
 
331 346
             $response['isSuccessfullyUpdated'] = true;
332 347
         }
@@ -389,18 +404,15 @@ class ScormEngine implements ContainerAwareInterface
389 404
             $response['error'] = 'La clef du nouveau cours existe déjà. Utilser \'updateCourse\' pour mettre à jour un cours existant.';
390 405
             return $response;
391 406
         }
392
-
393
-        // Récupération de l'entity manager
394
-        $em = $this->getDoctrine()->getManager();
395 407
         
396 408
         // COURS
397 409
         $newCourse = clone $originalCourse;
398 410
         $newCourse->setCourseKey($newCourseKey);
399 411
         $newCourse->setMaxVersion(1);
400
-        $em->persist($newCourse);
412
+        $this->em->persist($newCourse);
401 413
 
402 414
         // Récupération de l'objet Zip
403
-        $mappingRepository = $em->getRepository(MapCourseZipfile::class);
415
+        $mappingRepository = $this->em->getRepository(MapCourseZipfile::class);
404 416
         $originalMapping = $mappingRepository->findOneBy(array('course' => $originalCourse), array('mapCourseZipfileId' => 'desc'));
405 417
         $zipFile = $originalMapping->getZipFile();
406 418
 
@@ -410,8 +422,8 @@ class ScormEngine implements ContainerAwareInterface
410 422
         $mapping->setZipFile($zipFile);
411 423
         $mapping->setVersion($newCourse->getMaxVersion());
412 424
              
413
-        $em->persist($mapping);
414
-        $em->flush();
425
+        $this->em->persist($mapping);
426
+        $this->em->flush();
415 427
 
416 428
         // Réponse
417 429
         $response['course']['courseKey'] = $newCourse->getCourseKey();
@@ -432,15 +444,13 @@ class ScormEngine implements ContainerAwareInterface
432 444
      */
433 445
     public function updateCourseVersionRule(string $courseKey, string $versionRule)
434 446
     {
435
-        $em = $this->getDoctrine()->getManager();
436
-        
437 447
         $course = $this->requireCourse($courseKey);
438 448
 
439 449
         if ($course) {
440 450
             $course->setVersionRule($versionRule);
441 451
 
442
-            $em->persist($course);
443
-            $em->flush();
452
+            $this->em->persist($course);
453
+            $this->em->flush();
444 454
 
445 455
             return $course->getCourseKey();
446 456
         }
@@ -455,13 +465,11 @@ class ScormEngine implements ContainerAwareInterface
455 465
      */
456 466
     public function deleteCourse(string $courseKey)
457 467
     {
458
-        $em = $this->getDoctrine()->getManager();
459
-
460 468
         $course = $this->requireCourse($courseKey);
461 469
 
462 470
         if ($course) {
463
-            $em->remove($course);
464
-            $em->flush();
471
+            $this->em->remove($course);
472
+            $this->em->flush();
465 473
             return true;
466 474
         }
467 475
         
@@ -498,8 +506,7 @@ class ScormEngine implements ContainerAwareInterface
498 506
 
499 507
     public function getCourses() : array
500 508
     {
501
-        $em = $this->getDoctrine()->getManager();
502
-        $repository = $em->getRepository(Course::class);
509
+        $repository = $this->em->getRepository(Course::class);
503 510
         $courses = $repository->findAll();
504 511
         
505 512
         return $courses;
@@ -533,8 +540,6 @@ class ScormEngine implements ContainerAwareInterface
533 540
             $learner = $this->requireLearner($learnerKey);
534 541
 
535 542
             if (empty($learner)) {
536
-                $em = $this->getDoctrine()->getManager();
537
-
538 543
                 $familyName = $familyName ?? '';
539 544
                 $givenName = $givenName ?? '';
540 545
 
@@ -543,8 +548,8 @@ class ScormEngine implements ContainerAwareInterface
543 548
                 $learner->setFamilyName($familyName);
544 549
                 $learner->setGivenName($givenName);
545 550
 
546
-                $em->persist($learner);
547
-                $em->flush();
551
+                $this->em->persist($learner);
552
+                $this->em->flush();
548 553
             } else {
549 554
                 $response['isAlreadyExisting'] = true;
550 555
             }
@@ -577,8 +582,8 @@ class ScormEngine implements ContainerAwareInterface
577 582
                 $learner->setFamilyName($familyName);
578 583
                 $learner->setGivenName($givenName);
579 584
 
580
-                $em->persist($learner);
581
-                $em->flush();
585
+                $this->em->persist($learner);
586
+                $this->em->flush();
582 587
             }
583 588
         }
584 589
             return $learner->getLearnerKey();
@@ -593,8 +598,6 @@ class ScormEngine implements ContainerAwareInterface
593 598
      */
594 599
     public function getLearner(string $learnerKey)
595 600
     {
596
-        $em = $this->getDoctrine()->getManager();
597
-
598 601
         $learner = $this->requireLearner($learnerKey);
599 602
 
600 603
         return $learner;
@@ -602,8 +605,7 @@ class ScormEngine implements ContainerAwareInterface
602 605
 
603 606
     public function getLearners()
604 607
     {
605
-        $em = $this->getDoctrine()->getManager();
606
-        $repository = $em->getRepository(Learner::class);
608
+        $repository = $this->em->getRepository(Learner::class);
607 609
         $learners = $repository->findAll();
608 610
 
609 611
         return $learners;
@@ -618,13 +620,11 @@ class ScormEngine implements ContainerAwareInterface
618 620
      */
619 621
     public function deleteLearner(string $learnerKey)
620 622
     {
621
-        $em = $this->getDoctrine()->getManager();
622
-
623 623
         $learner = $this->requireLearner($learnerKey);
624 624
 
625 625
         if ($learner) {
626
-            $em->remove($learner);
627
-            $em->flush();
626
+            $this->em->remove($learner);
627
+            $this->em->flush();
628 628
             return true;
629 629
         }
630 630
         
@@ -663,15 +663,13 @@ class ScormEngine implements ContainerAwareInterface
663 663
 
664 664
             if ($course && $learner) {
665 665
                 if (empty($registration)) {
666
-                    $em = $this->getDoctrine()->getManager();
667
-
668 666
                     $registration = new Registration();
669 667
                     $registration->setRegistrationKey($registrationKey);
670 668
                     $registration->setCourse($course);
671 669
                     $registration->setLearner($learner);
672 670
 
673
-                    $em->persist($registration);
674
-                    $em->flush();
671
+                    $this->em->persist($registration);
672
+                    $this->em->flush();
675 673
                 } else {
676 674
                     $response['isAlreadyExisting'] = true;
677 675
                 }
@@ -708,8 +706,6 @@ class ScormEngine implements ContainerAwareInterface
708 706
             // Erreur : une inscription valide doit être passée
709 707
             return null;
710 708
         }
711
-
712
-        $em = $this->getDoctrine()->getManager();
713 709
         
714 710
         // Récupération du cours et des infos de version
715 711
         $course = $registration->getCourse();
@@ -717,7 +713,7 @@ class ScormEngine implements ContainerAwareInterface
717 713
         $versionRule = $course->getVersionRule();
718 714
 
719 715
         // Récupération du registrationAttempt courant
720
-        $attemptRepository = $em->getRepository(RegistrationAttempt::class);
716
+        $attemptRepository = $this->em->getRepository(RegistrationAttempt::class);
721 717
         $currentAttempt = $attemptRepository->findOneBy(array('registration' => $registration), array('registrationAttemptId' => 'desc'));
722 718
 
723 719
         $needCreation = empty($currentAttempt);
@@ -730,20 +726,20 @@ class ScormEngine implements ContainerAwareInterface
730 726
             $newAttempt->setCourseVersion($maxVersion);
731 727
             $newAttempt->setRegistration($registration);
732 728
 
733
-            $em->persist($newAttempt);
734
-            $em->flush();
729
+            $this->em->persist($newAttempt);
730
+            $this->em->flush();
735 731
 
736 732
             $currentAttempt = $newAttempt;
737 733
             $currentVersion = $maxVersion;
738 734
 
739 735
             if (!$needCreation) {
740
-// TODO Indiquer dans la réponse que l'on a effectué une modification de version pour l'apprenan
736
+// TODO Indiquer dans la réponse que l'on a effectué une modification de version pour l'apprenant
741 737
                 $data = null;
742 738
             }
743 739
         }
744 740
         
745 741
         // Récupération du zip correspondant et ainsi de la version du standard utilisée
746
-        $mapCourseZipRepository = $em->getRepository(MapCourseZipfile::class);
742
+        $mapCourseZipRepository = $this->em->getRepository(MapCourseZipfile::class);
747 743
         $mapCourseZip = $mapCourseZipRepository->findOneBy(array('course' => $course, 'version' => $currentVersion));
748 744
         $zipFile = $mapCourseZip->getZipFile();
749 745
         $standard = $zipFile->getStandard();
@@ -752,8 +748,7 @@ class ScormEngine implements ContainerAwareInterface
752 748
         $variables = null;
753 749
         switch ($standard) {
754 750
             case DOMSCORM2004::SCORM_2004:
755
-                $playerLogic = new Scorm2004PlayerLogic();
756
-                $playerLogic->setContainer($this->container);
751
+                $playerLogic = new Scorm2004PlayerLogic($this->router, $this->parameters, $this->em);
757 752
                 $variables = $playerLogic->getScorm2004PlayerVariables($registrationKey, $zipFile, $currentAttempt, $data);
758 753
                 break;
759 754
 
@@ -793,8 +788,6 @@ class ScormEngine implements ContainerAwareInterface
793 788
      */
794 789
     public function getCompletion(string $registrationKey)
795 790
     {
796
-        $em = $this->getDoctrine()->getManager();
797
-        
798 791
         // Vérification de l'existance de l'inscription
799 792
         $registration = $this->requireRegistration($registrationKey);
800 793
         if (empty($registration)) {
@@ -802,22 +795,22 @@ class ScormEngine implements ContainerAwareInterface
802 795
         }
803 796
         
804 797
         // Récupération du dernier essai moteur pour cette inscription
805
-        $registrationAttemptRepository = $em->getRepository(RegistrationAttempt::class);
798
+        $registrationAttemptRepository = $this->em->getRepository(RegistrationAttempt::class);
806 799
         $lastAttempt = $registrationAttemptRepository->findOneBy(array('registration' => $registration), array('registrationAttemptId' => 'desc'));
807 800
 
808 801
 // DETECTER AVANT LE TYPE DE SCORM POUR SAVOIR QUEL STANDARD
809 802
 // CODE SCORM 2004
810 803
         // On récupère le track correspondant
811
-        $track2004Repository = $em->getRepository(Scorm2004Track::class);
804
+        $track2004Repository = $this->em->getRepository(Scorm2004Track::class);
812 805
         $track2004 = $track2004Repository->findOneBy(array('registrationAttempt' => $lastAttempt));
813 806
         if (empty($track2004)) {
814 807
             return 0;
815 808
         }
816 809
 
817 810
         // Dans un premier temps on détermine si la complétion peut être remontée
818
-        // en se basant sur l'état de complétion de l'ensemble des items terminaux  
819
-        $mapTrackItemRepository = $em->getRepository(Scorm2004MapTrackItem::class);
820
-        $attemptItemRepository = $em->getRepository(Scorm2004AttemptProgressInformation::class);
811
+        // en se basant sur l'état de complétion de l'ensemble des items terminaux
812
+        $mapTrackItemRepository = $this->em->getRepository(Scorm2004MapTrackItem::class);
813
+        $attemptItemRepository = $this->em->getRepository(Scorm2004AttemptProgressInformation::class);
821 814
         
822 815
         $mapTrackItems = $mapTrackItemRepository->findBy(array('scorm2004Track' => $track2004));
823 816
 
@@ -850,7 +843,7 @@ class ScormEngine implements ContainerAwareInterface
850 843
             }
851 844
         }
852 845
 
853
-        // Si aucune complétion n'a été déterminée précédement 
846
+        // Si aucune complétion n'a été déterminée précédement
854 847
         // on controle que l'on aie pas un taux de complétion présent au niveau de l'organisation
855 848
         $organization = $track2004->getOrganizationId();
856 849
         if (empty($organization)) {
@@ -887,8 +880,6 @@ class ScormEngine implements ContainerAwareInterface
887 880
      */
888 881
     public function getAverageScore(string $registrationKey)
889 882
     {
890
-        $em = $this->getDoctrine()->getManager();
891
-        
892 883
         // Vérification de l'existance de l'inscription
893 884
         $registration = $this->requireRegistration($registrationKey);
894 885
         if (empty($registration)) {
@@ -896,19 +887,19 @@ class ScormEngine implements ContainerAwareInterface
896 887
         }
897 888
         
898 889
         // Récupération du dernier essai pour cette inscription
899
-        $registrationAttemptRepository = $em->getRepository(RegistrationAttempt::class);
890
+        $registrationAttemptRepository = $this->em->getRepository(RegistrationAttempt::class);
900 891
         $lastAttempt = $registrationAttemptRepository->findOneBy(array('registration' => $registration), array('registrationAttemptId' => 'desc'));
901 892
 
902 893
 // DETECTER AVANT LE TYPE DE SCORM POUR SAVOIR QUEL STANDARD
903 894
 // CODE SCORM 2004
904 895
         // On récupère le track correspondant
905
-        $track2004Repository = $em->getRepository(Scorm2004Track::class);
896
+        $track2004Repository = $this->em->getRepository(Scorm2004Track::class);
906 897
         $track2004 = $track2004Repository->findOneBy(array('registrationAttempt' => $lastAttempt));
907 898
         if (empty($track2004)) {
908 899
             return null;
909 900
         }
910 901
         
911
-        $mapTrackItemRepository = $em->getRepository(Scorm2004MapTrackItem::class);
902
+        $mapTrackItemRepository = $this->em->getRepository(Scorm2004MapTrackItem::class);
912 903
         
913 904
         $mapTrackItems = $mapTrackItemRepository->findBy(array('scorm2004Track' => $track2004));
914 905
 
@@ -948,8 +939,6 @@ class ScormEngine implements ContainerAwareInterface
948 939
      */
949 940
     public function getInteractions(string $registrationKey)
950 941
     {
951
-        $em = $this->getDoctrine()->getManager();
952
-        
953 942
         // Vérification de l'existance de l'inscription
954 943
         $registration = $this->requireRegistration($registrationKey);
955 944
         if (empty($registration)) {
@@ -957,19 +946,19 @@ class ScormEngine implements ContainerAwareInterface
957 946
         }
958 947
         
959 948
         // Récupération du dernier essai pour cette inscription
960
-        $registrationAttemptRepository = $em->getRepository(RegistrationAttempt::class);
949
+        $registrationAttemptRepository = $this->em->getRepository(RegistrationAttempt::class);
961 950
         $lastAttempt = $registrationAttemptRepository->findOneBy(array('registration' => $registration), array('registrationAttemptId' => 'desc'));
962 951
 
963 952
 // DETECTER AVANT LE TYPE DE SCORM POUR SAVOIR QUEL STANDARD
964 953
 // CODE SCORM 2004
965 954
         // On récupère le track correspondant
966
-        $track2004Repository = $em->getRepository(Scorm2004Track::class);
955
+        $track2004Repository = $this->em->getRepository(Scorm2004Track::class);
967 956
         $track2004 = $track2004Repository->findOneBy(array('registrationAttempt' => $lastAttempt));
968 957
         if (empty($track2004)) {
969 958
             return null;
970 959
         }
971 960
         
972
-        $mapTrackItemRepository = $em->getRepository(Scorm2004MapTrackItem::class);
961
+        $mapTrackItemRepository = $this->em->getRepository(Scorm2004MapTrackItem::class);
973 962
         
974 963
         // Récupération des données pour chaque items
975 964
         $mapTrackItems = $mapTrackItemRepository->findBy(array('scorm2004Track' => $track2004));
@@ -978,11 +967,10 @@ class ScormEngine implements ContainerAwareInterface
978 967
 
979 968
         if (!empty($mapTrackItems)) {
980 969
             // Récupération du DOM afin d'avoir des infos sur les items
981
-            $packageFolder = $this->container->getParameter('logipro_scorm.package_folder');
982
-            $domScorm2004 = $lastAttempt->getDOM($packageFolder);
970
+            $domScorm2004 = $lastAttempt->getDOM($this->packageFolder);
983 971
 
984
-            $attemptItemRepository = $em->getRepository(Scorm2004AttemptProgressInformation::class);
985
-            $interactionRepository = $em->getRepository(Scorm2004Interaction::class);
972
+            $attemptItemRepository = $this->em->getRepository(Scorm2004AttemptProgressInformation::class);
973
+            $interactionRepository = $this->em->getRepository(Scorm2004Interaction::class);
986 974
 
987 975
             // Pour chaque item
988 976
             foreach ($mapTrackItems as $item) {
@@ -1045,9 +1033,8 @@ class ScormEngine implements ContainerAwareInterface
1045 1033
         $registration = $this->requireRegistration($registrationKey);
1046 1034
 
1047 1035
         if ($registration) {
1048
-            $em = $this->getDoctrine()->getManager();
1049
-            $em->remove($registration);
1050
-            $em->flush();
1036
+            $this->em->remove($registration);
1037
+            $this->em->flush();
1051 1038
             return true;
1052 1039
         }
1053 1040
         
@@ -1063,9 +1050,7 @@ class ScormEngine implements ContainerAwareInterface
1063 1050
      */
1064 1051
     public function resetRegistraitonData(string $registrationKey)
1065 1052
     {
1066
-        $em = $this->getDoctrine()->getManager();
1067
-
1068
-        $trackRepository = $em->getRepository(Registration::class);
1053
+        $trackRepository = $this->em->getRepository(Registration::class);
1069 1054
 
1070 1055
         $registration = $this->requireRegistration($registrationKey);
1071 1056
 
@@ -1076,7 +1061,7 @@ class ScormEngine implements ContainerAwareInterface
1076 1061
             // Efface les RegistrationAttempts
1077 1062
             // Les objets SCORM seront effacés en cascade
1078 1063
             foreach ($attempts as $attempt) {
1079
-                $em->remove($attempt);
1064
+                $this->em->remove($attempt);
1080 1065
             }
1081 1066
 
1082 1067
             // Création d'un nouveau RegistrationAttempt
@@ -1084,10 +1069,10 @@ class ScormEngine implements ContainerAwareInterface
1084 1069
             $attempt = new RegistrationAttempt();
1085 1070
             $attempt->setCourseVersion($course->getMaxVersion());
1086 1071
             $attempt->setRegistration($registration);
1087
-            $em->persist($attempt);
1072
+            $this->em->persist($attempt);
1088 1073
 
1089 1074
 
1090
-            $em->flush();
1075
+            $this->em->flush();
1091 1076
             return true;
1092 1077
         }
1093 1078
         
@@ -1096,8 +1081,7 @@ class ScormEngine implements ContainerAwareInterface
1096 1081
 
1097 1082
     public function getRegistrations()
1098 1083
     {
1099
-        $em = $this->getDoctrine()->getManager();
1100
-        $repository = $em->getRepository(Registration::class);
1084
+        $repository = $this->em->getRepository(Registration::class);
1101 1085
         $registrations = $repository->findAll();
1102 1086
 
1103 1087
         return $registrations;
@@ -1114,8 +1098,6 @@ class ScormEngine implements ContainerAwareInterface
1114 1098
      */
1115 1099
     public function getAttempts(string $registrationKey)
1116 1100
     {
1117
-        $em = $this->getDoctrine()->getManager();
1118
-
1119 1101
         $registration = $this->requireRegistration($registrationKey);
1120 1102
 
1121 1103
         if ($registration) {
@@ -1135,12 +1117,10 @@ class ScormEngine implements ContainerAwareInterface
1135 1117
      */
1136 1118
     public function getCurrentAttempt(string $registrationKey)
1137 1119
     {
1138
-        $em = $this->getDoctrine()->getManager();
1139
-
1140 1120
         $registration = $this->requireRegistration($registrationKey);
1141 1121
 
1142 1122
         if ($registration) {
1143
-            $attemptRepository = $em->getRepository(RegistrationAttempt::class);
1123
+            $attemptRepository = $this->em->getRepository(RegistrationAttempt::class);
1144 1124
 
1145 1125
             $currentAttempt = $attemptRepository->findCurrentAttemptByRegistration($registration);
1146 1126
 
@@ -1159,8 +1139,6 @@ class ScormEngine implements ContainerAwareInterface
1159 1139
      */
1160 1140
     public function getAttemptCourseVersion(int $attemptId)
1161 1141
     {
1162
-        $em = $this->getDoctrine()->getManager();
1163
-
1164 1142
         $attempt = $this->requireRegistrationAttempt($attemptId);
1165 1143
 
1166 1144
         if ($attempt) {
@@ -1237,20 +1215,6 @@ class ScormEngine implements ContainerAwareInterface
1237 1215
     {
1238 1216
         return $this->contentUrlPrefix.'/'.$this->session->get('scormkey').'/'.$courseKey;
1239 1217
     }
1240
-
1241
-    /**
1242
-     *
1243
-     * @throws \LogicException
1244
-     * @return ManagerRegistry
1245
-     */
1246
-    protected function getDoctrine(): ManagerRegistry
1247
-    {
1248
-        if (!$this->container->has('doctrine')) {
1249
-            throw new \LogicException('The DoctrineBundle is not registered in your application. Try running "composer require symfony/orm-pack".');
1250
-        }
1251
-
1252
-        return $this->container->get('doctrine');
1253
-    }
1254 1218
     
1255 1219
     /**
1256 1220
      * Retourne l'activité
@@ -1260,8 +1224,7 @@ class ScormEngine implements ContainerAwareInterface
1260 1224
      */
1261 1225
     protected function requireCourse(string $courseKey)
1262 1226
     {
1263
-        $em = $this->getDoctrine()->getManager();
1264
-        $repository = $em->getRepository(Course::class);
1227
+        $repository = $this->em->getRepository(Course::class);
1265 1228
         
1266 1229
         $course = $repository->findOneBy(array('courseKey' => $courseKey));
1267 1230
 
@@ -1276,8 +1239,7 @@ class ScormEngine implements ContainerAwareInterface
1276 1239
      */
1277 1240
     protected function requireLearner(string $learnerKey)
1278 1241
     {
1279
-        $em = $this->getDoctrine()->getManager();
1280
-        $repository = $em->getRepository(Learner::class);
1242
+        $repository = $this->em->getRepository(Learner::class);
1281 1243
 
1282 1244
         $learner = $repository->findOneBy(array('learnerKey' => $learnerKey));
1283 1245
 
@@ -1293,8 +1255,7 @@ class ScormEngine implements ContainerAwareInterface
1293 1255
      */
1294 1256
     protected function requireRegistration(string $registrationKey)
1295 1257
     {
1296
-        $em = $this->getDoctrine()->getManager();
1297
-        $repository = $em->getRepository(Registration::class);
1258
+        $repository = $this->em->getRepository(Registration::class);
1298 1259
 
1299 1260
         $registration = $repository->findOneBy(array('registrationKey' => $registrationKey));
1300 1261
 
@@ -1310,8 +1271,7 @@ class ScormEngine implements ContainerAwareInterface
1310 1271
      */
1311 1272
     protected function requireRegistrationAttempt(int $attemptId)
1312 1273
     {
1313
-        $em = $this->getDoctrine()->getManager();
1314
-        $repository = $em->getRepository(RegistrationAttempt::class);
1274
+        $repository = $this->em->getRepository(RegistrationAttempt::class);
1315 1275
 
1316 1276
         $attempt = $repository->find($attemptId);
1317 1277
 

Loading…
Cancel
Save