From ed55e634c83a7bb0976f815c5846830032392557 Mon Sep 17 00:00:00 2001 From: Vincent Vanwaelscappel Date: Wed, 19 Oct 2022 16:16:00 +0200 Subject: [PATCH] wip #5471 @1.5 --- app/Models/Quiz.php | 70 ++++++++++++++++++++-------- app/SubForms/{ => Quiz}/Answer.php | 10 +++- app/SubForms/{ => Quiz}/Question.php | 4 +- app/SubForms/Quiz/TestResult.php | 26 +++++++++++ 4 files changed, 87 insertions(+), 23 deletions(-) rename app/SubForms/{ => Quiz}/Answer.php (57%) rename app/SubForms/{ => Quiz}/Question.php (97%) create mode 100644 app/SubForms/Quiz/TestResult.php diff --git a/app/Models/Quiz.php b/app/Models/Quiz.php index 17ac7c6e9..298635906 100644 --- a/app/Models/Quiz.php +++ b/app/Models/Quiz.php @@ -2,19 +2,19 @@ namespace App\Models; +use App\Fields\SCORMVersion; 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 Cubist\Scorm\Manifest; -use Cubist\Util\Files\VirtualDirectory; -use App\Fields\SCORMVersion; -use App\Http\Controllers\Admin\Base\QuizController; use App\Models\Base\ToolboxModel; use App\Models\Traits\SCORMVersionTrait; -use Spatie\MediaLibrary\MediaCollections\Models\Media; +use Cubist\Backpack\Magic\Fields\SelectFromArray; +use Cubist\Scorm\Manifest; +use Cubist\Util\Files\VirtualDirectory; use Spatie\Image\Manipulations; +use Spatie\MediaLibrary\MediaCollections\Models\Media; class Quiz extends ToolboxModel { @@ -104,13 +104,6 @@ class Quiz extends ToolboxModel $this->addColumnDateFields(__('Projet')); $this->addOwnerField(__('Projet')); - $this->addField(['name' => 'scorm_version', - 'label' => __('Version SCORM'), - 'column' => true, - 'type' => SCORMVersion::class, - 'tab' => __('Projet')] - ); - $this->addField(['name' => 'title', 'label' => __('Titre du quiz'), 'type' => 'Text', @@ -137,23 +130,41 @@ class Quiz extends ToolboxModel $this->addField([ 'name' => 'questions', 'type' => 'BunchOfFieldsMultiple', - 'bunch' => 'App\SubForms\Question', + 'bunch' => \App\SubForms\Quiz\Question::class, 'label' => '', 'add_label' => __('Nouvelle question'), 'tab' => __('Questions / Réponses'), ]); + $this->addField([ + 'name' => 'type', + 'type' => SelectFromArray::class, + 'label' => __('Mode'), + 'options' => ['quiz' => __('Quiz'), 'test' => __('Test')], + 'default' => 'quiz', + 'database_default' => 'quiz', + 'tab' => __('Paramètres'), + ]); + $this->addField(['name' => 'scorm', 'label' => __('SCORM activé'), 'column_label' => __('SCORM'), 'type' => 'Checkbox', - 'tab' => __('Paramètres')]); + 'tab' => __('SCORM')]); + + $this->addField(['name' => 'scorm_version', + 'label' => __('Version SCORM'), + 'column' => true, + 'type' => SCORMVersion::class, + 'tab' => __('SCORM')] + ); $this->addField(['name' => 'display_score', 'label' => __('Afficher le score'), 'type' => 'Checkbox', 'default' => true, 'tab' => __('Paramètres'), + 'when' => ['type' => 'quiz'], ]); $this->addField(['name' => 'threshold', @@ -162,14 +173,19 @@ class Quiz extends ToolboxModel 'min' => 0, 'max' => 100, 'hint' => __('Au dessus de ce score (sur 100), le quiz est considéré comme réussi. Indiquer 0 pour désactiver'), - 'tab' => __('Paramètres')]); + 'tab' => __('Paramètres'), + 'when' => ['type' => 'quiz'], + ], + ); $this->addField(['name' => 'instantReview', 'label' => __('Activer l\'indication de réussite instantané'), 'hint' => __('Montrer une pastille à l\'utilisateur juste après sa réponse pour signaler si il a bien répondu'), 'default' => true, 'type' => 'Checkbox', - 'tab' => __('Paramètres')]); + 'tab' => __('Paramètres'), + 'when' => ['type' => 'quiz'], + ]); $this->addField(['name' => 'review', 'label' => __('Activer le passage en revue'), @@ -186,13 +202,16 @@ class Quiz extends ToolboxModel '0' => 'never', ], 'default' => true, - 'tab' => __('Paramètres')]); + 'tab' => __('Paramètres'), + 'when' => ['type' => 'quiz'], + ]); $this->addField(['name' => 'restart_button', 'label' => __('Ajouter un bouton "Redémarrer" lorsque l\'utilisateur a échoué'), 'type' => 'Checkbox', 'default' => false, 'tab' => __('Paramètres'), + 'when' => ['type' => 'quiz'], ]); $this->addField(['name' => 'logattempts', @@ -200,17 +219,30 @@ class Quiz extends ToolboxModel 'hint' => __('Les tentatives seront enregistrées sur le serveur de la Toolbox'), 'type' => 'Checkbox', 'default' => false, - 'tab' => __('Paramètres')]); + 'tab' => __('Paramètres'), + 'when' => ['type' => 'quiz'], + ]); foreach (self::_getActions() as $action => $label) { $this->addField(['name' => $action, 'label' => $label, 'hint' => __('Code Javascript'), 'type' => 'Textarea', - 'tab' => __('Paramètres') + 'tab' => __('Paramètres'), + 'when' => ['type' => 'quiz'], ]); } + $this->addField([ + 'name' => 'test_results', + 'label' => __('Résultats du test'), + 'type' => 'BunchOfFieldsMultiple', + 'bunch' => \App\SubForms\Quiz\TestResult::class, + 'add_label' => __('Nouveau résultat'), + 'tab' => __('Paramètres'), + 'when' => ['type' => 'test'], + ]); + $default = ['tab' => __('Thème'), 'type' => 'Color']; foreach (self::_getColors() as $name => $color) { $f = array_merge($default, $color, ['name' => $name]); diff --git a/app/SubForms/Answer.php b/app/SubForms/Quiz/Answer.php similarity index 57% rename from app/SubForms/Answer.php rename to app/SubForms/Quiz/Answer.php index efa5f275f..9b295e50b 100644 --- a/app/SubForms/Answer.php +++ b/app/SubForms/Quiz/Answer.php @@ -1,8 +1,9 @@ addField(['name' => 'correct', 'type' => 'Checkbox', - 'label' => __('Réponse correct')]); + 'label' => __('Réponse correcte')]); + + $this->addField(['name' => 'score', + 'type' => Integer::class, + 'label' => __('Score'), + 'default' => 1]); } } diff --git a/app/SubForms/Question.php b/app/SubForms/Quiz/Question.php similarity index 97% rename from app/SubForms/Question.php rename to app/SubForms/Quiz/Question.php index 5dce61bac..d96353ed2 100644 --- a/app/SubForms/Question.php +++ b/app/SubForms/Quiz/Question.php @@ -1,7 +1,7 @@ addField([ 'name' => 'answers', 'type' => 'BunchOfFieldsMultiple', - 'bunch' => 'App\SubForms\Answer', + 'bunch' => Answer::class, 'add_label' => __('Nouvelle réponse'), 'label' => __('Réponses'), 'when' => ['type' => 'multiple'] diff --git a/app/SubForms/Quiz/TestResult.php b/app/SubForms/Quiz/TestResult.php new file mode 100644 index 000000000..898a2a539 --- /dev/null +++ b/app/SubForms/Quiz/TestResult.php @@ -0,0 +1,26 @@ +addField(['name' => 'text', + 'type' => Textarea::class, + 'label' => __('Texte du résultat'), + ]); + + $this->addField(['name' => 'score', + 'type' => Range::class, + 'label' => __('Score'), + ]); + } +} -- 2.39.5