--- /dev/null
+<?php
+
+namespace App\Console\Commands\Base;
+
+use App\Models\User;
+use Cubist\Backpack\Console\Commands\CubistCommand;
+
+class ToolboxCommand extends CubistCommand
+{
+ protected $signature = 'toolbox';
+ protected $description = 'Base command for Toolbox';
+
+ protected function getUser($id = 5)
+ {
+ return User::withoutGlobalScope('ownerclause')->findOrFail($id);
+ }
+}
--- /dev/null
+<?php
+
+namespace App\Console\Commands;
+
+use App\Console\Commands\Base\ToolboxCommand;
+use App\Models\ELearningMedia;
+
+class ElearningMediaDownload extends ToolboxCommand
+{
+ protected $signature = 'elearningmedia:download {id} {--action=download} {--scormversion=default}';
+ protected $description = 'Compile a Elearning Media';
+
+ public function handle()
+ {
+ $instance = ELearningMedia::withoutGlobalScopes()->find($this->argument('id'));
+ $scormVersion = $this->option('scormversion') !== 'default' ? $this->option('scormversion') : null;
+ (new \App\Jobs\ElearningMediaDownload($instance, $this->option('action'), $scormVersion, $this->getUser()))->handle();
+ }
+}
--- /dev/null
+<?php
+
+namespace App\Console\Commands;
+
+use App\Console\Commands\Base\ToolboxCommand;
+use App\Models\ELearningPackage;
+
+class ElearningPackageDownload extends ToolboxCommand
+{
+ protected $signature = 'elearningpackage:download {id} {--action=download} {--scormversion=default}';
+ protected $description = 'Compile a Elearning package';
+
+ public function handle()
+ {
+ $instance = ELearningPackage::withoutGlobalScopes()->find($this->argument('id'));
+ $scormVersion = $this->option('scormversion') !== 'default' ? $this->option('scormversion') : null;
+ (new \App\Jobs\ElearningPackageDownload($instance, $this->option('action'), $scormVersion, $this->getUser()))->handle();
+ }
+}
namespace App\Console\Commands;
+use App\Console\Commands\Base\ToolboxCommand;
use App\Jobs\FluidbookCollectionDownload;
-
-use App\Models\User;
-use Cubist\Backpack\Console\Commands\CubistCommand;
use Cubist\Util\PHP;
-class FluidbookCollection extends CubistCommand
+class FluidbookCollection extends ToolboxCommand
{
protected $signature = 'fluidbook:collection {id} {action}';
protected $description = 'Compile a fluidbook';
{
PHP::neverStop(true);
$collection = \App\Models\FluidbookCollection::find($this->argument('id'));
- $job = new FluidbookCollectionDownload($collection, $this->argument('action'), User::withoutGlobalScope('ownerclause')->findOrFail(5));
+ $job = new FluidbookCollectionDownload($collection, $this->argument('action'), $this->getUser());
$job->handle();
}
}
namespace App\Console\Commands;
+use App\Console\Commands\Base\ToolboxCommand;
use App\Fluidbook\Compiler\Compiler;
use App\Models\FluidbookPublication;
-use Cubist\Backpack\Console\Commands\CubistCommand;
use Cubist\Util\PHP;
-class FluidbookCompile extends CubistCommand
+class FluidbookCompile extends ToolboxCommand
{
+
protected $signature = 'fluidbook:compile {id}';
protected $description = 'Compile a fluidbook';
namespace App\Console\Commands;
+use App\Console\Commands\Base\ToolboxCommand;
use App\Jobs\FluidbookDocumentUpload;
use App\Models\FluidbookDocument;
use App\Models\User;
-use Cubist\Backpack\Console\Commands\CubistCommand;
use Cubist\Util\PHP;
use Cubist\Util\Str;
use Illuminate\Support\Facades\Log;
-class FluidbookDocumentProcess extends CubistCommand
+class FluidbookDocumentProcess extends ToolboxCommand
{
protected $signature = 'fluidbook:document:process {id}';
protected $description = 'Reprocess a fluidbook document';
namespace App\Console\Commands;
+use App\Console\Commands\Base\ToolboxCommand;
use App\Fluidbook\Farm;
-use Cubist\Backpack\Console\Commands\CubistCommand;
-class FluidbookFarmPing extends CubistCommand
+class FluidbookFarmPing extends ToolboxCommand
{
protected $signature = 'fluidbook:farm:ping {--force}';
protected $description = 'Manage fluidbook farm';
namespace App\Console\Commands;
-use App\Jobs\GenerateDeliveryThumbnailsPreview;
-use Illuminate\Console\Command;
+use App\Console\Commands\Base\ToolboxCommand;
use App\Models\FluidbookPublication;
-use Illuminate\Support\Facades\Bus;
-class FluidbookGeneratePreview extends Command
+class FluidbookGeneratePreview extends ToolboxCommand
{
/**
* The name and signature of the console command.
namespace App\Console\Commands;
+use App\Console\Commands\Base\ToolboxCommand;
use App\Fluidbook\Link\LinksData;
-use Cubist\Backpack\Console\Commands\CubistCommand;
-class FluidbookLinksFromPDF extends CubistCommand
+class FluidbookLinksFromPDF extends ToolboxCommand
{
protected $signature = 'fluidbook:links:importfrompdf {id}';
protected $description = 'Import links from PDF';
namespace App\Console\Commands;
-use App\Fluidbook\Farm;
+use App\Console\Commands\Base\ToolboxCommand;
use App\Fluidbook\HostingLoadBalancer;
-use Cubist\Backpack\Console\Commands\CubistCommand;
-class FluidbookLoadbalancerPing extends CubistCommand
+class FluidbookLoadbalancerPing extends ToolboxCommand
{
protected $signature = 'fluidbook:loadbalancer:ping {--force}';
protected $description = 'Manage fluidbook loadbalancer';
namespace App\Console\Commands;
+use App\Console\Commands\Base\ToolboxCommand;
use App\Fluidbook\Packager\Download;
use App\Models\FluidbookPublication;
use App\Models\User;
-use Cubist\Backpack\Console\Commands\CubistCommand;
-class FluidbookPackage extends CubistCommand
+class FluidbookPackage extends ToolboxCommand
{
protected $signature = 'fluidbook:package {id} {type=online} {action=download} {--zip}';
protected $description = 'Compile a fluidbook';
*/
public function handle()
{
- $download = new Download(FluidbookPublication::find($this->argument('id')), $this->argument('type'), $this->argument('action'), User::withoutGlobalScope('ownerclause')->findOrFail(5));
+ $download = new Download(FluidbookPublication::find($this->argument('id')), $this->argument('type'), $this->argument('action'), $this->getUser());
$download->handle();
}
}
namespace App\Console\Commands;
+use App\Console\Commands\Base\ToolboxCommand;
use App\Jobs\FluidbookImagesPreprocess;
-use Cubist\Backpack\Console\Commands\CubistCommand;
use Cubist\Util\PHP;
-class FluidbookPreprocessImages extends CubistCommand
+class FluidbookPreprocessImages extends ToolboxCommand
{
protected $signature = 'fluidbook:preprocess {id}';
protected $description = 'Compile a fluidbook';
namespace App\Console\Commands;
+use App\Console\Commands\Base\ToolboxCommand;
use App\Models\Traits\FluidbookPlayerBranches;
-use Cubist\Backpack\Console\Commands\CubistCommand;
use Cubist\Util\PHP;
-class FluidbookPullSources extends CubistCommand
+class FluidbookPullSources extends ToolboxCommand
{
protected $signature = 'fluidbook:player:updatesources';
protected $description = 'Update fluidbook player sources from git repos';
namespace App\Console\Commands;
+use App\Console\Commands\Base\ToolboxCommand;
use App\Slack\Slack;
-use Cubist\Backpack\Console\Commands\CubistCommand;
use Cubist\Backpack\Facades\App;
-class FluidbookQuote extends CubistCommand
+class FluidbookQuote extends ToolboxCommand
{
protected $signature = 'fluidbook:quote {--reminder}';
protected $description = 'Fluidbook Quotes';
namespace App\Console\Commands;
+use App\Console\Commands\Base\ToolboxCommand;
use App\Models\FluidbookPublication;
-use Cubist\Backpack\Console\Commands\CubistCommand;
use Cubist\Util\ArrayUtil;
use Cubist\Util\PHP;
-class FluidbookSocialImage extends CubistCommand
+class FluidbookSocialImage extends ToolboxCommand
{
protected $signature = 'fluidbook:socialimage {id} {--force}';
protected $description = 'Generate image for social networks';
namespace App\Console\Commands;
+use App\Console\Commands\Base\ToolboxCommand;
use App\Jobs\GenerateThemePreview;
use App\Models\FluidbookTheme;
-use Cubist\Backpack\Console\Commands\CubistCommand;
use Cubist\Util\ArrayUtil;
use Illuminate\Database\Query\Builder;
-class FluidbookThemePreview extends CubistCommand
+class FluidbookThemePreview extends ToolboxCommand
{
protected $signature = 'fluidbook:theme:preview {id?}';
protected $description = 'Generate a theme preview';
--- /dev/null
+<?php
+
+namespace App\Console\Commands;
+
+use App\Console\Commands\Base\ToolboxCommand;
+use App\Models\Quiz;
+
+class QuizDownload extends ToolboxCommand
+{
+ protected $signature = 'quiz:download {id} {--action=download} {--scormversion=default}';
+ protected $description = 'Compile a quiz';
+
+ public function handle()
+ {
+ $instance = Quiz::withoutGlobalScopes()->find($this->argument('id'));
+ $scormVersion = $this->option('scormversion') !== 'default' ? $this->option('scormversion') : null;
+ (new \App\Jobs\QuizDownload($instance, $this->option('action'), $scormVersion, $this->getUser()))->handle();
+ }
+}
+++ /dev/null
-<?php
-
-
-namespace App\Console\Commands;
-
-use App\Models\QuizAttempt;
-use Carbon\Carbon;
-use Cubist\Backpack\Console\Commands\CubistCommand;
-use Cubist\Backpack\Magic\Models\CubistMagicAbstractModel;
-use Illuminate\Support\Facades\Storage;
-use Lucy\Document;
-use Lucy\Parser;
-
-class QuizLogReplay extends CubistCommand
-{
-
- protected $signature = 'quiz:log:replay';
- protected $description = 'Replay quiz logs';
-
- public function handle()
- {
- $files = Storage::disk('storage')->files('quizlogs', true);
- $this->_parseFile('quizlogs/toolbox-audit.log');
-// foreach ($files as $file) {
-// $this->_parseFile($file);
-// }
- }
-
- public function _parseFile($file)
- {
- $log = new Document(storage_path($file), Parser::class);
- foreach ($log->getParsers() as $parser) {
-
- if ($parser->getMethod() !== 'POST') {
- continue;
- }
- if (!preg_match('/^\/quiz\/([0-9]+)\/log$/', $parser->getPath(), $matches)) {
- continue;
- }
- $data = $parser->getPostData();
- $log = new QuizAttempt();
- $log->quiz = $matches[1];
- $log->score = $data['score'];
- $log->passed = $data['passed'] !== 'false' ? '1' : '0';
- $log->answers = json_encode($data['questions']);
- $log->created_at=$parser->getDate()->toDateTimeString();
- $log->updated_at=$parser->getDate()->toDateTimeString();
- dd($log);
- //$log->save();
- }
-
- }
-}
namespace App\Console\Commands;
+use App\Console\Commands\Base\ToolboxCommand;
use App\Models\Traits\QuizBranches;
-use Cubist\Backpack\Console\Commands\CubistCommand;
use Cubist\Util\PHP;
-class QuizPullSources extends CubistCommand
+class QuizPullSources extends ToolboxCommand
{
protected $signature = 'quiz:player:updatesources';
protected $description = 'Update quiz player sources from git repos';
namespace App\Console\Commands;
+use App\Console\Commands\Base\ToolboxCommand;
use App\Fields\FluidbookTTSVoice;
-use App\Fluidbook\Farm;
use App\Models\FluidbookTranslate;
use Cubedesigners\UserDatabase\Permissions;
-use Cubist\Backpack\Console\Commands\CubistCommand;
-class ToolboxPrecache extends CubistCommand
+class ToolboxPrecache extends ToolboxCommand
{
protected $signature = 'toolbox:precache';
protected $description = 'Precache Toolbox';
namespace App\Console\Commands;
+use App\Console\Commands\Base\ToolboxCommand;
use App\Models\FluidbookPublication;
-use Cubist\Backpack\Console\Commands\CubistCommand;
use Illuminate\Support\Facades\DB;
-class ToolboxToWorkshop extends CubistCommand
+class ToolboxToWorkshop extends ToolboxCommand
{
protected $signature = 'toolboxtows {id} {targetid=new}';
protected $description = 'Migrate a fluidbook made on the toolbox back to the workshop';
} else {
DB::table(self::$_wstable)->where('book_id', $targetid)->update($data);
}
-
- //DB::table(self::$_wstable)->in
}
}
+++ /dev/null
-<?php
-
-namespace App\Console\Commands;
-
-use App\Models\ToolboxTranslate;
-use App\Models\Traits\FluidbookPlayerBranches;
-use Cubist\Backpack\Console\Commands\CubistCommand;
-use Cubist\Backpack\Facades\App;
-use Cubist\Locale\Translate;
-use Cubist\Util\PHP;
-
-class ToolboxTranslations extends CubistCommand
-{
- protected $signature = 'translate:toolbox';
-
-
- use FluidbookPlayerBranches;
-
- public function handle()
- {
- App::setLocale('en');
-
- dd(ToolboxTranslate::find(1));
-
- $paths = [];
- foreach (self::getActiveBranches() as $branch) {
- $paths['Player - git:' . $branch] = 'resources/fluidbookpublication/player/branches/' . $branch . '/js';
- $paths['Player - local:' . $branch] = 'resources/fluidbookpublication/player/local/' . $branch . '/js';
- }
-
- $t = new Translate();
- $t->setExtensions(['js']);
- foreach ($paths as $path) {
- $t->addPath(base_path() . '/' . $path);
- }
- $t->parseFiles();
- dd($t->getStringToTranslate());
- }
-}
namespace App\Console\Commands;
-use Cubist\Backpack\Console\Commands\CubistCommand;
+use App\Console\Commands\Base\ToolboxCommand;
use Cubist\Util\Files\Files;
use Cubist\Util\Zip;
-class UpdateNWJS extends CubistCommand
+class UpdateNWJS extends ToolboxCommand
{
/** @see https://nwjs.io/ */
namespace App\Console\Commands;
-use Cubist\Backpack\Console\Commands\CubistCommand;
+use App\Console\Commands\Base\ToolboxCommand;
use Cubist\Util\Files\Files;
use Cubist\Util\Zip;
-class UpdatePDFJSLibrary extends CubistCommand
+class UpdatePDFJSLibrary extends ToolboxCommand
{
/** @see https://mozilla.github.io/pdf.js/getting_started/#download */
namespace App\Console\Commands;
+use App\Console\Commands\Base\ToolboxCommand;
use App\Models\FluidbookDocument;
use App\Models\FluidbookPublication;
use App\Models\FluidbookTheme;
use Cubist\Util\Json;
use Cubist\Util\ObjectUtil;
use Cubist\Util\PHP;
-use Cubist\Util\Text;
use Illuminate\Contracts\Cache\Lock;
use Illuminate\Support\Facades\Artisan;
use Illuminate\Support\Facades\Cache;
use Illuminate\Support\Facades\DB;
-class WorkshopMigration extends CubistCommand
+class WorkshopMigration extends ToolboxCommand
{
protected $signature = 'ws:migrate {--publications=v2} {--documents=missing} {--quick} {--force}';
protected $description = 'Migrate data from Workshop V2';
protected $_wsRanks = [];
const OLD_DB = 'extranet_clean';
protected $_oldRoot = '/home/extranet/www/fluidbook/';
- protected static $_admin = 5;
/** @var Lock */
protected Lock $_lock;
{
$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->compilePath = protected_path($this->getBaseURL() . '/compile/' . $this->quiz->id);
$this->dest = $dest;
$this->forceScorm = $forceScorm;
}
+ protected function getBaseURL()
+ {
+ return $this->quiz->getOption('name');
+ }
+
public function handle()
{
$compileVdir = new VirtualDirectory($this->compilePath);
--- /dev/null
+<?php
+
+namespace App\Http\Controllers\Admin\Operations\Base;
+
+// __('!! e-Learning')
+
+use App\Http\Middleware\CheckIfAdmin;
+use Cubist\Backpack\Http\Controllers\Base\XSendFileController;
+use Illuminate\Support\Facades\Route;
+use Prologue\Alerts\Facades\Alert;
+
+trait BaseDownloadOperation
+{
+ protected function setupDownloadRoutes($segment, $routeName, $controller)
+ {
+ 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', $this->button . '.download', 'end');
+ }
+
+ protected function package($id, $action, $version = null)
+ {
+ $entry = $this->getModelInstance();
+ $model = get_class($entry);
+ $job = $this->downloadJob;
+
+ if (!$model::hasPermission($id, 'read')) {
+ abort(401);
+ }
+ $instance = $model::withoutGlobalScopes()->find($id);
+ $version = $version ?? $instance->scorm_version;
+ $job::dispatch($instance, $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($entry->getOption('name')));
+ }
+
+ protected function download($id, $hash, $file)
+ {
+ $entry = $this->getModelInstance();
+ $model = get_class($entry);
+
+ $instance = $model::withoutGlobalScopes()->where('id', $id)->where('hash', $hash)->first();
+ if (null === $instance) {
+ abort(404, __('Ce fichier est indisponible'));
+ }
+ $path = protected_path($entry->getOption('name') . '/download/' . $id . '/' . $file);
+ if (!file_exists($path)) {
+ abort(404, __('Le fichier n\'existe pas'));
+ }
+ return XSendFileController::sendfile($path);
+ }
+}
// __('!! e-Learning')
-use App\Http\Middleware\CheckIfAdmin;
+use App\Http\Controllers\Admin\Operations\Base\BaseDownloadOperation;
use App\Jobs\ElearningMediaDownload;
-use App\Jobs\QuizDownload;
-use App\Models\ELearningMedia;
-use App\Models\Quiz;
-use Cubist\Backpack\Http\Controllers\Base\XSendFileController;
-use Illuminate\Support\Facades\Route;
-use Prologue\Alerts\Facades\Alert;
trait DownloadOperation
{
- protected function setupDownloadRoutes($segment, $routeName, $controller)
- {
- 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()
- {
+ use BaseDownloadOperation;
- $this->crud->addButtonFromView('line', 'download', 'elearningmedia.download', 'end');
- }
-
- protected function package($id, $action, $version = null)
- {
- if (!ElearningMedia::hasPermission($id, 'read')) {
- abort(401);
- }
- $media = ElearningMedia::withoutGlobalScopes()->find($id);
- $version = $version ?? $media->scorm_version;
- ElearningMediaDownload::dispatch($media, $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('elearning-media'));
- }
-
- protected function download($id, $hash, $file)
- {
- $media = ElearningMedia::withoutGlobalScopes()->where('id', $id)->where('hash', $hash)->first();
- if (null === $media) {
- abort(404, __('Ce fichier est indisponible'));
- }
- $path = protected_path('elearning-media/download/' . $id . '/' . $file);
- if (!file_exists($path)) {
- abort(404, __('Le fichier n\'existe pas'));
- }
- return XSendFileController::sendfile($path);
- }
-
-// protected function download($id, $action)
-// {
-// ElearningMediaDownload::dispatch(ELearningMedia::find($id), $action, 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('elearning-media'));
-// }
+ protected $button = 'elearningmedia';
+ protected $downloadJob = ElearningMediaDownload::class;
}
namespace App\Http\Controllers\Admin\Operations\ELearningPackage;
-use App\Http\Middleware\CheckIfAdmin;
+use App\Http\Controllers\Admin\Operations\Base\BaseDownloadOperation;
use App\Jobs\ElearningPackageDownload;
-use App\Models\ELearningPackage;
-use Cubist\Backpack\Http\Controllers\Base\XSendFileController;
-use Illuminate\Support\Facades\Route;
-use Prologue\Alerts\Facades\Alert;
// __('!! e-Learning')
trait DownloadOperation
{
- protected function setupDownloadRoutes($segment, $routeName, $controller)
- {
- Route::match(['get'], $segment . '/{id}/package/{action}/{version?}', $controller . '@package');
- Route::match(['get'], $segment . '/{id}_{hash}/download/{file}', $controller . '@download')->withoutMiddleware([CheckIfAdmin::class]);;
- }
+ use BaseDownloadOperation;
- protected function setupDownloadDefaults()
- {
- $this->crud->addButtonFromView('line', 'download', 'elearningpackage.download', 'end');
- }
-
- protected function package($id, $action, $version = null)
- {
- if (!ElearningPackage::hasPermission($id, 'read')) {
- abort(401);
- }
- $media = ElearningPackage::withoutGlobalScopes()->find($id);
- $version = $version ?? $media->scorm_version;
- ElearningPackageDownload::dispatch($media, $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('elearning-package'));
- }
-
- protected function download($id, $hash, $file)
- {
- $media = ElearningPackage::withoutGlobalScopes()->where('id', $id)->where('hash', $hash)->first();
- if (null === $media) {
- abort(404, __('Ce fichier est indisponible'));
- }
- $path = protected_path('elearningmedia/download/' . $id . '/' . $file);
- if (!file_exists($path)) {
- abort(404, __('Le fichier n\'existe pas'));
- }
- return XSendFileController::sendfile($path);
- }
-
-// protected function download($id, $action)
-// {
-// ElearningPackageDownload::dispatch(ELearningPackage::find($id), $action, 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('elearning-package'));
-// }
+ protected $button = 'elearningpackage';
+ protected $downloadJob = ELearningPackageDownload::class;
}
namespace App\Http\Controllers\Admin\Operations\Quiz;
-use App\Fields\SCORMVersion;
-use App\Http\Middleware\CheckIfAdmin;
+use App\Http\Controllers\Admin\Operations\Base\BaseDownloadOperation;
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;
// __('!! e-Learning')
trait DownloadOperation
{
- protected function setupDownloadRoutes($segment, $routeName, $controller)
- {
- Route::match(['get'], $segment . '/{id}/package/{action}/{version?}', $controller . '@package');
- Route::match(['get'], $segment . '/{id}_{hash}/download/{file}', $controller . '@download')->withoutMiddleware([CheckIfAdmin::class]);;
- }
+ use BaseDownloadOperation;
- protected function setupDownloadDefaults()
- {
-
- $this->crud->addButtonFromView('line', 'download', 'quiz.download', 'end');
- }
-
- protected function package($id, $action, $version = null)
- {
- 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);
- }
+ protected $button = 'quiz';
+ protected $downloadJob = QuizDownload::class;
}
class Base extends \Cubist\Backpack\Jobs\Base
{
+ protected $tries = 1;
+
/**
* @var User|null
*/
use App\Models\User;
use App\Notifications\DownloadReady;
use App\Services\ScormCloud;
-use App\Slack\Message;
use App\Slack\Slack;
use Cubist\Backpack\Facades\App;
use Cubist\Backpack\Magic\Models\CubistMagicAbstractModel;
use Cubist\Util\Files\Files;
use Cubist\Util\Str;
use Cubist\Util\Zip;
-use GrahamCampbell\Markdown\Facades\Markdown;
-use Illuminate\Support\Facades\Log;
use Illuminate\Support\Facades\Mail;
-use JoliCode\Slack\ClientFactory;
use League\CommonMark\CommonMarkConverter;
use League\CommonMark\Exception\CommonMarkException;
class DownloadBase extends Base
{
- /**
- * @var string
- */
- protected $type = 'base';
-
/**
* @var CubistMagicAbstractModel
*/
Mail::send($mail);
}
+ protected function getBaseURL()
+ {
+ return $this->entry->getOption('name');
+ }
+
+ protected function getType()
+ {
+ return str_replace('-', '', $this->getBaseURL());
+ }
+
protected function _fname($title = null, $extension = 'zip')
{
if (null === $title) {
$title = $this->_title();
}
- return Str::slugCase($this->type . '-' . date('Ymdhis') . '-' . md5(rand(10000, 100000000)) . '-' . Str::slug($title)) . '.' . $extension;
+ return Str::slugCase($this->getType() . '-' . date('Ymdhis') . '-' . md5(rand(10000, 100000000)) . '-' . Str::slug($title)) . '.' . $extension;
}
protected function _dest($fname)
{
- return Files::mkdir(protected_path($this->type . '/download/' . $this->entry->id . '/')) . $fname;
+ return Files::mkdir(protected_path($this->getBaseURL() . '/download/' . $this->entry->id . '/')) . $fname;
}
protected function _url($fname)
{
- return url('/' . $this->type . '/' . $this->entry->id . '_' . $this->entry->hash . '/download/' . $fname);
+ return url('/' . $this->getBaseURL() . '/' . $this->entry->id . '_' . $this->entry->hash . '/download/' . $fname);
}
protected function _title()
$showTextIfNotEmail = false;
if ($this->action === 'scormcloud') {
try {
- $scormURL = ScormCloud::send($url, env('SCORM_CLOUD_PREFIX', 'toolbox_') . $this->type . '_' . $this->_id());
+ $scormURL = ScormCloud::send($url, env('SCORM_CLOUD_PREFIX', 'toolbox_') . $this->getType() . '_' . $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]);
}
}
} catch (\Exception $e) {
- $subject = __('Erreur lors de la compilation du :type :nb', ['nb' => $this->_id(), 'type' => $this->type]);
+ $subject = __('Erreur lors de la compilation du :type :nb', ['nb' => $this->_id(), 'type' => $this->getType()]);
$text = __('Détails de l\'erreur :message', ['message' => $e->getMessage() . ' at line ' . $e->getLine() . ' of ' . $e->getFile()]);
$showTextIfNotEmail = true;
$actions = [];
protected function _compileandpackage()
{
+ echo 'Compile' . "\n";
$compilepath = $this->_compile();
+ echo 'Compiled : ' . $compilepath . "\n";
$fname = $this->_fname();
- $dest = Files::mkdir(protected_path($this->type . '/download/' . $this->entry->id . '/')) . $fname;
-
+ $dest = Files::mkdir(protected_path($this->getBaseURL() . '/download/' . $this->entry->id . '/')) . $fname;
+ echo 'Zip to ' . $dest . "\n";
Zip::archive($compilepath, $dest);
if (!file_exists($dest)) {
throw new \Exception('An error occured while compiling the collection');
protected function _compile()
{
$compilepath = $this->entry->getFinalPath();
+ echo 'Compile to '.$compilepath."\n";
$this->entry->compile($compilepath);
return $compilepath;
}
namespace App\Jobs;
-use App\Services\ScormCloud;
-use Cubist\Util\Files\Files;
-use Cubist\Util\Zip;
-
-class ElearningMediaDownload extends DownloadBase
+class ElearningMediaDownload extends ScormDownloadBase
{
- protected $type = 'elearningmedia';
// __('Media ":title" (#:nb) prêt au téléchargement')
protected $_subject = 'Media ":title" (#:nb) prêt au téléchargement';
// __('Le media ":title" est prêt au téléchargement');
namespace App\Jobs;
-use App\Services\ScormCloud;
-use Cubist\Util\Files\Files;
-use Cubist\Util\Zip;
-
-class ElearningPackageDownload extends DownloadBase
+class ElearningPackageDownload extends ScormDownloadBase
{
- protected $type = 'elearningpackage';
// __('Package ":title" (#:nb) prêt au téléchargement')
protected $_subject = 'Package ":title" (#:nb) prêt au téléchargement';
// __('Le package ":title" est prêt au téléchargement');
*/
protected $fluidbook_id;
- /**
- * @var int
- */
- public $tries = 1;
-
public $queue = 'fluidbookprocess';
/**
namespace App\Jobs;
-use App\Services\ScormCloud;
-use Cubist\Util\Files\Files;
-use Cubist\Util\Zip;
-
-class QuizDownload extends DownloadBase
+class QuizDownload extends ScormDownloadBase
{
-
- protected $type = 'quiz';
// __('Quiz ":title" (#:nb) prêt au téléchargement')
protected $_subject = 'Quiz ":title" (#:nb) prêt au téléchargement';
// __('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();
- }
-
}
--- /dev/null
+<?php
+
+namespace App\Jobs;
+
+use App\Jobs\DownloadBase;
+
+class ScormDownloadBase extends DownloadBase
+{
+ 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();
+ }
+}
--- /dev/null
+<?php
+
+namespace App\Models\Base;
+
+use App\Models\Traits\CheckHash;
+use Cubist\Util\Files\Files;
+
+trait ToolboxDownloadable
+{
+ use CheckHash;
+
+ public function onSaving(): bool
+ {
+ $this->checkHash();
+ return parent::onSaving();
+ }
+
+ public function getFinalPath()
+ {
+ return Files::mkdir(protected_path($this->getOption('name') . '/final/' . $this->id));
+ }
+}
use App\Http\Controllers\Admin\Operations\ELearningMedia\ImportOperation;
use App\Http\Controllers\Admin\Operations\ELearningMedia\PreviewOperation;
use App\Http\Controllers\Admin\Operations\ELearningMedia\DownloadOperation;
+use App\Models\Base\ToolboxDownloadable;
use App\Models\Base\ToolboxModel;
use App\Models\Traits\CheckHash;
use App\Models\Traits\SCORMVersionTrait;
class ELearningMedia extends ToolboxModel
{
use SCORMVersionTrait;
- use CheckHash;
+ use ToolboxDownloadable;
protected $table = 'elearning_media';
}
}
- public function getFinalPath()
- {
- return protected_path('elearningmedia/final/' . $this->id);
- }
-
public function compile($dest)
{
$owner = User::withoutGlobalScopes()->findOrFail($this->owner);
return $title;
}
- public function onSaving(): bool
- {
- $this->checkHash();
- return parent::onSaving();
- }
-
public function getIdTitleAttribute()
{
return $this->id . ' - ' . $this->title;
use App\Http\Controllers\Admin\Operations\ELearningPackage\ImportOperation;
use App\Http\Controllers\Admin\Operations\ELearningPackage\PreviewOperation;
use App\Http\Controllers\Admin\Operations\ELearningPackage\DownloadOperation;
+use App\Models\Base\ToolboxDownloadable;
use App\Models\Base\ToolboxModel;
use App\Models\Traits\CheckHash;
use App\Models\Traits\SCORMVersionTrait;
class ELearningPackage extends ToolboxModel
{
use SCORMVersionTrait;
- use CheckHash;
+ use ToolboxDownloadable;
protected $table = 'elearning_package';
$this->addField('contents', BunchOfFieldsMultiple::class, __('Contenus'), ['bunch' => ElearningPackageContent::class, 'edit_label' => __('Editer « :label »', ['label' => '%content_type'])]);
}
- public function getFinalPath()
- {
- return protected_path('elearningpackage/final/' . $this->id);
- }
public function compile($dest, $user = null)
{
return $res;
}
- public function onSaving(): bool
- {
- $this->checkHash();
- return parent::onSaving();
- }
-
/**
* @param $id int
* @param $vdir VirtualDirectory
use App\Http\Controllers\Admin\Operations\ChangeownerOperation;
use App\Http\Controllers\Admin\Operations\FluidbookCollection\DownloadOperation;
use App\Http\Controllers\Admin\Operations\FluidbookCollection\PreviewOperation;
+use App\Models\Base\ToolboxDownloadable;
use App\Models\Base\ToolboxModel;
use App\Models\Traits\CheckHash;
use App\Slack\Slack;
// __('!! Collections de fluidbooks')
class FluidbookCollection extends ToolboxModel
{
- use CheckHash;
+ use ToolboxDownloadable;
protected $table = 'fluidbook_collection';
protected $_options = ['name' => 'fluidbook-collection',
$this->addOwnerField();
- $this->addField('hash', Hidden::class);
+ $this->addHashField();
$this->addField('type', SelectFromArray::class, __('Type'), ['can' => 'fluidbook-collection:write', 'column' => true, 'options' => ['export' => __('Export'), 'export_multilang' => __('Export multilingue'), 'scorm_multilang' => __('SCORM multilingue')]]);
$this->addField('locale_switch', Checkbox::class, __('Permettre le changement de langue'), ['when' => ['type' => ['scorm_multilang', 'export_multilang']], 'default' => true]);
$this->addField('redirection_algorithm', SelectFromArray::class, __('Algorithme de choix de la version'),
return Files::mkdir(protected_path('fluidbookcollection/final/' . $this->id));
}
- public function onSaving(): bool
- {
- $this->checkHash();
- return parent::onSaving();
- }
public function allowsPreview()
use App\Jobs\FluidbookImagesPreprocess;
use App\Jobs\FluidbookSocialImage;
use App\Jobs\GenerateDeliveryThumbnailsPreview;
+use App\Models\Base\ToolboxDownloadable;
use App\Models\Base\ToolboxSettingsModel;
use App\Models\Traits\CheckHash;
use App\Models\Traits\PublicationSettings;
use PublicationSettings;
use PublicationTags;
use SCORMVersionTrait;
- use CheckHash;
+ use ToolboxDownloadable;
public static function addOwnerClause(Builder $builder)
{
use App\Fields\SCORMVersion;
use App\Http\Controllers\Admin\Operations\ChangeownerOperation;
use App\Http\Controllers\Admin\Operations\Quiz\DownloadOperation;
-use App\Http\Controllers\Admin\Operations\Quiz\ImportOperation;
use App\Http\Controllers\Admin\Operations\Quiz\LogOperation;
use App\Http\Controllers\Admin\Operations\Quiz\PreviewOperation;
use App\Http\Controllers\Admin\Operations\Quiz\ReportOperation;
+use App\Models\Base\ToolboxDownloadable;
use App\Models\Base\ToolboxModel;
-use App\Models\Traits\CheckHash;
use App\Models\Traits\SCORMVersionTrait;
use Cubist\Backpack\Magic\Fields\Checkbox;
use Cubist\Backpack\Magic\Fields\Code;
use Cubist\Backpack\Magic\Fields\FormSection;
use Cubist\Backpack\Magic\Fields\FormSeparator;
use Cubist\Backpack\Magic\Fields\FormSuperSection;
-use Cubist\Backpack\Magic\Fields\Hidden;
use Cubist\Backpack\Magic\Fields\SelectFromArray;
use Cubist\Backpack\Magic\Fields\Text;
use Cubist\Backpack\Magic\Fields\Textarea;
// __('!! e-Learning')
class Quiz extends ToolboxModel
{
- use CheckHash;
+ use ToolboxDownloadable;
+ use SCORMVersionTrait;
protected $table = 'quiz';
protected $_operations = [PreviewOperation::class, DownloadOperation::class, LogOperation::class, ReportOperation::class, ChangeownerOperation::class];
- use SCORMVersionTrait;
+
protected static function _getColors()
{
return parent::create($data);
}
- public function getFinalPath()
- {
- return protected_path('quiz/final/' . $this->id);
- }
-
- public function onSaving(): bool
- {
- $this->checkHash();
- return parent::onSaving();
- }
-
public function getPreviewURL($attrs = [])
{
$routeName = 'quiz_preview';
foreach ($this->actions as $label => $url) {
$m->line(new HtmlString($label . __(': ') . ' <a href="' . $url . '">' . $url . '</a>'));
}
- $m->salutation(new HtmlString(__('Cordialement,') . "<br>" . __('L\'équipe :teamname',['team_name'=>env('MAIL_TEAM_NAME')])));
+ $m->salutation(new HtmlString(__('Cordialement,') . "<br>" . __('L\'équipe :teamname', ['teamname' => env('MAIL_TEAM_NAME')])));
return $m;
}