From: Vincent Vanwaelscappel Date: Thu, 30 Mar 2023 14:45:12 +0000 (+0200) Subject: wait #5840 @1.5 X-Git-Url: http://git.cubedesigners.com/?a=commitdiff_plain;h=41d544c6ccff7d3e9f7985fcb68a1b11a8c14f3e;p=fluidbook-toolbox.git wait #5840 @1.5 --- diff --git a/app/Console/Commands/FluidbookCollection.php b/app/Console/Commands/FluidbookCollection.php index 4ae7550ff..ce8aa4d0a 100644 --- a/app/Console/Commands/FluidbookCollection.php +++ b/app/Console/Commands/FluidbookCollection.php @@ -19,8 +19,8 @@ class FluidbookCollection extends CubistCommand public function handle() { PHP::neverStop(true); - $fluidbook = \App\Models\FluidbookCollection::find($this->argument('id')); - $job = new FluidbookCollectionDownload($fluidbook, $this->argument('action'), User::withoutGlobalScope('ownerclause')->findOrFail(5)); + $collection = \App\Models\FluidbookCollection::find($this->argument('id')); + $job = new FluidbookCollectionDownload($collection, $this->argument('action'), User::withoutGlobalScope('ownerclause')->findOrFail(5)); $job->handle(); } } diff --git a/app/Jobs/DownloadBase.php b/app/Jobs/DownloadBase.php index 28015d768..365f12b68 100644 --- a/app/Jobs/DownloadBase.php +++ b/app/Jobs/DownloadBase.php @@ -52,19 +52,9 @@ class DownloadBase extends Base $this->action = $action; } - public function sendNotification($subject, $text, $actions = []) + public function sendNotification($subject, $text, $actions = [], $showTextIfNotEmail = false) { - $this->getUser()->notify(new DownloadReady($subject, $text, $actions)); -// -// -// if ($this->getUser()->slack) { -// if ($this->sendSlack($subject, $text, $actions)) { -// return; -// } -// } -// -// // Fallback email if -// $this->sendEmail($subject, $text, $actions); + $this->getUser()->notify(new DownloadReady($subject, $text, $actions, $showTextIfNotEmail)); } public function sendSlack($subject, $text, $actions = []) diff --git a/app/Jobs/FluidbookCollectionDownload.php b/app/Jobs/FluidbookCollectionDownload.php index 7713aada9..0ad90dde9 100644 --- a/app/Jobs/FluidbookCollectionDownload.php +++ b/app/Jobs/FluidbookCollectionDownload.php @@ -6,6 +6,7 @@ use App\Fluidbook\Packager\Packager; use App\Models\FluidbookPublication; use App\Models\User; use App\Services\WorkshopV2; +use Cubist\Backpack\Magic\PageData; use Cubist\Util\CommandLine\Rsync; use Cubist\Util\Files\Files; use Cubist\Util\PHP; @@ -45,6 +46,8 @@ class FluidbookCollectionDownload extends DownloadBase } /** + * @param $path + * @return null * @throws \Exception */ public function compile($path) @@ -67,7 +70,7 @@ class FluidbookCollectionDownload extends DownloadBase { $options = []; foreach ($this->entry->getPageData()->override_settings as $setting) { - if (!$setting['key']) { + if (!$setting || !isset($setting['key']) || !$setting['key']) { continue; } $options[$setting['key']] = $setting['value']; @@ -77,14 +80,98 @@ class FluidbookCollectionDownload extends DownloadBase } /** + * @param $data PageData + * @param $path string + * @return void * @throws \Exception */ + protected function compileSCORMMultilang($data, $path) { - return $this->compileSCORM($data, $path, true); + $ws = $this->_getws2(); + $langs = []; + $countries = []; + + $defaultFlags = ['en' => 'gb', 'sv' => 'se']; + + foreach ($data->publications as $publication) { + $fbid = $publication['fluidbook']; + $metadata = $ws->getMetadata($fbid); + $langs[$fbid] = $metadata->lang; + $countries[$fbid] = $metadata->settings->country; + } + + $options = $this->getCollectionGlobalSettings(); + $options['scorm_enable'] = true; + + + if (count($data->publications) >= 2) { + if ($data->locale_switch) { + $multilang = []; + foreach ($langs as $fbid => $lang) { + if ($countries[$fbid]) { + $flag = $countries[$fbid]; + } else { + if (strlen($lang) === 5) { + $flag = substr($lang, 3, 2); + } else if (isset($defaultFlags[$lang])) { + $flag = $defaultFlags[$lang]; + } else { + $flag = $lang; + } + } + $multilang[] = $lang . ',' . strtolower($flag) . ',../' . $lang . '/index.html'; + } + $options['multilang'] = implode("\n", $multilang); + $options['multilangDisplay'] = 'lang'; + } else { + $options['multilang'] = ''; + } + + foreach ($data->publications as $publication) { + $fbid = $publication['fluidbook']; + $lang = $langs[$fbid]; + $dir = $path . '/' . $lang; + $ws->installBook($fbid, $dir, $options, 'scorm', 3); + } + + if (in_array('en', $langs)) { + $default = 'en'; + } else { + $default = $langs[0]; + } + + $manifestFile = $path . '/imsmanifest.xml'; + foreach ($langs as $lang) { + $manifest = $path . '/' . $lang . '/imsmanifest.xml'; + if ($lang === $default) { + rename($manifest, $manifestFile); + } else if (file_exists($manifest)) { + unlink($manifest); + } + } + + $manifestContent = file_get_contents($manifestFile); + $manifestContent = preg_replace('/\(.*)\<\/title\>/U', '' . htmlspecialchars($this->entry->title) . '', $manifestContent); + file_put_contents($manifestFile, $manifestContent); + + $redirectionScript = self::getRedirectScript($langs, $default); + + file_put_contents($path . '/index.html', $redirectionScript); + } else { + foreach ($data->publications as $publication) { + $fbid = $publication['fluidbook']; + $dir = $path; + $ws->installBook($fbid, $dir, $options, 'scorm', 3); + break; + } + } } /** + * @param $data PageData + * @param $path string + * @return void * @throws \Exception */ protected function compileMultilang($data, $path, $scorm = false) @@ -229,6 +316,19 @@ class FluidbookCollectionDownload extends DownloadBase return $done === $nbjobs; } + protected function _getws2() + { + $ws = new WorkshopV2(); + $ws->login($this->user->email, $this->user->api_token); + return $ws; + } + + /** + * @param $data PageData + * @param $path string + * @return void + * @throws \Exception + */ protected function compileExport($data, $path) { $ws = $this->_getws2(); diff --git a/app/Models/FluidbookCollection.php b/app/Models/FluidbookCollection.php index 61932e830..c48efe445 100644 --- a/app/Models/FluidbookCollection.php +++ b/app/Models/FluidbookCollection.php @@ -37,7 +37,7 @@ class FluidbookCollection extends ToolboxModel $this->addField('locale_switch', Checkbox::class, __('Permettre le changement de langue'), ['when' => ['type' => ['scorm_multilang', 'export_multilang']], 'default' => true]); $this->addField('version', FluidbookExportVersion::class, __('Version'), ['when' => ['type' => 'export']]); $this->addField('publications', BunchOfFieldsMultiple::class, __('Publications'), ['bunch' => CollectionPublication::class, 'edit_label' => '%fluidbook > %dir']); - $this->addField('install', ExternalPath::class, 'Installer sur un serveur externe', ['default' => '', 'fake' => true, 'translatable' => false, 'store_in' => 'settings', 'servers_model' => FluidbookExternalInstallServer::class]); + $this->addField('install', ExternalPath::class, 'Installer sur un serveur externe', ['default' => '', 'fake' => true, 'translatable' => false, 'store_in' => 'settings', 'servers_model' => FluidbookExternalInstallServer::class, ['when' => ['type' => ['export', 'export_multilang']]]]); $this->addField('override_settings', BunchOfFieldsMultiple::class, __('Redéfinir les paramètres lors de l\'export'), ['bunch' => Fluidbook_Setting::class]); } diff --git a/resources/views/vendor/backpack/crud/buttons/fluidbook_collection/download.blade.php b/resources/views/vendor/backpack/crud/buttons/fluidbook_collection/download.blade.php index 5cd9b4550..cca55965e 100644 --- a/resources/views/vendor/backpack/crud/buttons/fluidbook_collection/download.blade.php +++ b/resources/views/vendor/backpack/crud/buttons/fluidbook_collection/download.blade.php @@ -1,21 +1,26 @@ {{-- __('!! Collections de fluidbooks') --}} @php - $v=$entry->version?:'online'; - $servers=\App\Models\FluidbookExternalInstallServer::getAllServers(); - $vname=\App\Fields\FluidbookExportVersion::getVersions()[$v]['short']; - $actions=['download'=>__('Télécharger la version :version',['version'=>$vname])]; - if($entry->install && $entry->install->server && isset($servers[$entry->install->server])){ - $server=$servers[$entry->install->server]; - if($entry->install->path || $server['allows_root']){ - $actions['install']=[ - 'label'=>__('Installer sur le serveur :server',['server'=>''.$server['name'].'']).' '.$server['base_url'].''.$entry->install->path.'', - ]; - } - } - - if($entry->type==='scorm_multilang'){ + if($entry->type==='export'){ + $v=$entry->version?:'online'; + $vname=\App\Fields\FluidbookExportVersion::getVersions()[$v]['short']; + $actions=['export'=>__('Télécharger la version :version',['version'=>$vname])]; + }else if($entry->type==='scorm_multilang'){ + $actions['export']=__('Télécharger'); $actions['scormcloud']=__('Tester sur Scorm Cloud'); + }else if($entry->type==='export_multilang'){ + $actions['export']=__('Télécharger'); + } + if($entry->type==='export' || $entry->type==='export_multilang'){ + $servers=\App\Models\FluidbookExternalInstallServer::getAllServers(); + if($entry->install && $entry->install->server && isset($servers[$entry->install->server])){ + $server=$servers[$entry->install->server]; + if($entry->install->path || $server['allows_root']){ + $actions['install']=[ + 'label'=>__('Installer sur le serveur :server',['server'=>''.$server['name'].'']).' '.$server['base_url'].''.$entry->install->path.'', + ]; + } + } } @endphp