use Cubist\Util\PHP;
use Cubist\Util\Str;
use Cubist\Util\Zip;
+use GuzzleHttp\Exception\RequestException;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Queue\SerializesModels;
use Illuminate\Support\Facades\Mail;
use InvalidArgumentException;
+use Psr\Http\Message\ResponseInterface;
use RusticiSoftware\Cloud\V2 as ScormCloud;
try {
if ($this->action === 'scormcloud') {
- $scormURL = $this->sendToSCORMCloud($dest);
+ $scormURL = $this->sendToSCORMCloud($url);
$body .= "<br><br>";
$body .= __('La collection peut être testée sur SCORM Cloud : <a href=":url">:url</a>', ['url' => $scormURL]);
}
} catch (\Exception $e) {
$body .= "<br><br>";
- $body .= __('Une erreur s\'est produite lors de l\'envoi sur SCORM Cloud : :error', ['error' => $e->getMessage()]);
+ $body .= __('Une erreur s\'est produite lors de l\'envoi sur SCORM Cloud (App ID :appid) : :error', ['error' => $e->getMessage(), 'appid' => env('SCORM_CLOUD_APP_ID')]);
}
}
$options = $this->getCollectionGlobalSettings();
+ $options['scorm_enable'] = true;
- 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];
+ if (count($data->publications) >= 2) {
+
+ if ($data->locale_switch) {
+ $multilang = [];
+ foreach ($langs as $fbid => $lang) {
+ if ($countries[$fbid]) {
+ $flag = $countries[$fbid];
} else {
- $flag = $lang;
+ 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';
}
- $multilang[] = $lang . ',' . strtolower($flag) . ',../' . $lang . '/index.html';
+ $options['multilang'] = implode("\n", $multilang);
+ $options['multilangDisplay'] = 'lang';
+ } else {
+ $options['multilang'] = '';
}
- $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];
- }
+ foreach ($data->publications as $publication) {
+ $fbid = $publication['fluidbook'];
+ $lang = $langs[$fbid];
+ $dir = $path . '/' . $lang;
+ $ws->installBook($fbid, $dir, $options, 'scorm', 3);
+ }
- $manifestFile = $path . '/imsmanifest.xml';
- foreach ($langs as $lang) {
- $manifest = $path . '/' . $lang . '/imsmanifest.xml';
- if ($lang === $default) {
- rename($manifest, $manifestFile);
+ if (in_array('en', $langs)) {
+ $default = 'en';
} else {
- unlink($manifest);
+ $default = $langs[0];
}
- }
- $manifestContent = file_get_contents($manifestFile);
- $manifestContent = preg_replace('/\<title\>(.*)\<\/title\>/U', '<title>' . htmlspecialchars($this->collection->title) . '</title>', $manifestContent);
- file_put_contents($manifestFile, $manifestContent);
+ $manifestFile = $path . '/imsmanifest.xml';
+ foreach ($langs as $lang) {
+ $manifest = $path . '/' . $lang . '/imsmanifest.xml';
+ if ($lang === $default) {
+ rename($manifest, $manifestFile);
+ } else {
+ unlink($manifest);
+ }
+ }
+
+ $manifestContent = file_get_contents($manifestFile);
+ $manifestContent = preg_replace('/\<title\>(.*)\<\/title\>/U', '<title>' . htmlspecialchars($this->collection->title) . '</title>', $manifestContent);
+ file_put_contents($manifestFile, $manifestContent);
- $redirectionScript = "<html>
+ $redirectionScript = "<html>
<head></head>
<body>
<script type=\"text/javascript\">
</body>
</html>";
- file_put_contents($path . '/index.html', $redirectionScript);
+ 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;
+ }
+ }
}
protected function compileExport($data, $path)
}
}
- public function sendToSCORMCloud($file)
+ public function sendToSCORMCloud($url)
{
$config = new ScormCloud\Configuration();
$appId = env('SCORM_CLOUD_APP_ID');
}
- $jobId = $courseAPI->createUploadAndImportCourseJob($courseId, true, null, 'application/zip', null, new \SplFileObject($file));
+ $request = new ScormCloud\Model\ImportFetchRequestSchema(['url' => $url, 'content_type' => 'application/zip']);
+ $promise = $courseAPI->createFetchAndImportCourseJobAsync($courseId, $request, true);
+ $jobId = $promise->wait();
-
- $jobResult = $courseAPI->getImportJobStatus($jobId->getResult());
+ for ($i = 0; $i <= 20; $i++) {
+ try {
+ $jobResult = $courseAPI->getImportJobStatus($jobId->getResult());
+ break;
+ } catch (\Exception $e) {
+ sleep(10);
+ }
+ }
while ($jobResult->getStatus() == ScormCloud\Model\ImportJobResultSchema::STATUS_RUNNING) {
sleep(1);
$jobResult = $courseAPI->getImportJobStatus($jobId->getResult());
}
- if ($jobResult->getStatus() == ScormCloud\Model\ImportJobResultSchema::STATUS_ERROR)
+ if ($jobResult->getStatus() == ScormCloud\Model\ImportJobResultSchema::STATUS_ERROR) {
throw new InvalidArgumentException('Course is not properly formatted: ' . $jobResult->getMessage());
+ }
return 'https://cloud.scorm.com/sc/user/Course?appId=' . $appId . '&courseId=' . $courseId;
}