frederic 3 years ago
parent
commit
55ba0ae4d1

+ 6
- 6
ClientAPI/ApiScorm2004.php View File

@@ -760,12 +760,12 @@ EOT;
760 760
             $index++;
761 761
         }
762 762
 
763
-        $apiString .=<<<EOT
764
-        window.setInterval(periodical, 20000);
765
-        function periodical() {
766
-            API_1484_11.Commit("");
767
-        }
768
-EOT;
763
+//         $apiString .=<<<EOT
764
+//         window.setInterval(periodical, 20000);
765
+//         function periodical() {
766
+//             API_1484_11.Commit("");
767
+//         }
768
+// EOT;
769 769
 
770 770
 /*         // 4.3 Gestion de la fermeture de la page
771 771
         $apiString .=<<<EOT

+ 23
- 10
Controller/Track2004Controller.php View File

@@ -19,6 +19,7 @@ use Logipro\Bundle\SCORMBundle\Tools\UnicodeTools;
19 19
 use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
20 20
 use Symfony\Component\HttpFoundation\Request;
21 21
 use Symfony\Component\HttpFoundation\Response;
22
+use Symfony\Component\HttpFoundation\JsonResponse;
22 23
 
23 24
 class Track2004Controller extends AbstractController
24 25
 {
@@ -34,6 +35,12 @@ class Track2004Controller extends AbstractController
34 35
     {
35 36
         $em = $this->getDoctrine()->getManager();
36 37
 
38
+        // Traitement de la requete json
39
+        if (0 === strpos($request->headers->get('Content-Type'), 'application/json')) {
40
+            $data = json_decode($request->getContent(), true);
41
+            $request->request->replace(is_array($data) ? $data : array());
42
+        }
43
+
37 44
         // Récupérer la requete et les objets qu'elle contient
38 45
         $data = null;
39 46
         if ($request->isMethod('POST')) {
@@ -44,8 +51,8 @@ class Track2004Controller extends AbstractController
44 51
        //                       1). Récupération des objets du sco                             //
45 52
       //======================================================================================//
46 53
         // On attrape l'objet CMI et ADL à partir de l'url
47
-        $cmiData = $this->getCMIFromRequest();
48
-        $adlData = $this->getADLFromRequest();
54
+        $cmiData = $this->getCMIFromRequest($request);
55
+        $adlData = $this->getADLFromRequest($request);
49 56
 
50 57
         // sin on a ni l'objet cmi et ni l'objet adl alors on a rien à faire
51 58
         if (!$cmiData && !$adlData) {
@@ -365,7 +372,7 @@ class Track2004Controller extends AbstractController
365 372
 
366 373
         $response = $this->getReaderChanges($reader); */
367 374
 
368
-        $response = array();
375
+        $response = array('todo');
369 376
 
370 377
         return $this->json($response);
371 378
     }
@@ -848,8 +855,14 @@ class Track2004Controller extends AbstractController
848 855
             return ;
849 856
         }
850 857
 
858
+        // Traitement de la requete json
859
+		if (0 === strpos($request->headers->get('Content-Type'), 'application/json')) {
860
+			$data = json_decode($request->getContent(), true);
861
+			$request->request->replace(is_array($data) ? $data : array());
862
+		}
863
+
851 864
         //1. Récuppération du type de la requête envoyée par l'API
852
-        $typeURL = $_REQUEST ['request'];
865
+        $typeURL = $_REQUEST['request'];
853 866
 
854 867
         // 2. Récuppération du plannode
855 868
         // Décryptage de la requête
@@ -961,13 +974,13 @@ class Track2004Controller extends AbstractController
961 974
      *
962 975
      * @return NULL|CMIArray
963 976
      */
