// __('La collection ":title" est prêt au téléchargement');
protected $_text = 'La collection ":title" est prêt au téléchargement';
+ protected $fluidbooks = [];
+ protected $dirs = [];
+ protected $langs = [];
+ protected $countries = [];
+
public function handle()
{
*/
protected function compileMultilang($data, $path, $scorm = false)
{
- $langs = [];
- $countries = [];
-
- $defaultFlags = ['en' => 'gb', 'sv' => 'se', 'zh' => 'cn', 'el' => 'gr'];
-
- $fluidbooks = [];
+ $optionsFluidbooks = [];
foreach ($data->publications as $publication) {
$fbid = $publication['fluidbook'];
- $fluidbooks[$fbid] = FluidbookPublication::syncPublicationFromWorkshop($fbid);
- $langs[$fbid] = $fluidbooks[$fbid]->locale;
- $countries[$fbid] = $fluidbooks[$fbid]->country;
- $devices[$fbid] = $fluidbooks[$fbid]->mobileNavigationType === 'mobilefirst' ? 'mf' : 'd';
+ $this->fluidbooks[$fbid] = FluidbookPublication::syncPublicationFromWorkshop($fbid);
+ $this->langs[$fbid] = $this->fluidbooks[$fbid]->locale;
+ $this->countries[$fbid] = $this->fluidbooks[$fbid]->country;
+ $this->devices[$fbid] = $this->fluidbooks[$fbid]->mobileNavigationType === 'mobilefirst' ? 'mf' : 'd';
+ $optionsFluidbooks[$fbid] = [];
}
// We have at least one desktop and one mobile first
- $multipleDevices = count(array_unique($devices)) > 1;
+ $multipleDevices = count(array_unique($this->devices)) > 1;
$options = $this->getCollectionGlobalSettings();
$options['scorm_enable'] = $scorm;
// We don't want an hybrid fluidbook in a collection
$options['mobilefirstFluidbookId'] = '';
- // Switch is disabled for multidevices packages
- if (!$multipleDevices && $data->locale_switch) {
- $multilang = [];
- foreach ($langs as $fbid => $lang) {
- if ($countries[$fbid]) {
- $flag = $countries[$fbid];
+ // Get all available version and install directories
+ $versionsByLanguage = [];
+ $versionsByDevice = [];
+ $allVersions = [];
+ foreach ($this->fluidbooks as $fbid => $publication) {
+ $dir = $this->langs[$fbid];
+ if ($multipleDevices) {
+ $dir .= '_' . $this->devices[$fbid];
+ if (!isset($versionsByDevice[$this->devices[$fbid]])) {
+ $versionsByDevice[$this->devices[$fbid]] = [];
+ }
+ if (!isset($versionsByLanguage[$this->langs[$fbid]])) {
+ $versionsByLanguage[$this->langs[$fbid]] = [];
+ }
+ $versionsByDevice[$this->devices[$fbid]][$this->langs[$fbid]] = $dir;
+ $versionsByLanguage[$this->langs[$fbid]][$this->devices[$fbid]] = $dir;
+ } else {
+ $versionsByLanguage[$this->langs[$fbid]] = $dir;
+ }
+ $allVersions[] = $dir;
+ $this->dirs[$fbid] = $dir;
+ }
+
+ if ($data->locale_switch) {
+ if (!$multipleDevices) {
+ $options['multilang'] = $this->_getMultilangOptions($this->fluidbooks);
+ } else {
+ if ($data->redirection_algorithm === 'language') {
+ foreach ($this->fluidbooks as $fbid => $publication) {
+ $optionsFluidbooks[$fbid]['multilang'] = $this->getLanguageMultilangOptions($fbid);
+ }
} else {
- if (strlen($lang) === 5) {
- $flag = substr($lang, 3, 2);
- } else if (isset($defaultFlags[$lang])) {
- $flag = $defaultFlags[$lang];
- } else {
- $flag = $lang;
+ foreach ($this->fluidbooks as $fbid => $publication) {
+ $optionsFluidbooks[$fbid]['multilang'] = $this->getDeviceMultilangOptions($fbid);
}
}
- $multilang[] = $lang . ',' . strtolower($flag) . ',../' . $lang . '/index.html';
}
- $options['multilang'] = implode("\n", $multilang);
$options['multilangDisplay'] = 'lang';
} else {
$options['multilang'] = '';
}
$jobs = [];
- $versionsByLanguage = [];
- $versionsByDevice = [];
- $allVersions = [];
- foreach ($fluidbooks as $fbid => $publication) {
- $dir = $langs[$fbid];
- if ($multipleDevices) {
- $dir .= '_' . $devices[$fbid];
- if (!isset($versionsByDevice[$devices[$fbid]])) {
- $versionsByDevice[$devices[$fbid]] = [];
- }
- if (!isset($versionsByLanguage[$langs[$fbid]])) {
- $versionsByLanguage[$langs[$fbid]] = [];
- }
- $versionsByDevice[$devices[$fbid]][$langs[$fbid]] = $dir;
- $versionsByLanguage[$langs[$fbid]][$devices[$fbid]] = $dir;
- } else {
- $versionsByLanguage[$langs[$fbid]] = $dir;
+ foreach ($this->fluidbooks as $fbid => $publication) {
+ $fbOptions = $options;
+ if (isset($optionsFluidbooks[$fbid])) {
+ $fbOptions += $optionsFluidbooks[$fbid];
}
- $allVersions[] = $dir;
- $jobs[] = $this->_jobDownloadFluidbook($fbid, $scorm ? 'scorm' : 'online', $path . $dir, $options);
+ $jobs[] = $this->_jobDownloadFluidbook($fbid, $scorm ? 'scorm' : 'online', $path . $this->dirs[$fbid], $fbOptions);
}
$this->_waitJobs($jobs);
- if (in_array('en', $langs)) {
+ if (in_array('en', $this->langs)) {
$default = 'en';
} else {
- $default = $langs[0];
+ $default = $this->langs[0];
}
if ($scorm) {
file_put_contents($path . '/index.html', $redirectScript);
}
+
+ protected function getLanguageMultilangOptions($fbid)
+ {
+ $device = $this->devices[$fbid];
+ $sameDevice = [];
+ $otherDevice = [];
+ foreach ($this->fluidbooks as $k => $v) {
+ if ($this->devices[$k] === $device) {
+ $sameDevice[$this->langs[$k]] = $k;
+ } else {
+ $otherDevice[$this->langs[$k]] = $k;
+ }
+ }
+ foreach ($otherDevice as $lang => $fbid) {
+ if (isset($sameDevice[$lang])) {
+ continue;
+ }
+ $sameDevice[$lang] = $fbid;
+ }
+ $fluidbooks = [];
+ foreach ($sameDevice as $lang => $fbid) {
+ $fluidbooks[$fbid] = $this->fluidbooks[$fbid];
+ }
+ return $this->_getMultilangOptions($fluidbooks);
+ }
+
+ protected function getDeviceMultilangOptions($fbid)
+ {
+ $device = $this->devices[$fbid];
+ $fluidbooks = [];
+ foreach ($this->fluidbooks as $k => $v) {
+ if ($this->devices[$k] === $device) {
+ $fluidbooks[$k] = $v;
+ }
+ }
+ return $this->_getMultilangOptions($fluidbooks);
+ }
+
+ protected function _getMultilangOptions($fluidbooks)
+ {
+ $defaultFlags = ['en' => 'gb', 'sv' => 'se', 'zh' => 'cn', 'el' => 'gr'];
+
+ $multilang = [];
+ foreach ($fluidbooks as $fbid => $publication) {
+ $lang = $this->langs[$fbid];
+ if ($this->countries[$fbid]) {
+ $flag = $this->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) . ',../' . $this->dirs[$fbid] . '/index.html';
+ }
+ if (count($multilang) <= 1) {
+ return '';
+ }
+ return implode("\n", $multilang);
+ }
+
protected function package($fbid, $version, $options, $path)
{
$packager = Packager::package($fbid, $version, false, true, $options);
}
$name .= '.exe';
- $job = $this->_jobDownloadFluidbook($fbid, $this->entry->version, $compilepath . $name, $options);
+ $job = $this->_jobDownloadFluidbook($fbid, $this->entry->version, $compilepath . $name, $options, false);
$jobs['Fluidbook #' . $fbid] = $job;
$res['Fluidbook #' . $fbid] = url('fluidbook-collection/' . $this->entry->id . '/downloadfile/' . $rand . '/' . $name);