From: Vincent Vanwaelscappel Date: Wed, 19 Oct 2022 14:16:00 +0000 (+0200) Subject: wip #5471 @1.5 X-Git-Url: http://git.cubedesigners.com/?a=commitdiff_plain;h=ed55e634c83a7bb0976f815c5846830032392557;p=fluidbook-toolbox.git wip #5471 @1.5 --- 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/Answer.php deleted file mode 100644 index efa5f275f..000000000 --- a/app/SubForms/Answer.php +++ /dev/null @@ -1,23 +0,0 @@ -addField(['name' => 'answer', - 'type' => 'Text', - 'label' => __('Texte de la réponse') - ]); - - $this->addField(['name' => 'correct', - 'type' => 'Checkbox', - 'label' => __('Réponse correct')]); - } -} diff --git a/app/SubForms/Question.php b/app/SubForms/Question.php deleted file mode 100644 index 5dce61bac..000000000 --- a/app/SubForms/Question.php +++ /dev/null @@ -1,86 +0,0 @@ -addField(['name' => 'question', - 'type' => 'Text', - 'label' => __('Intitulé de la question'), - ]); - - $this->addField(['name' => 'required', - 'type' => 'Checkbox', - 'default' => true, - 'label' => __('Réponse obligatoire')]); - - $this->addField(['name' => 'report_label', - 'type' => 'Text', - 'label' => __('Intitulé de la question dans les rapports'), - ]); - - $this->addField(['name' => 'type', - 'type' => 'SelectFromArray', - 'label' => __('Type'), - 'default' => 'multiple', - 'options' => [ - 'multiple' => __('Question à choix multiple'), - 'text' => __('Texte'), - 'textarea' => __('Texte long'), - 'email' => __('E-mail'), - 'country' => __('Pays'), - ] - ]); - - $this->addField(['name' => 'count_for_score', - 'label' => __('Comptabiliser dans le score'), - 'type' => 'Checkbox', - 'default' => true]); - - $this->addField(['name' => 'placeholder', - 'type' => 'Text', - 'label' => __('Placeholder'), - 'hint' => __('Texte affiché lorsque le champ n\'a pas été rempli'), - 'when' => ['type' => ['text', 'textarea', 'email']] - ]); - - $this->addField(['name' => 'explaination', - 'type' => 'Textarea', - 'label' => __('Explication ou réponse détaillée'), - 'hint' => __('Texte affiché lors du passage en revue des réponses'), - ]); - - $this->addField(['name' => 'multiple', - 'type' => 'Checkbox', - 'label' => __('Réponses multiples'), - 'when' => ['type' => 'multiple'] - ]); - - $this->addField([ - 'name' => 'min_score', - 'type' => 'Integer', - 'label' => __('Score minimum nécessaire pour réussir'), - 'hint' => __('0 signifie que toutes et seulement les réponses correctes doivent être cochées.'), - 'default' => 0, - 'when' => ['type' => 'multiple', 'multiple' => 1] - ]); - - $this->addField([ - 'name' => 'answers', - 'type' => 'BunchOfFieldsMultiple', - 'bunch' => 'App\SubForms\Answer', - 'add_label' => __('Nouvelle réponse'), - 'label' => __('Réponses'), - 'when' => ['type' => 'multiple'] - ]); - - - } -} diff --git a/app/SubForms/Quiz/Answer.php b/app/SubForms/Quiz/Answer.php new file mode 100644 index 000000000..9b295e50b --- /dev/null +++ b/app/SubForms/Quiz/Answer.php @@ -0,0 +1,29 @@ +addField(['name' => 'answer', + 'type' => 'Text', + 'label' => __('Texte de la réponse') + ]); + + $this->addField(['name' => 'correct', + 'type' => 'Checkbox', + 'label' => __('Réponse correcte')]); + + $this->addField(['name' => 'score', + 'type' => Integer::class, + 'label' => __('Score'), + 'default' => 1]); + } +} diff --git a/app/SubForms/Quiz/Question.php b/app/SubForms/Quiz/Question.php new file mode 100644 index 000000000..d96353ed2 --- /dev/null +++ b/app/SubForms/Quiz/Question.php @@ -0,0 +1,86 @@ +addField(['name' => 'question', + 'type' => 'Text', + 'label' => __('Intitulé de la question'), + ]); + + $this->addField(['name' => 'required', + 'type' => 'Checkbox', + 'default' => true, + 'label' => __('Réponse obligatoire')]); + + $this->addField(['name' => 'report_label', + 'type' => 'Text', + 'label' => __('Intitulé de la question dans les rapports'), + ]); + + $this->addField(['name' => 'type', + 'type' => 'SelectFromArray', + 'label' => __('Type'), + 'default' => 'multiple', + 'options' => [ + 'multiple' => __('Question à choix multiple'), + 'text' => __('Texte'), + 'textarea' => __('Texte long'), + 'email' => __('E-mail'), + 'country' => __('Pays'), + ] + ]); + + $this->addField(['name' => 'count_for_score', + 'label' => __('Comptabiliser dans le score'), + 'type' => 'Checkbox', + 'default' => true]); + + $this->addField(['name' => 'placeholder', + 'type' => 'Text', + 'label' => __('Placeholder'), + 'hint' => __('Texte affiché lorsque le champ n\'a pas été rempli'), + 'when' => ['type' => ['text', 'textarea', 'email']] + ]); + + $this->addField(['name' => 'explaination', + 'type' => 'Textarea', + 'label' => __('Explication ou réponse détaillée'), + 'hint' => __('Texte affiché lors du passage en revue des réponses'), + ]); + + $this->addField(['name' => 'multiple', + 'type' => 'Checkbox', + 'label' => __('Réponses multiples'), + 'when' => ['type' => 'multiple'] + ]); + + $this->addField([ + 'name' => 'min_score', + 'type' => 'Integer', + 'label' => __('Score minimum nécessaire pour réussir'), + 'hint' => __('0 signifie que toutes et seulement les réponses correctes doivent être cochées.'), + 'default' => 0, + 'when' => ['type' => 'multiple', 'multiple' => 1] + ]); + + $this->addField([ + 'name' => 'answers', + 'type' => 'BunchOfFieldsMultiple', + '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'), + ]); + } +}