$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 = [])
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;
}
/**
+ * @param $path
+ * @return null
* @throws \Exception
*/
public function compile($path)
{
$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'];
}
/**
+ * @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\>(.*)\<\/title\>/U', '<title>' . htmlspecialchars($this->entry->title) . '</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)
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();
$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]);
}
{{-- __('!! 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'=>'<strong>'.$server['name'].'</strong>']).' <span class="small"><span class="grey">'.$server['base_url'].'</span>'.$entry->install->path.'</span>',
- ];
- }
- }
-
- 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'=>'<strong>'.$server['name'].'</strong>']).' <span class="small"><span class="grey">'.$server['base_url'].'</span>'.$entry->install->path.'</span>',
+ ];
+ }
+ }
}
@endphp
<a class="btn btn-sm btn-link exportcollection" href="#"