]> _ Git - fluidbook-toolbox.git/commitdiff
wip #5471 @1.5
authorVincent Vanwaelscappel <vincent@cubedesigners.com>
Wed, 19 Oct 2022 14:16:00 +0000 (16:16 +0200)
committerVincent Vanwaelscappel <vincent@cubedesigners.com>
Wed, 19 Oct 2022 14:16:00 +0000 (16:16 +0200)
app/Models/Quiz.php
app/SubForms/Answer.php [deleted file]
app/SubForms/Question.php [deleted file]
app/SubForms/Quiz/Answer.php [new file with mode: 0644]
app/SubForms/Quiz/Question.php [new file with mode: 0644]
app/SubForms/Quiz/TestResult.php [new file with mode: 0644]

index 17ac7c6e9c23ba233df1587c99f476ba5985df62..298635906a039ec56d09aeac0cd79cdd1422f3ed 100644 (file)
@@ -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 (file)
index efa5f27..0000000
+++ /dev/null
@@ -1,23 +0,0 @@
-<?php
-
-
-namespace App\SubForms;
-
-use Cubist\Backpack\Magic\SubForm;
-
-class Answer extends SubForm
-{
-    public function init()
-    {
-        parent::init();
-
-        $this->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 (file)
index 5dce61b..0000000
+++ /dev/null
@@ -1,86 +0,0 @@
-<?php
-
-
-namespace App\SubForms;
-
-use Cubist\Backpack\Magic\SubForm;
-
-class Question extends SubForm
-{
-    public function init()
-    {
-        parent::init();
-
-        $this->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 (file)
index 0000000..9b295e5
--- /dev/null
@@ -0,0 +1,29 @@
+<?php
+
+
+namespace App\SubForms\Quiz;
+
+use Cubist\Backpack\Magic\Fields\Integer;
+use Cubist\Backpack\Magic\SubForm;
+
+class Answer extends SubForm
+{
+    public function init()
+    {
+        parent::init();
+
+        $this->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 (file)
index 0000000..d96353e
--- /dev/null
@@ -0,0 +1,86 @@
+<?php
+
+
+namespace App\SubForms\Quiz;
+
+use Cubist\Backpack\Magic\SubForm;
+
+class Question extends SubForm
+{
+    public function init()
+    {
+        parent::init();
+
+        $this->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 (file)
index 0000000..898a2a5
--- /dev/null
@@ -0,0 +1,26 @@
+<?php
+
+
+namespace App\SubForms\Quiz;
+
+use Cubist\Backpack\Magic\Fields\Range;
+use Cubist\Backpack\Magic\Fields\Textarea;
+use Cubist\Backpack\Magic\SubForm;
+
+class TestResult extends SubForm
+{
+    public function init()
+    {
+        parent::init();
+
+        $this->addField(['name' => 'text',
+            'type' => Textarea::class,
+            'label' => __('Texte du résultat'),
+        ]);
+
+        $this->addField(['name' => 'score',
+            'type' => Range::class,
+            'label' => __('Score'),
+        ]);
+    }
+}