From f9ddef25a92e8a631467ed45c0219154dd23ed19 Mon Sep 17 00:00:00 2001 From: Vincent Vanwaelscappel Date: Wed, 8 Dec 2021 18:53:38 +0100 Subject: [PATCH] wait #4949 @2 --- app/Jobs/FluidbookCollectionDownload.php | 69 +++++++++++++----------- app/Models/FluidbookCollection.php | 2 + app/SubForms/Fluidbook_Setting.php | 17 ++++++ 3 files changed, 58 insertions(+), 30 deletions(-) create mode 100644 app/SubForms/Fluidbook_Setting.php diff --git a/app/Jobs/FluidbookCollectionDownload.php b/app/Jobs/FluidbookCollectionDownload.php index 101c63300..0dc348373 100644 --- a/app/Jobs/FluidbookCollectionDownload.php +++ b/app/Jobs/FluidbookCollectionDownload.php @@ -39,6 +39,7 @@ class FluidbookCollectionDownload implements ShouldQueue */ protected $action; + /** * @param $collection FluidbookCollection * @param $user User @@ -71,13 +72,18 @@ class FluidbookCollectionDownload implements ShouldQueue $url = url('storage/collection/download/' . $fname); - $subject = __('Collection :nb prête au téléchargement', ['nb' => $this->collection->id]); + $subject = __('Collection ":title" (#:nb) prête au téléchargement', ['title' => $this->collection->title, 'nb' => $this->collection->id]); $body = __('Le fichier est disponible à l\'adresse suivante : :url', ['url' => $url]); - if ($this->action === 'scormcloud') { - $scormURL = $this->sendToSCORMCloud($url); + try { + if ($this->action === 'scormcloud') { + $scormURL = $this->sendToSCORMCloud($dest); + $body .= "

"; + $body .= __('La collection peut être testée sur SCORM Cloud : :url', ['url' => $scormURL]); + } + } catch (\Exception $e) { $body .= "

"; - $body .= __('La collection peut être testée sur SCORM Cloud : :url', ['url' => $scormURL]); + $body .= __('Une erreur s\'est produite lors de l\'envoi sur SCORM Cloud : :error', ['error' => $e->getMessage()]); } @@ -119,6 +125,18 @@ class FluidbookCollectionDownload implements ShouldQueue return $ws; } + protected function getCollectionGlobalSettings() + { + + $options = []; + foreach ($this->collection->getPageData()->override_settings as $setting) { + $options[$setting['key']] = $setting['value']; + } + + return $options; + } + + /** * @throws \Exception */ @@ -137,8 +155,7 @@ class FluidbookCollectionDownload implements ShouldQueue $countries[$fbid] = $metadata->settings->country; } - - $options = []; + $options = $this->getCollectionGlobalSettings(); if ($data->locale_switch) { $multilang = []; @@ -185,9 +202,9 @@ class FluidbookCollectionDownload implements ShouldQueue } } - $manifestContent=file_get_contents($manifestFile); - $manifestContent=preg_replace('/\(.*)\<\/title\>/U',''.htmlspecialchars($this->collection->title).'',$manifestContent); - file_put_contents($manifestFile,$manifestContent); + $manifestContent = file_get_contents($manifestFile); + $manifestContent = preg_replace('/\(.*)\<\/title\>/U', '' . htmlspecialchars($this->collection->title) . '', $manifestContent); + file_put_contents($manifestFile, $manifestContent); $redirectionScript = " @@ -243,7 +260,7 @@ window.location='./' + locale + '/index.html'; { $ws = $this->_getws2(); - $options = []; + $options = $this->getCollectionGlobalSettings(); $zipmerge = in_array($data->version, ['online', 'scorm', 'sharepoint', 'precompiled', 'win_exe_html', 'win_html', 'win_cd_html', 'mac_exe_html']); foreach ($data->publications as $publication) { @@ -267,7 +284,7 @@ window.location='./' + locale + '/index.html'; } } - public function sendToSCORMCloud($url) + public function sendToSCORMCloud($file) { $config = new ScormCloud\Configuration(); $appId = env('SCORM_CLOUD_APP_ID'); @@ -277,28 +294,20 @@ window.location='./' + locale + '/index.html'; $courseId = 'toolbox_collection_' . $this->collection->getKey(); $courseAPI = new ScormCloud\Api\CourseApi(); - $request = new ScormCloud\Model\ImportFetchRequestSchema(['url' => $url, 'content_type' => 'application/zip', 'media_file_metadata' => ['title' => $this->collection->title]]); - while (true) { - try { - $jobId = $courseAPI->createFetchAndImportCourseJob($courseId, $request, true); - break; - } catch (\Exception $e) { - sleep(1); - } + + try { + $courseAPI->deleteCourse($courseId); + } catch (\Exception $e) { + } - while (true) { - try { - $jobResult = $courseAPI->getImportJobStatus($jobId->getResult()); + $jobId = $courseAPI->createUploadAndImportCourseJob($courseId, true, null, 'application/zip', null, new \SplFileObject($file)); - if ($jobResult->getStatus() == ScormCloud\Model\ImportJobResultSchema::STATUS_RUNNING) { - sleep(1); - } else { - break; - } - } catch (\Exception $e) { - sleep(1); - } + + $jobResult = $courseAPI->getImportJobStatus($jobId->getResult()); + while ($jobResult->getStatus() == ScormCloud\Model\ImportJobResultSchema::STATUS_RUNNING) { + sleep(1); + $jobResult = $courseAPI->getImportJobStatus($jobId->getResult()); } if ($jobResult->getStatus() == ScormCloud\Model\ImportJobResultSchema::STATUS_ERROR) diff --git a/app/Models/FluidbookCollection.php b/app/Models/FluidbookCollection.php index 3ee1f578e..965f48b8d 100644 --- a/app/Models/FluidbookCollection.php +++ b/app/Models/FluidbookCollection.php @@ -6,6 +6,7 @@ use App\Fields\FluidbookExportVersion; use App\Fields\User; use App\Http\Controllers\Admin\Operations\FluidbookCollection\DownloadOperation; use App\SubForms\CollectionPublication; +use App\SubForms\Fluidbook_Setting; use Cubist\Backpack\Magic\Fields\BunchOfFieldsMultiple; use Cubist\Backpack\Magic\Fields\Checkbox; use Cubist\Backpack\Magic\Fields\SelectFromArray; @@ -54,6 +55,7 @@ class FluidbookCollection extends CubistMagicAbstractModel $this->addField('locale_switch', Checkbox::class, __('Permettre le changement de langue'), ['when' => ['type' => 'scorm_multilang'], 'default' => true]); $this->addField('version', FluidbookExportVersion::class, __('Version'), ['when' => ['type' => 'export']]); $this->addField('publications', BunchOfFieldsMultiple::class, __('Publications'), ['bunch' => CollectionPublication::class]); + $this->addField('override_settings',BunchOfFieldsMultiple::class,__('Redéfinir les paramètres lors de l\'export'),['bunch'=>Fluidbook_Setting::class]); } diff --git a/app/SubForms/Fluidbook_Setting.php b/app/SubForms/Fluidbook_Setting.php new file mode 100644 index 000000000..5b25ddc8a --- /dev/null +++ b/app/SubForms/Fluidbook_Setting.php @@ -0,0 +1,17 @@ +addField('key', Text::class, __('Nom du paramètre')); + $this->addField('value', Textarea::class, __('Valeur')); + } +} -- 2.39.5