1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192 |
- <?php
-
- namespace Logipro\Bundle\SCORMBundle\Package;
-
- use Logipro\Bundle\SCORMBundle\LearningModels\DOMSCORM;
- use Logipro\Bundle\SCORMBundle\LearningModels\DOMLearningModel;
- use Logipro\Bundle\SCORMBundle\Tools\TimeTools;
-
- class PackageValidator
- {
- /**
- * Méthode outil premettant de valider un paquet e-learning
- * le standard est défini et la validation adéquat appliquée
- *
- * @param string $zipPath
- *
- * @return array
- */
- public static function validatePackage($zipPath)
- {
- $response = array(
- 'standard' => null,
- 'title' => null,
- 'duration' => null,
- 'validation' => null
- );
-
- // Identification du standard
- // Accès au contenu du zip
- $zip = new \ZipArchive();
- $result = $zip->open($zipPath);
-
- if ($result !== true) {
- $response['validation'] = array(
- 'status' => false,
- 'error' => sprintf("L'ouverture du ZIP a échoué avec le code : %d", $result)
- );
- return $response;
- }
-
- // Dans un premier temps on ne considère que SCORM
- // On recherche donc un fichier 'imsmanifest.xml'
-
- // Récupération du manifest
- $manifest = $zip->getFromName('imsmanifest.xml');
- $zip->close();
- $zipName = pathinfo($zipPath)['filename'];
-
- if ($manifest !== false) {
- // SCORM - Définition du standard et création du parser (objet DOM)
- $standard = DOMSCORM::defineStandard($manifest);
- $dom = DOMLearningModel::getInstance($zipName, $manifest, $standard);
- } else {
- // Si pas de imsmanifest.xml --> possible autre standard
- $response['validation'] = array(
- 'status' => false,
- 'error' => 'Standard non géré ou manifest absent'
- );
- return $response;
- }
-
- // Si standard identifié, on peut passé à la validation du xml
- if ($dom) {
- $response['standard'] = $standard;
- $response['title'] = $dom->getTitle();
- $response['duration'] = '';
- // Récupération de la balise durée (métadonnée)
- $typicalLearningTime = $dom->getTypicalLearningTime();
- if (!empty($typicalLearningTime)) {
- if (array_key_exists('duration', $typicalLearningTime)) {
- $isoDuration = $typicalLearningTime['duration'];
- $duration = TimeTools::convertIso8601DurationToSeconds($isoDuration);
- $response['duration'] = $duration;
- }
- }
-
- // @TODO Validation XML reportée
- // $response['validation'] = $dom->validate();
- $response['validation'] = array(
- 'status' => true
- );
- } else {
- $response['validation'] = array(
- 'status' => false,
- 'error' => 'Standard non géré'
- );
- return $response;
- }
-
- return $response;
- }
- }
|