public function __construct($quiz, $dest, $forceScorm = false)
{
- $this->quiz = Quiz::withoutGlobalScopes()->find($quiz);
+ $this->quiz = $quiz instanceof Quiz ? $quiz : Quiz::withoutGlobalScopes()->find($quiz);
$this->theme = $this->quiz->getTheme();
$this->compilePath = protected_path('quiz/compile/' . $this->quiz->id);
$this->dest = $dest;
namespace App\Http\Controllers\Admin\Operations\Quiz;
+use App\Fields\SCORMVersion;
+use App\Http\Middleware\CheckIfAdmin;
use App\Jobs\QuizDownload;
+use App\Models\FluidbookPublication;
use App\Models\Quiz;
+use Cubist\Backpack\Http\Controllers\Base\XSendFileController;
+use Cubist\Scorm\Version;
use Illuminate\Support\Facades\Route;
use Prologue\Alerts\Facades\Alert;
{
protected function setupDownloadRoutes($segment, $routeName, $controller)
{
- Route::match(['get'], $segment . '/{id}/download/{action}', $controller . '@download');
+ Route::match(['get'], $segment . '/{id}/package/{action}/{version?}', $controller . '@package');
+ Route::match(['get'], $segment . '/{id}_{hash}/download/{file}', $controller . '@download')->withoutMiddleware([CheckIfAdmin::class]);;
}
protected function setupDownloadDefaults()
$this->crud->addButtonFromView('line', 'download', 'quiz.download', 'end');
}
- protected function download($id, $action)
+ protected function package($id, $action, $version = null)
{
- QuizDownload::dispatch(Quiz::find($id), $action, backpack_user())->onQueue('download');;
+ if (!Quiz::hasPermission($id, 'read')) {
+ abort(401);
+ }
+ $quiz = Quiz::withoutGlobalScopes()->find($id);
+ $version = $version ?? $quiz->scorm_version;
+ QuizDownload::dispatch($quiz, $action, $version, backpack_user())->onQueue('download');;
Alert::add('success', __('La compilation a été placée en file d\'attente. Vous recevrez un email lorsqu\'elle sera terminée.'))->flash();
return redirect(backpack_url('quiz'));
}
+
+ protected function download($id, $hash, $file)
+ {
+ $quiz = Quiz::withoutGlobalScopes()->where('id', $id)->where('hash', $hash)->first();
+ if (null === $quiz) {
+ abort(404, __('Ce fichier est indisponible'));
+ }
+ $path = protected_path('quiz/download/' . $id . '/' . $file);
+ if (!file_exists($path)) {
+ abort(404, __('Le fichier n\'existe pas'));
+ }
+ return XSendFileController::sendfile($path);
+ }
}
* @param $action string
* @param $user User
*/
- public function __construct($entry, $action, $user=null)
+ public function __construct($entry, $action, $user = null)
{
$this->entry = $entry;
$this->setUser($user);
protected function _dest($fname)
{
- return Files::mkdir(storage_path('app/public/' . $this->type . '/download/')) . $fname;
+ return Files::mkdir(protected_path($this->type . '/download/' . $this->entry->id . '/')) . $fname;
}
protected function _url($fname)
{
- return url('storage/' . $this->type . '/download/' . $fname);
+ return url('/' . $this->type . '/' . $this->entry->id . '_' . $this->entry->hash . '/download/' . $fname);
}
protected function _title()
$text = __($this->_text, $translateVariables);
$actions = [__('Télécharger') => $url];
$showTextIfNotEmail = false;
- try {
- if ($this->action === 'scormcloud') {
- $scormURL = ScormCloud::send($url, env('SCORM_CLOUD_PREFIX','toolbox_') . $this->type . '_' . $this->_id());
+ if ($this->action === 'scormcloud') {
+ try {
+ $scormURL = ScormCloud::send($url, env('SCORM_CLOUD_PREFIX', 'toolbox_') . $this->type . '_' . $this->_id());
$actions[__('Tester sur SCORM Cloud')] = $scormURL;
+ } catch (\Exception $e) {
+ $text .= "\n\n" . __('Une erreur s\'est produite lors de l\'envoi sur SCORM Cloud (App ID :appid) : :error (:url)', ['error' => $e->getMessage(), 'appid' => env('SCORM_CLOUD_APP_ID'), 'url' => $url]);
+ $showTextIfNotEmail = true;
}
- } catch (\Exception $e) {
- $text = __('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')]);
}
} catch (\Exception $e) {
$subject = __('Erreur lors de la compilation du :type :nb', ['nb' => $this->_id(), 'type' => $this->type]);
$compilepath = $this->_compile();
$fname = $this->_fname();
- $dest = Files::mkdir(storage_path('app/public/' . $this->type . '/download/')) . $fname;
+ $dest = Files::mkdir(protected_path($this->type . '/download/' . $this->entry->id . '/')) . $fname;
Zip::archive($compilepath, $dest);
if (!file_exists($dest)) {
// __('Le quiz ":title" est prêt au téléchargement')
protected $_text = 'Le quiz ":title" est prêt au téléchargement';
+ protected $_scormVersion = null;
+
+ public function __construct($entry, $action, $scormVersion = null, $user = null)
+ {
+ $this->_scormVersion = $scormVersion;
+ parent::__construct($entry, $action, $user);
+ }
+
+ protected function _compile()
+ {
+ if (null !== $this->_scormVersion) {
+ $this->entry->scorm_version = $this->_scormVersion;
+ }
+ return parent::_compile();
+ }
+
}
*/
public function compile($dest, $forceScorm = false, $user = null)
{
- $job = new QuizCompiler($this->id, $dest, $forceScorm);
+ $job = new QuizCompiler($this, $dest, $forceScorm);
$job->handle();
}
{{-- __('!! e-Learning') --}}
+@php
+ $base=$crud->route.'/'.$entry->id.'/package/';
+ $actions['download']=[
+ 'label'=>__('Télécharger'),
+ 'url'=>$base.'download'
+ ];
+ if($entry->scorm){
+ $actions['sep_scorm']='---------';
+ foreach (\App\Fields\SCORMVersion::getSCORMVersions() as $k=>$v) {
+ $actions['download_scorm_'.$k]=[
+ 'label'=>__('Version :version',['version'=>$v]),
+ 'url'=>$base.'scorm/'.$k
+ ];
+ }
+ $actions['sep_scormcloud ']='---------';
+ $actions['scormcloud']=['label'=>__('Tester sur SCORM Cloud'),
+ 'url'=> $base.'scormcloud'
+ ];
+
+ }
+
+@endphp
+
<a class="btn btn-sm btn-link exportquiz" href="#"
data-toggle="tooltip"
title="{{__('Exporter le quiz')}}"
- data-context-actions="{{json_encode(['download'=>__('Télécharger'),'scormcloud'=>__('Tester sur Scorm Cloud')])}}"
- data-context-route="{{$crud->route}}/$id/download/$action"
- data-context-id="{{$entry->getKey()}}"
+ data-context-actions="{{json_encode($actions)}}"
>
<i class="la la-arrow-circle-down"></i> {{__('Exporter')}}
</a>