964
-    protected function getCMIFromRequest()
977
+    protected function getCMIFromRequest(Request $request)
965 978
     {
966
-        if (! isset($_REQUEST['cmi'])) {
979
+        if (empty($request->request->get('cmi'))) {
967 980
             return null;
968 981
         }
969 982
 
970
-        $cmiData = $_REQUEST['cmi'];
983
+        $cmiData = $request->request->get('cmi');
971 984
         if (! is_array($cmiData)) {
972 985
             return null;
973 986
         }
@@ -981,13 +994,13 @@ class Track2004Controller extends AbstractController
981 994
      *
982 995
      * @return NULL|CMIArray
983 996
      */
984
-    protected function getADLFromRequest()
997
+    protected function getADLFromRequest(Request $request)
985 998
     {
986
-        if (!isset($_REQUEST['adl'])) {
999
+        if (empty($request->request->get('adl'))) {
987 1000
             return null;
988 1001
         }
989 1002
 
990
-        $adlData = $_REQUEST['adl'];
1003
+        $adlData = $request->request->get('adl');
991 1004
         if (!is_array($adlData)) {
992 1005
             return null;
993 1006
         }

+ 15
- 16
Entity/Scorm2004/Scorm2004MapTrackObjective.php View File

@@ -74,8 +74,7 @@ class Scorm2004MapTrackObjective
74 74
     protected $scorm2004Track;
75 75
 
76 76
     /**
77
-     * @ORM\ManyToOne(targetEntity="Scorm2004Objective", inversedBy="scorm2004MapTrackObjectives")
78
-     * @ORM\JoinColumn(name="objective_fk", referencedColumnName="objective_id", nullable=false)
77
+     * @var string
79 78
      */
80 79
     protected $scorm2004Objective;
81 80
 
@@ -110,7 +109,7 @@ class Scorm2004MapTrackObjective
110 109
      * Set the value of success_status.
111 110
      *
112 111
      * @param string $success_status
113
-     * @return Logipro\Logipro\Bundle\SCORMBundleSCORMLogipro\Bundle\SCORMBundle\Entity\Scorm2004\Scorm2004MapTrackObjective
112
+     * @return Logipro\Bundle\SCORMBundle\Entity\Scorm2004\Scorm2004MapTrackObjective
114 113
      */
115 114
     public function setSuccessStatus($success_status)
116 115
     {
@@ -133,7 +132,7 @@ class Scorm2004MapTrackObjective
133 132
      * Set the value of completion_status.
134 133
      *
135 134
      * @param string $completion_status
136
-     * @return Logipro\Logipro\Bundle\SCORMBundleSCORMLogipro\Bundle\SCORMBundle\Entity\Scorm2004\Scorm2004MapTrackObjective
135
+     * @return Logipro\Bundle\SCORMBundle\Entity\Scorm2004\Scorm2004MapTrackObjective
137 136
      */
138 137
     public function setCompletionStatus($completion_status)
139 138
     {
@@ -156,7 +155,7 @@ class Scorm2004MapTrackObjective
156 155
      * Set the value of progress_measure.
157 156
      *
158 157
      * @param float $progress_measure
159
-     * @return Logipro\Logipro\Bundle\SCORMBundleSCORMLogipro\Bundle\SCORMBundle\Entity\Scorm2004\Scorm2004MapTrackObjective
158
+     * @return Logipro\Bundle\SCORMBundle\Entity\Scorm2004\Scorm2004MapTrackObjective
160 159
      */
161 160
     public function setProgressMeasure($progress_measure)
162 161
     {
@@ -179,7 +178,7 @@ class Scorm2004MapTrackObjective
179 178
      * Set the value of score_scaled.
180 179
      *
181 180
      * @param float $score_scaled
182
-     * @return Logipro\Logipro\Bundle\SCORMBundleSCORMLogipro\Bundle\SCORMBundle\Entity\Scorm2004\Scorm2004MapTrackObjective
181
+     * @return Logipro\Bundle\SCORMBundle\Entity\Scorm2004\Scorm2004MapTrackObjective
183 182
      */
184 183
     public function setScoreScaled($score_scaled)
185 184
     {
@@ -202,7 +201,7 @@ class Scorm2004MapTrackObjective
202 201
      * Set the value of score_raw.
203 202
      *
204 203
      * @param float $score_raw
205
-     * @return Logipro\Logipro\Bundle\SCORMBundleSCORMLogipro\Bundle\SCORMBundle\Entity\Scorm2004\Scorm2004MapTrackObjective
204
+     * @return Logipro\Bundle\SCORMBundle\Entity\Scorm2004\Scorm2004MapTrackObjective
206 205
      */
207 206
     public function setScoreRaw($score_raw)
208 207
     {
@@ -225,7 +224,7 @@ class Scorm2004MapTrackObjective
225 224
      * Set the value of score_min.
226 225
      *
227 226
      * @param float $score_min
228
-     * @return Logipro\Logipro\Bundle\SCORMBundleSCORMLogipro\Bundle\SCORMBundle\Entity\Scorm2004\Scorm2004MapTrackObjective
227
+     * @return Logipro\Bundle\SCORMBundle\Entity\Scorm2004\Scorm2004MapTrackObjective
229 228
      */
230 229
     public function setScoreMin($score_min)
231 230
     {
@@ -248,7 +247,7 @@ class Scorm2004MapTrackObjective
248 247
      * Set the value of score_max.
249 248
      *
250 249
      * @param float $score_max
251
-     * @return Logipro\Logipro\Bundle\SCORMBundleSCORMLogipro\Bundle\SCORMBundle\Entity\Scorm2004\Scorm2004MapTrackObjective
250
+     * @return Logipro\Bundle\SCORMBundle\Entity\Scorm2004\Scorm2004MapTrackObjective
252 251
      */
253 252
     public function setScoreMax($score_max)
254 253
     {
@@ -270,8 +269,8 @@ class Scorm2004MapTrackObjective
270 269
     /**
271 270
      * Set Scorm2004Track entity (many to one).
272 271
      *
273
-     * @param Logipro\Logipro\Bundle\SCORMBundleSCORMLogipro\Bundle\SCORMBundle\Entity\Scorm2004\Scorm2004Track $scorm2004Track
274
-     * @return Logipro\Logipro\Bundle\SCORMBundleSCORMLogipro\Bundle\SCORMBundle\Entity\Scorm2004\Scorm2004MapTrackObjective
272
+     * @param Logipro\Bundle\SCORMBundle\Entity\Scorm2004\Scorm2004Track $scorm2004Track
273
+     * @return Logipro\Bundle\SCORMBundle\Entity\Scorm2004\Scorm2004MapTrackObjective
275 274
      */
276 275
     public function setScorm2004Track(Scorm2004Track $scorm2004Track = null)
277 276
     {
@@ -283,7 +282,7 @@ class Scorm2004MapTrackObjective
283 282
     /**
284 283
      * Get Scorm2004Track entity (many to one).
285 284
      *
286
-     * @return Logipro\Logipro\Bundle\SCORMBundleSCORMLogipro\Bundle\SCORMBundle\Entity\Scorm2004\Scorm2004Track
285
+     * @return Logipro\Bundle\SCORMBundle\Entity\Scorm2004\Scorm2004Track
287 286
      */
288 287
     public function getScorm2004Track()
289 288
     {
@@ -293,10 +292,10 @@ class Scorm2004MapTrackObjective
293 292
     /**
294 293
      * Set Scorm2004Objective entity (many to one).
295 294
      *
296
-     * @param Logipro\Logipro\Bundle\SCORMBundleSCORMLogipro\Bundle\SCORMBundle\Entity\Scorm2004\Scorm2004Objective $scorm2004Objective
297
-     * @return Logipro\Logipro\Bundle\SCORMBundleSCORMLogipro\Bundle\SCORMBundle\Entity\Scorm2004\Scorm2004MapTrackObjective
295
+     * @param string $scorm2004Objective
296
+     * @return Logipro\Bundle\SCORMBundle\Entity\Scorm2004\Scorm2004MapTrackObjective
298 297
      */
299
-    public function setScorm2004Objective(Scorm2004Objective $scorm2004Objective = null)
298
+    public function setScorm2004Objective(string $scorm2004Objective = null)
300 299
     {
301 300
         $this->scorm2004Objective = $scorm2004Objective;
302 301
 
@@ -306,7 +305,7 @@ class Scorm2004MapTrackObjective
306 305
     /**
307 306
      * Get Scorm2004Objective entity (many to one).
308 307
      *
309
-     * @return Logipro\Logipro\Bundle\SCORMBundleSCORMLogipro\Bundle\SCORMBundle\Entity\Scorm2004\Scorm2004Objective
308
+     * @return string
310 309
      */
311 310
     public function getScorm2004Objective()
312 311
     {

+ 28
- 0
Entity/Scorm2004/Scorm2004Track.php View File

@@ -96,6 +96,11 @@ class Scorm2004Track
96 96
      */
97 97
     protected $registrationAttempt;
98 98
 
99
+    /**
100
+     * @var Logipro\Bundle\SCORMBundle\Entity\Learner
101
+     */
102
+    protected $learner;
103
+
99 104
     /**
100 105
      *
101 106
      * @var ArrayCollection
@@ -490,6 +495,29 @@ class Scorm2004Track
490 495
         return $this->registrationAttempt;
491 496
     }
492 497
 
498
+    /**
499
+     * Set Learner entity (many to one).
500
+     *
501
+     * @param Logipro\Bundle\SCORMBundle\Entity\Learner $learner
502
+     * @return \Logipro\Bundle\SCORMBundle\Entity\Scorm2004\Scorm2004Track
503
+     */
504
+    public function setLearner(Learner $learner)
505
+    {
506
+        $this->learner = $learner;
507
+
508
+        return $this;
509
+    }
510
+
511
+    /**
512
+     * Get Learner entity (many to one).
513
+     *
514
+     * @return Logipro\Bundle\SCORMBundle\Entity\Learner
515
+     */
516
+    public function getLearner()
517
+    {
518
+        return $this->learner;
519
+    }
520
+
493 521
     /**
494 522
      * Add Scorm2004Comment entity to collection (one to many).
495 523
      *

+ 0
- 1
LearningModels/SCORM2004/SequencingNavigation/SeqNavRequest.php View File

@@ -306,7 +306,6 @@ class SeqNavRequest implements ContainerAwareInterface
306 306
 
307 307
             // On évalue le processus de rollup sur la progression de l'item par la mesure
308 308
             $itemMethodByMeasureApplied = $this->evaluateItemProgressRollupUsingMeasure($item);
309
-
310 309
             // Si la méthode ne s'applique pas, on applique la méthode se basant sur les règles
311 310
             if (!$itemMethodByMeasureApplied) {
312 311
                 $this->evaluateItemProgressRollupUsingRules($item);

+ 6
- 6
Resources/config/doctrine/Scorm2004.Scorm2004Interaction.orm.xml View File

@@ -11,12 +11,12 @@
11 11
     <field name="identifier" type="string" column="identifier" length="255" nullable="false"/>
12 12
     <field name="type" type="string" column="type" length="50" nullable="false"/>
13 13
     <field name="weighting" type="float" column="weighting" nullable="false"/>
14
-    <field name="result" type="string" column="result" length="50" nullable="false"/>
15
-    <field name="description" type="text" column="description" nullable="false"/>
16
-    <field name="student_response" type="text" column="student_response" nullable="false"/>
17
-    <field name="correct_responses" type="text" column="correct_responses" nullable="false"/>
18
-    <field name="time" type="datetime" column="time" nullable="false"/>
19
-    <field name="latency" type="float" column="latency" nullable="false"/>
14
+    <field name="result" type="string" column="result" length="50" nullable="true"/>
15
+    <field name="description" type="text" column="description" nullable="true"/>
16
+    <field name="student_response" type="text" column="student_response" nullable="true"/>
17
+    <field name="correct_responses" type="text" column="correct_responses" nullable="true"/>
18
+    <field name="time" type="datetime" column="time" nullable="true"/>
19
+    <field name="latency" type="float" column="latency" nullable="true"/>
20 20
     
21 21
     <!-- item sur lequel l'essai est tenté -->
22 22
     <field name="itemIdentifier" type="string" column="item_identifier" length="255" nullable="false"/>

+ 7
- 0
Resources/config/doctrine/Scorm2004.Scorm2004Track.orm.xml View File

@@ -70,6 +70,13 @@
70 70
         <join-column name="registration_attempt_fk" referenced-column-name="registration_attempt_id" nullable=""/>
71 71
       </join-columns>
72 72
     </many-to-one>
73
+
74
+    <!-- apprenant auquel le track est lié -->
75
+    <many-to-one field="learner" target-entity="Logipro\Bundle\SCORMBundle\Entity\Learner" inversed-by="scorm2004Tracks" fetch="LAZY">
76
+      <join-columns>
77
+        <join-column name="learner_fk" referenced-column-name="learner_id" nullable="true"/>
78
+      </join-columns>
79
+    </many-to-one>
73 80
   
74 81
   </entity>
75 82
 </doctrine-mapping>

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

@@ -10,7 +10,7 @@
10 10
             <argument></argument> <!-- will be filled in with content_url_prefix dynamically -->
11 11
             <argument type="service" id="session"/>
12 12
         </service>
13
-        <service id="scorm.services.engine" alias="Logipro\Bundle\SCORMBundle\Services\ScormEngine"/>
13
+        <service id="scorm.services.engine" alias="Logipro\Bundle\SCORMBundle\Services\ScormEngine" public="true" />
14 14
 
15 15
         <service id="Logipro\Bundle\SCORMBundle\EntityListener\Scorm2004ObjectiveProgressInformationListener" class="Logipro\Bundle\SCORMBundle\EntityListener\Scorm2004ObjectiveProgressInformationListener" public="false">
16 16
             <argument type="service" id="Logipro\Bundle\SCORMBundle\Services\Scorm2004ObjectiveProgressInfoManager"/>

+ 33
- 5
Resources/public/js/scorm2004.js View File

@@ -424,7 +424,21 @@ ScormApi.prototype.processRequest = (function (){
424 424
 			redirection.item = item;
425 425
 		}
426 426
 
427
-		$.post(this.ajaxURLRedirection, redirection, success, 'text');
427
+		//$.post(this.ajaxURLRedirection, redirection, success, 'text');
428
+
429
+		var xhr = new XMLHttpRequest();
430
+		xhr.open('POST', this.ajaxURLRedirection, false);
431
+		xhr.setRequestHeader('Content-Type', 'application/json');
432
+		xhr.onload = function() {
433
+   			if (xhr.status === 200) {
434
+				this.printConsoleLog('Redirection OK');
435
+				this.success();
436
+    		}
437
+    		else if (xhr.status !== 200) {
438
+        		this.printConsoleLog('Redirection failed.  Returned status of ' + xhr.status);
439
+    		}
440
+		};
441
+		xhr.send(JSON.stringify(redirection));
428 442
 	}
429 443
 });
430 444
 
@@ -514,7 +528,7 @@ ScormApi.prototype.LMSGetValue = (function(param){
514 528
 
515 529
 	} catch (err) {
516 530
 		this.printConsoleLog("erreur dans la fonction getValue : dans myGet ");
517
-		this.logDebug(param + ' >> ???');
531
+		this.printConsoleLog(param + ' >> ???');
518 532
 		this.setError(err.code);
519 533
 
520 534
 		return "";
@@ -694,14 +708,28 @@ ScormApi.prototype.LMSCommit = (function() {
694 708
 	this.printConsoleLog("Les données à commiter... ");
695 709
 	this.printConsoleLog(commit);
696 710
 
697
-	$.ajax({
711
+	/* $.ajax({
698 712
 		  type: 'POST',
699 713
 		  url: this.ajaxURL,
700 714
 		  data: commit,
701 715
 		  async:false,
702 716
 		  success: commitCallback,
703 717
 		  dataType: 'json'
704
-		});
718
+		}); */
719
+
720
+	var xhr = new XMLHttpRequest();
721
+	xhr.open('POST', this.ajaxURL, false);
722
+	xhr.setRequestHeader('Content-Type', 'application/json');
723
+	xhr.onload = function() {
724
+		if (xhr.status === 200) {
725
+			this.printConsoleLog('Commit OK');
726
+			this.commitCallback();
727
+		}
728
+		else if (xhr.status !== 200) {
729
+			this.printConsoleLog('Commit failed.  Returned status of ' + xhr.status);
730
+		}
731
+	};
732
+	xhr.send(JSON.stringify(commit));
705 733
 
706 734
 	this.setError(gNoError);
707 735
 
@@ -1853,7 +1881,7 @@ ScormApi.prototype.printConsoleLog = (function(message) {
1853 1881
 });
1854 1882
 
1855 1883
 
1856
-ScormApi.prototype.logDebug = (function(str) {
1884
+ScormApi.prototype.printConsoleLog = (function(str) {
1857 1885
 	if (this.debugMode) {
1858 1886
 		if (typeof console !== 'object') {
1859 1887
 			return;

+ 239
- 15
Services/ScormEngine.php View File

@@ -9,6 +9,9 @@ use Logipro\Bundle\SCORMBundle\Entity\MapCourseZipfile;
9 9
 use Logipro\Bundle\SCORMBundle\Entity\Registration;
10 10
 use Logipro\Bundle\SCORMBundle\Entity\RegistrationAttempt;
11 11
 use Logipro\Bundle\SCORMBundle\Entity\ZipFile;
12
+use Logipro\Bundle\SCORMBundle\Entity\Scorm2004\Scorm2004Track;
13
+use Logipro\Bundle\SCORMBundle\Entity\Scorm2004\Scorm2004MapTrackItem;
14
+use Logipro\Bundle\SCORMBundle\Entity\Scorm2004\Scorm2004AttemptProgressInformation;
12 15
 use Logipro\Bundle\SCORMBundle\LearningModels\DOMSCORM12;
13 16
 use Logipro\Bundle\SCORMBundle\LearningModels\DOMSCORM2004;
14 17
 use Logipro\Bundle\SCORMBundle\Package\Common\PackageTypeDetector;
@@ -101,7 +104,7 @@ class ScormEngine implements ContainerAwareInterface
101 104
 
102 105
             if ($course) {
103 106
                 $response['code'] = 400;
104
-                $response['error'] = 'La clef de cours existe déjà. Utilser \'updateCourse\' pour mettre à jours un cours existant';
107
+                $response['error'] = 'La clef de cours existe déjà. Utilser \'updateCourse\' pour mettre à jour un cours existant';
105 108
                 return $response;
106 109
             }
107 110
 
@@ -330,6 +333,94 @@ class ScormEngine implements ContainerAwareInterface
330 333
         return $response;
331 334
     }
332 335
 
336
+    /**
337
+     * Copie un cours à partir d'un cours existant
338
+     *
339
+     * @param string $orginalCourseKey
340
+     * @param string $newCourseKey
341
+     * @param bool $analyse
342
+     * @param string $versioningRule
343
+     *
344
+     * @return array
345
+     */
346
+    public function duplicateCourse(string $orginalCourseKey, string $newCourseKey)
347
+    {
348
+        // Création de la structure de la réponse
349
+        $response = array(
350
+            'code' => 200,
351
+            'isSuccessfullyCreated' => false,
352
+            'error' => '',
353
+            'course' => array(
354
+                'courseKey' => '',
355
+                'maxVersion' => 0,
356
+                'versioningRule' => ''
357
+            )
358
+        );
359
+
360
+        // Contrôle que la clef du cours existant est fournie
361
+        if (empty($orginalCourseKey)) {
362
+            $response['code'] = 400;
363
+            $response['error'] = 'La clef d\'un cours existant à dupliquer est requise.';
364
+            return $response;
365
+        }
366
+
367
+        // Contrôle que la clef du nouveau cours est fournie
368
+        if (empty($newCourseKey)) {
369
+            $response['code'] = 400;
370
+            $response['error'] = 'La clef du nouveau cours dupliqué est requise.';
371
+            return $response;
372
+        }
373
+        
374
+        // Contrôle de l'existence du cours à dupliquer
375
+        $originalCourse = $this->requireCourse($orginalCourseKey);
376
+
377
+        if (empty($originalCourse)) {
378
+            $response['code'] = 400;
379
+            $response['error'] = 'Le cours que vous souhaitez dupliquer est inexistant.';
380
+            return $response;
381
+        }
382
+
383
+        // Contrôle de la disponibilité de la clef pour le nouveau cours
384
+        $newCourse = $this->requireCourse($newCourseKey);
385
+
386
+        if ($newCourse) {
387
+            $response['code'] = 400;
388
+            $response['error'] = 'La clef du nouveau cours existe déjà. Utilser \'updateCourse\' pour mettre à jour un cours existant.';
389
+            return $response;
390
+        }
391
+
392
+        // Récupération de l'entity manager
393
+        $em = $this->getDoctrine()->getManager();
394
+        
395
+        // COURS
396
+        $newCourse = clone $originalCourse;
397
+        $newCourse->setCourseKey($newCourseKey);
398
+        $newCourse->setMaxVersion(1);
399
+        $em->persist($newCourse);
400
+
401
+        // Récupération de l'objet Zip
402
+        $mappingRepository = $em->getRepository(MapCourseZipfile::class);
403
+        $originalMapping = $mappingRepository->findOneBy(array('course' => $originalCourse), array('mapCourseZipfileId' => 'desc'));
404
+        $zipFile = $originalMapping->getZipFile();
405
+
406
+        // Mapping Zip/Cours
407
+        $mapping = new MapCourseZipfile();
408
+        $mapping->setCourse($newCourse);
409
+        $mapping->setZipFile($zipFile);
410
+        $mapping->setVersion($newCourse->getMaxVersion());
411
+             
412
+        $em->persist($mapping);
413
+        $em->flush();
414
+
415
+        // Réponse
416
+        $response['course']['courseKey'] = $newCourse->getCourseKey();
417
+        $response['course']['maxVersion'] = $newCourse->getMaxVersion();
418
+        $response['course']['versioningRule'] = $newCourse->getVersionRule();
419
+        $response['isSuccessfullyCreated'] = true;
420
+
421
+        return $response;
422
+    }
423
+
333 424
     /**
334 425
      * Remplace la règle de versionning d'un cours
335 426
      *
@@ -425,6 +516,18 @@ class ScormEngine implements ContainerAwareInterface
425 516
      */
426 517
     public function createLearner(string $learnerKey, string $familyName, string $givenName)
427 518
     {
519
+        // Création de la structure de la réponse
520
+        $response = array(
521
+            'code' => 400,
522
+            'isAlreadyExisting' => false,
523
+            'error' => '',
524
+            'learner' => array(
525
+                'learnerKey' => '',
526
+                'familyName' => '',
527
+                'givenName' => ''
528
+            )
529
+        );
530
+
428 531
         if (!empty($learnerKey)) {
429 532
             $learner = $this->requireLearner($learnerKey);
430 533
 
@@ -438,12 +541,19 @@ class ScormEngine implements ContainerAwareInterface
438 541
 
439 542
                 $em->persist($learner);
440 543
                 $em->flush();
441
-
442
-                return $learner->getLearnerId();
544
+            } else {
545
+                $response['isAlreadyExisting'] = true;
443 546
             }
547
+
548
+            $response['code'] = 200;
549
+            $response['learner']['learnerKey'] = $learner->getLearnerKey();
550
+            $response['learner']['familyName'] = $learner->getFamilyName();
551
+            $response['learner']['givenName'] = $learner->getGivenName();
552
+        } else {
553
+            $response['error'] = 'La clef d\'identification est necessaire';
444 554
         }
445 555
         
446
-        return null;
556
+        return $response;
447 557
     }
448 558
 
449 559
     /**
@@ -530,27 +640,49 @@ class ScormEngine implements ContainerAwareInterface
530 640
      */
531 641
     public function createRegistration(string $registrationKey, string $courseKey, string $learnerKey)
532 642
     {
643
+        // Création de la structure de la réponse
644
+        $response = array(
645
+            'code' => 400,
646
+            'isAlreadyExisting' => false,
647
+            'error' => '',
648
+            'registration' => array(
649
+                'registrationKey' => '',
650
+                'courseKey' => '',
651
+                'learnerKey' => ''
652
+            )
653
+        );
654
+
533 655
         if (!empty($registrationKey)) {
534 656
             $registration = $this->requireRegistration($registrationKey);
535 657
             $course = $this->requireCourse($courseKey);
536 658
             $learner = $this->requireLearner($learnerKey);
537 659
 
538
-            if (empty($registration) && $course && $learner) {
539
-                $em = $this->getDoctrine()->getManager();
540
-
541
-                $registration = new Registration();
542
-                $registration->setRegistrationKey($registrationKey);
543
-                $registration->setCourse($course);
544
-                $registration->setLearner($learner);
660
+            if ($course && $learner) {
661
+                if (empty($registration)) {
662
+                    $em = $this->getDoctrine()->getManager();
545 663
 
546
-                $em->persist($registration);
547
-                $em->flush();
664
+                    $registration = new Registration();
665
+                    $registration->setRegistrationKey($registrationKey);
666
+                    $registration->setCourse($course);
667
+                    $registration->setLearner($learner);
548 668
 
549
-                return $registration->getRegistrationKey();
669
+                    $em->persist($registration);
670
+                    $em->flush();
671
+                } else {
672
+                    $response['isAlreadyExisting'] = true;
673
+                }
674
+                $response['code'] = 200;
675
+                $response['registration']['registrationKey'] = $registration->getRegistrationKey();
676
+                $response['registration']['courseKey'] = $registration->getCourse();
677
+                $response['registration']['learnerKey'] = $registration->getLearner();
678
+            } else {
679
+                $response['error'] = 'Le cours et l\'apprenant doivent exister';
550 680
             }
681
+        } else {
682
+            $response['error'] = 'La clef d\'identification est necessaire';
551 683
         }
552 684
         
553
-        return null;
685
+        return $response;
554 686
     }
555 687
 
556 688
     /**
@@ -642,6 +774,98 @@ class ScormEngine implements ContainerAwareInterface
642 774
         return $variables;
643 775
     }
644 776
 
777
+    /**
778
+     * Récupération de la complétion d'une activité
779
+     *
780
+     * @param string $registrationKey
781
+     */
782
+    public function getCompletion(string $registrationKey)
783
+    {
784
+        $em = $this->getDoctrine()->getManager();
785
+        
786
+        // Vérification de l'existance de l'inscription
787
+        $registration = $this->requireRegistration($registrationKey);
788
+        if (empty($registration)) {
789
+            return 0;
790
+        }
791
+        
792
+        // Récupération du dernier essai pour cette inscription
793
+        $registrationAttemptRepository = $em->getRepository(RegistrationAttempt::class);
794
+        $lastAttempt = $registrationAttemptRepository->findOneBy(array('registration' => $registration), array('registrationAttemptId' => 'desc'));
795
+
796
+// DETECTER AVANT LE TYPE DE SCORM POUR SAVOIR QUEL STANDARD
797
+// CODE SCORM 2004
798
+        // On récupère le track correspondant
799
+        $track2004Repository = $em->getRepository(Scorm2004Track::class);
800
+        $track2004 = $track2004Repository->findOneBy(array('registrationAttempt' => $lastAttempt));
801
+        if (empty($track2004)) {
802
+            return 0;
803
+        }
804
+
805
+/*      // Récupération du DOM afin d'avoir des infos sur les items
806
+        $packageFolder = $this->container->getParameter('logipro_scorm.package_folder');
807
+        $domScorm2004 = $lastAttempt->getDOM($packageFolder); */
808
+
809
+        // Dans un premier temps on détermine si la complétion peut être remontée
810
+        // en se basant sur l'état de complétion de l'ensemble des items terminaux
811
+        
812
+        $mapTrackItemRepository = $em->getRepository(Scorm2004MapTrackItem::class);
813
+        $attemptItemRepository = $em->getRepository(Scorm2004AttemptProgressInformation::class);
814
+        
815
+        $mapTrackItems = $mapTrackItemRepository->findBy(array('scorm2004Track' => $track2004));
816
+
817
+        if (!empty($mapTrackItems)) {
818
+            $numCompletedItems = 0;
819
+            $numFinalItems = 0;
820
+            foreach ($mapTrackItems as $item) {
821
+                // Si les items sont terminaux
822
+                if ($item->getAvailableOrder() > -1) {
823
+                    $numFinalItems ++;
824
+                    $identifier = $item->getItemIdentifier();
825
+                    $attemptItem = $attemptItemRepository->findOneBy(array('scorm2004Track'=> $track2004, 'item_identifier' => $identifier), array('attempt_id' => 'desc'));
826
+                    if (!empty($attemptItem)) {
827
+                        $progressStatus = $attemptItem->getProgressStatus();
828
+                        $completionStatus = $attemptItem->getCompletionStatus();
829
+                        if (true == $progressStatus && true == $completionStatus) {
830
+                            $numCompletedItems ++;
831
+                        }
832
+                    }
833
+                }
834
+            }
835
+
836
+            if ($numFinalItems != 0) {
837
+                $completion = 100.0 * ($numCompletedItems / $numFinalItems);
838
+                $completion = round($completion, 2);
839
+                // Si on obtient une valeur de complétion elle est retournée
840
+                if ($completion > 0) {
841
+                    return $completion;
842
+                }
843
+            }
844
+        }
845
+
846
+        // Si aucune complétion n'a été déterminée précédement on controle que l'on aie pas un taux de complétion présent au niveau de l'organisation
847
+        $organization = $track2004->getOrganizationId();
848
+        if (empty($organization)) {
849
+            return 0;
850
+        }
851
+
852
+        $lastOrganizationAttempt = $attemptItemRepository->findOneBy(array('scorm2004Track'=> $track2004, 'item_identifier' => $organization), array('attempt_id' => 'desc'));
853
+        if (empty($lastOrganizationAttempt)) {
854
+            return 0;
855
+        }
856
+
857
+        $completionAmount = $lastOrganizationAttempt->getCompletionAmount();
858
+        if ($completionAmount > 0) {
859
+            return round(100.0 * $completionAmount, 2);
860
+        }
861
+
862
+        $progressStatus = $attelastOrganizationAttemptmptItem->getProgressStatus();
863
+        $completionStatus = $lastOrganizationAttempt->getCompletionStatus();
864
+        if (true == $progressStatus && true == $completionStatus) {
865
+            return 100;
866
+        }
867
+    }
868
+
645 869
     /**
646 870
      * supprime une inscription
647 871
      *

+ 8
- 6
Tools/UnicodeTools.php View File

@@ -7,14 +7,16 @@ class UnicodeTools
7 7
 
8 8
     public static function strToUTF8($value)
9 9
     {
10
-        $encoding = self::getEncoding($value);
11
-
12
-        if ($encoding == 'UTF-8') {
13
-            return $value;
10
+        if (!empty($value)) {
11
+            $encoding = self::getEncoding($value);
12
+
13
+            if ($encoding == 'UTF-8') {
14
+                return $value;
15
+            }
16
+            
17
+            $value = @mb_convert_encoding($value, 'UTF-8', $encoding);
14 18
         }
15 19
         
16
-        $value = @mb_convert_encoding($value, 'UTF-8', $encoding);
17
-        
18 20
         return $value;
19 21
     }
20 22
 

Loading…
Cancel
Save