Browse Source

TLD-507 Ajout de la gestion de callback

Mael ETIENNE 3 years ago
parent
commit
3f91cdcaf2

+ 8
- 0
ClientAPI/ApiScorm2004.php View File

@@ -532,6 +532,14 @@ EOT;
532 532
 
533 533
         $apiString .= $cmiStructure;
534 534
         $apiString .= $scorm2004;
535
+
536
+        $ajaxCallbackPath = $this->container->getParameter('logipro_scorm.ajax_callback');
537
+        $ajaxCallback = file_get_contents($ajaxCallbackPath);
538
+        if (!empty($ajaxCallback)) {
539
+            $apiString .= $ajaxCallback;
540
+        }
541
+        
542
+        
535 543
         
536 544
         $apiString.=<<<EOT
537 545
 //=================================================//

+ 11
- 12
Controller/Track2004Controller.php View File

@@ -13,7 +13,9 @@ use Logipro\Bundle\SCORMBundle\Entity\Scorm2004\Scorm2004MapTrackItem;
13 13
 use Logipro\Bundle\SCORMBundle\Entity\Scorm2004\Scorm2004Note;
14 14
 use Logipro\Bundle\SCORMBundle\Entity\Scorm2004\Scorm2004ObjectiveProgressInformation;
15 15
 use Logipro\Bundle\SCORMBundle\Entity\Scorm2004\Scorm2004Track;
16
+use Logipro\Bundle\SCORMBundle\LearningModels\DOMSCORM2004;
16 17
 use Logipro\Bundle\SCORMBundle\Player\SCORM2004\CMIArray;
18
+use Logipro\Bundle\SCORMBundle\Player\SCORM2004\Scorm2004PlayerView;
17 19
 use Logipro\Bundle\SCORMBundle\Tools\TimeTools;
18 20
 use Logipro\Bundle\SCORMBundle\Tools\UnicodeTools;
19 21
 use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
@@ -364,15 +366,12 @@ class Track2004Controller extends AbstractController
364 366
         // On flush toutes les données persistées jusqu'à maintenant
365 367
         $em->flush();
366 368
 
367
-// A FAIRE
368
-        // Récupération des modifications du lecteur
369
-        /* $reader = new AGOReaderSCORM2004View($node);
370
-        $reader->setUser($idStudent);
371
-        $reader->setActivite($idActivite);
372 369
 
373
-        $response = $this->getReaderChanges($reader); */
374
-
375
-        $response = array('todo');
370
+        // Récupération des modifications du lecteur pour la réponse ajax
371
+        $packageFolder = $this->container->getParameter('logipro_scorm.package_folder');
372
+        $dom = $registrationAttempt->getDOM($packageFolder);
373
+        $playerView = new Scorm2004PlayerView($this->container, $dom, $track, $registrationKey, $organization, $item);
374
+        $response = $playerView->getNavResponse();
376 375
 
377 376
         return $this->json($response);
378 377
     }
@@ -856,10 +855,10 @@ class Track2004Controller extends AbstractController
856 855
         }
857 856
 
858 857
         // 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
-		}
858
+        if (0 === strpos($request->headers->get('Content-Type'), 'application/json')) {
859
+            $data = json_decode($request->getContent(), true);
860
+            $request->request->replace(is_array($data) ? $data : array());
861
+        }
863 862
 
864 863
         //1. Récuppération du type de la requête envoyée par l'API
865 864
         $typeURL = $_REQUEST['request'];

+ 5
- 0
DependencyInjection/Configuration.php View File

@@ -28,6 +28,11 @@ class Configuration implements ConfigurationInterface
28 28
                     ->cannotBeEmpty()
29 29
                     ->defaultValue('/content')
30 30
                 ->end()
31
+                ->scalarNode('ajax_callback')
32
+                    ->isRequired()
33
+                    ->cannotBeEmpty()
34
+                    ->defaultValue('/assets/exclusive/js/ajax_callback.js')
35
+                ->end()
31 36
             ->end()
32 37
         ;
33 38
 

+ 1
- 0
DependencyInjection/LogiproSCORMExtension.php View File

@@ -20,6 +20,7 @@ class LogiproSCORMExtension extends Extension
20 20
         $container->setParameter('logipro_scorm.package_folder', $config['package_folder']);
21 21
         $container->setParameter('logipro_scorm.content_folder', $config['content_folder']);
22 22
         $container->setParameter('logipro_scorm.content_url_prefix', $config['content_url_prefix']);
23
+        $container->setParameter('logipro_scorm.ajax_callback', $config['ajax_callback']);
23 24
 
24 25
         $definition = $container->getDefinition('Logipro\Bundle\SCORMBundle\Services\ScormEngine');
25 26
         $definition->replaceArgument(0, $config['package_folder']);

+ 2
- 2
LearningModels/SCORM2004/SequencingNavigation/SequencingRequest.php View File

@@ -887,9 +887,9 @@ class SequencingRequest extends SeqNavRequest
887 887
      *
888 888
      * @param string $identifiedItem
889 889
      * @param string $traversalDirection sens de circulation dans l'arbre
890
-     * @return string
890
+     * @return string|bool
891 891
      */
892
-    protected function getChoiceItemException($identifiedItem, $traversalDirection): mixed
892
+    protected function getChoiceItemException($identifiedItem, $traversalDirection)
893 893
     {
894 894
         // Dans le cas d'un déplacement vers l'avant
895 895
         // On vérifie que les règle de séquencage du item ne valide pas l'action 'stop'

+ 10
- 0
Player/SCORM2004/Scorm2004PlayerView.php View File

@@ -81,6 +81,16 @@ class Scorm2004PlayerView implements ContainerAwareInterface
81 81
         return $this->response;
82 82
     }
83 83
 
84
+    public function getNavResponse()
85
+    {
86
+        $this->response['player']['current'] = $this->getCurrent();
87
+        $this->response['player']['toc'] = $this->getToc();
88
+        $this->response['player']['previous'] = $this->getNavigationAction(SCORM2004_HIDE_LMS_UI_PREVIOUS);
89
+        $this->response['player']['next'] = $this->getNavigationAction(SCORM2004_HIDE_LMS_UI_CONTINUE);
90
+        
91
+        return $this->response;
92
+    }
93
+
84 94
     /**
85 95
      * Initialise le tableau d'information concernant les controles de navigation
86 96
      */

+ 14
- 65
Resources/public/js/scorm2004.js View File

@@ -424,20 +424,17 @@ ScormApi.prototype.processRequest = (function (){
424 424
 			redirection.item = item;
425 425
 		}
426 426
 
427
-		//$.post(this.ajaxURLRedirection, redirection, success, 'text');
428
-
429 427
 		var xhr = new XMLHttpRequest();
430
-		xhr.open('POST', this.ajaxURLRedirection, false);
431
-		xhr.setRequestHeader('Content-Type', 'application/json');
432 428
 		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
-    		}
429
+			if (xhr.status === 200) {
430
+				console.log('Redirection OK');
431
+				success(xhr.responseText);
432
+			} else if (xhr.status !== 200) {
433
+				console.log('Redirection failed.  Returned status of ' + xhr.status);
434
+			}
440 435
 		};
436
+		xhr.open('POST', this.ajaxURLRedirection, false);
437
+		xhr.setRequestHeader('Content-Type', 'application/json');
441 438
 		xhr.send(JSON.stringify(redirection));
442 439
 	}
443 440
 });
@@ -704,31 +701,19 @@ ScormApi.prototype.LMSCommit = (function() {
704 701
 	commit.cmi    = this.cmi;
705 702
 	commit.adl    = this.adl;
706 703
 
707
-
708 704
 	this.printConsoleLog("Les données à commiter... ");
709 705
 	this.printConsoleLog(commit);
710 706
 
711
-	/* $.ajax({
712
-		  type: 'POST',
713
-		  url: this.ajaxURL,
714
-		  data: commit,
715
-		  async:false,
716
-		  success: commitCallback,
717
-		  dataType: 'json'
718
-		}); */
719
-
720 707
 	var xhr = new XMLHttpRequest();
721
-	xhr.open('POST', this.ajaxURL, false);
722
-	xhr.setRequestHeader('Content-Type', 'application/json');
723
-	xhr.onload = function() {
708
+	xhr.onload  = function() {
724 709
 		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);
710
+			scormBundleCommitCallback(xhr.response);
711
+		} else {
712
+			console.log('Commit failed.  Returned status of ' + xhr.status);
730 713
 		}
731 714
 	};
715
+	xhr.open('POST', this.ajaxURL, false);
716
+	xhr.setRequestHeader('Content-Type', 'application/json');
732 717
 	xhr.send(JSON.stringify(commit));
733 718
 
734 719
 	this.setError(gNoError);
@@ -737,28 +722,6 @@ ScormApi.prototype.LMSCommit = (function() {
737 722
 	return 'true';
738 723
 });
739 724
 
740
-
741
-function commitCallback(result)
742
-{
743
-	//console.log(result);
744
-
745
-	// // Désactiver le click sur les liens
746
-	// $("a").off("click", onNavigationControlClick);
747
-
748
-	// // Table des matières
749
-	// $("#TableOfContents").replaceWith(result.toc);
750
-	// // Bouton Précédent
751
-	// $(".Control--Prev").replaceWith(result.prev);
752
-	// // Bouton Suivant
753
-	// $(".Control--Next").replaceWith(result.next);
754
-
755
-	// // Rappel le framework foundation afin de mettre à jour la nouvelle table des matières
756
-	// $(document).foundation();
757
-
758
-	// // réactiver le click sur les potentiels nouveaux éléments
759
-	// $("a").on("click", onNavigationControlClick);
760
-}
761
-
762 725
 /**
763 726
  * Fonction qui permet de convertir la duré en seconde.
764 727
  */
@@ -1867,20 +1830,6 @@ ScormApi.prototype.setError = (function(errorCode) {
1867 1830
 });
1868 1831
 
1869 1832
 
1870
-
1871
-ScormApi.prototype.printConsoleLog = (function(message) {
1872
-
1873
-	if (this.debugMode)
1874
-	{
1875
-		if (typeof console !== 'object')
1876
-		{
1877
-			return;
1878
-		}
1879
-		console.log(message);
1880
-	}
1881
-});
1882
-
1883
-
1884 1833
 ScormApi.prototype.printConsoleLog = (function(str) {
1885 1834
 	if (this.debugMode) {
1886 1835
 		if (typeof console !== 'object') {

Loading…
Cancel
Save