Przeglądaj źródła

Add new exercise settings to handle page results UI see BT#15844

New config:
$_configuration['allow_quiz_results_page_config'] = false;

Requires a DB change.
Julio Montoya 5 lat temu
rodzic
commit
84d4105a90

+ 3 - 1
main/exercise/Draggable.php

@@ -217,7 +217,9 @@ class Draggable extends Question
 
         if ($exercise->showExpectedChoice()) {
             $header .= '<th>'.get_lang('YourChoice').'</th>';
-            $header .= '<th>'.get_lang('ExpectedChoice').'</th>';
+            if ($exercise->showExpectedChoiceColumn()) {
+                $header .= '<th>'.get_lang('ExpectedChoice').'</th>';
+            }
         } else {
             $header .= '<th>'.get_lang('ElementList').'</th>';
         }

+ 3 - 1
main/exercise/MatchingDraggable.php

@@ -274,7 +274,9 @@ class MatchingDraggable extends Question
         }
 
         if ($exercise->showExpectedChoice()) {
-            $header .= '<th>'.get_lang('ExpectedChoice').'</th>';
+            if ($exercise->showExpectedChoiceColumn()) {
+                $header .= '<th>'.get_lang('ExpectedChoice').'</th>';
+            }
             $header .= '<th>'.get_lang('Status').'</th>';
         } else {
             $header .= '<th>'.get_lang('CorrespondsTo').'</th>';

+ 8 - 7
main/exercise/MultipleAnswerTrueFalseDegreeCertainty.php

@@ -306,13 +306,14 @@ class MultipleAnswerTrueFalseDegreeCertainty extends Question
     public function return_header(Exercise $exercise, $counter = null, $score = [])
     {
         $header = parent::return_header($exercise, $counter, $score);
-        $header .= '<table class="'
-            .$this->question_table_class
-            .'"><tr><th>'
-            .get_lang('Choice')
-            .'</th><th>'
-            .get_lang('ExpectedChoice')
-            .'</th><th>'
+        $header .= '<table class="'.$this->question_table_class.'"><tr>';
+        $header .= '<th>'.get_lang('Choice').'</th>';
+
+        if ($exercise->showExpectedChoiceColumn()) {
+            $header .= '<th>'.get_lang('ExpectedChoice').'</th>';
+        }
+
+        $header .='<th>'
             .get_lang('Answer')
             .'</th><th colspan="2" style="text-align:center;">'
             .get_lang('YourDegreeOfCertainty')

+ 5 - 3
main/exercise/UniqueAnswerImage.php

@@ -351,9 +351,11 @@ class UniqueAnswerImage extends UniqueAnswer
         if ($exercise->showExpectedChoice()) {
             $header = '<table class="'.$this->question_table_class.'">
 			<tr>
-				<th>'.get_lang('Choice').'</th>
-				<th>'.get_lang('ExpectedChoice').'</th>
-				<th>'.get_lang('Answer').'</th>';
+				<th>'.get_lang('Choice').'</th>';
+            if ($exercise->showExpectedChoiceColumn()) {
+                $header .= '<th>'.get_lang('ExpectedChoice').'</th>';
+            }
+            $header .= '<th>'.get_lang('Answer').'</th>';
             $header .= '<th>'.get_lang('Status').'</th>';
             $header .= '<th>'.get_lang('Comment').'</th>';
             $header .= '</tr>';

+ 3 - 1
main/exercise/calculated_answer.class.php

@@ -252,7 +252,9 @@ class CalculatedAnswer extends Question
         $header .= '<th>'.get_lang('Answer').'</th>';
         if ($exercise->showExpectedChoice()) {
             $header .= '<th>'.get_lang('YourChoice').'</th>';
-            $header .= '<th>'.get_lang('ExpectedChoice').'</th>';
+            if ($exercise->showExpectedChoiceColumn()) {
+                $header .= '<th>'.get_lang('ExpectedChoice').'</th>';
+            }
             $header .= '<th>'.get_lang('Status').'</th>';
         }
         $header .= '</tr>';

+ 177 - 31
main/exercise/exercise.class.php

@@ -3,6 +3,7 @@
 
 use Chamilo\CoreBundle\Entity\TrackEHotspot;
 use ChamiloSession as Session;
+use Doctrine\DBAL\Types\Type;
 
 /**
  * Class Exercise.
@@ -84,6 +85,7 @@ class Exercise
     public $export = false;
     public $autolaunch;
     public $exerciseCategoryId;
+    public $pageResultConfiguration;
 
     /**
      * Constructor of the class.
@@ -201,6 +203,10 @@ class Exercise
                 $this->notifications = explode(',', $object->notifications);
             }
 
+            if (!empty($object->page_result_configuration)) {
+                $this->pageResultConfiguration = $object->page_result_configuration;
+            }
+
             if (isset($object->show_previous_button)) {
                 $this->showPreviousButton = $object->show_previous_button == 1 ? true : false;
             }
@@ -1588,6 +1594,11 @@ class Exercise
                     $notifications = implode(',', $notifications);
                     $paramsExtra['notifications'] = $notifications;
                 }
+
+                $pageConfig = api_get_configuration_value('allow_quiz_results_page_config');
+                if ($pageConfig && !empty($this->pageResultConfiguration)) {
+                    $paramsExtra['page_result_configuration'] = $this->pageResultConfiguration;
+                }
             }
 
             $params = array_merge($params, $paramsExtra);
@@ -1673,6 +1684,11 @@ class Exercise
                 }
             }
 
+            $pageConfig = api_get_configuration_value('allow_quiz_results_page_config');
+            if ($pageConfig && !empty($this->pageResultConfiguration)) {
+                $params['page_result_configuration'] = $this->pageResultConfiguration;
+            }
+
             $this->id = $this->iId = Database::insert($TBL_EXERCISES, $params);
 
             if ($this->id) {
@@ -2085,6 +2101,31 @@ class Exercise
                 ]
             );
 
+            $pageConfig = api_get_configuration_value('allow_quiz_results_page_config');
+            if ($pageConfig) {
+                $group = [
+                    $form->createElement(
+                        'checkbox',
+                        'hide_expected_answer',
+                        null,
+                        get_lang('HideExpectedAnswer')
+                    ),
+                    $form->createElement(
+                        'checkbox',
+                        'hide_total_score',
+                        null,
+                        get_lang('HideTotalScore')
+                    ),
+                    $form->createElement(
+                        'checkbox',
+                        'hide_question_score',
+                        null,
+                        get_lang('HideQuestionScore')
+                    )
+                ];
+                $form->addGroup($group, null, get_lang('ResultsConfigurationPage'));
+            }
+
             $displayMatrix = 'none';
             $displayRandom = 'none';
             $selectionType = $this->getQuestionSelectionType();
@@ -2132,13 +2173,6 @@ class Exercise
             $form->addElement('label', null, $cat_form);
             $form->addElement('html', '</div>');
 
-            // Category name.
-            $radio_display_cat_name = [
-                $form->createElement('radio', 'display_category_name', null, get_lang('Yes'), '1'),
-                $form->createElement('radio', 'display_category_name', null, get_lang('No'), '0'),
-            ];
-            $form->addGroup($radio_display_cat_name, null, get_lang('QuestionDisplayCategoryName'));
-
             // Random answers.
             $radios_random_answers = [
                 $form->createElement('radio', 'randomAnswers', null, get_lang('Yes'), '1'),
@@ -2146,6 +2180,13 @@ class Exercise
             ];
             $form->addGroup($radios_random_answers, null, get_lang('RandomAnswers'));
 
+            // Category name.
+            $radio_display_cat_name = [
+                $form->createElement('radio', 'display_category_name', null, get_lang('Yes'), '1'),
+                $form->createElement('radio', 'display_category_name', null, get_lang('No'), '0'),
+            ];
+            $form->addGroup($radio_display_cat_name, null, get_lang('QuestionDisplayCategoryName'));
+
             // Hide question title.
             $group = [
                 $form->createElement('radio', 'hide_question_title', null, get_lang('Yes'), '1'),
@@ -2370,12 +2411,7 @@ class Exercise
             $form->addRule('end_time', get_lang('InvalidDate'), 'datetime');
 
             if ($this->id > 0) {
-                //if ($this->random > $this->selectNbrQuestions()) {
-                //    $defaults['randomQuestions'] = $this->selectNbrQuestions();
-                //} else {
                 $defaults['randomQuestions'] = $this->random;
-                //}
-
                 $defaults['randomAnswers'] = $this->getRandomAnswers();
                 $defaults['exerciseType'] = $this->selectType();
                 $defaults['exerciseTitle'] = $this->get_formated_title();
@@ -2443,6 +2479,9 @@ class Exercise
         if (api_get_setting('search_enabled') === 'true') {
             $defaults['index_document'] = 'checked="checked"';
         }
+
+
+        $this->setPageResultConfigurationDefaults($defaults);
         $form->setDefaults($defaults);
 
         // Freeze some elements.
@@ -2572,6 +2611,7 @@ class Exercise
         $this->setShowPreviousButton($form->getSubmitValue('show_previous_button'));
         $this->setNotifications($form->getSubmitValue('notifications'));
         $this->setExerciseCategoryId($form->getSubmitValue('exercise_category_id'));
+        $this->setPageResultConfiguration($form->getSubmitValues());
 
         $this->start_time = null;
         if ($form->getSubmitValue('activate_start_date_check') == 1) {
@@ -4351,10 +4391,12 @@ class Exercise
                                     case MATCHING:
                                     case MATCHING_DRAGGABLE:
                                         echo '<tr>';
-                                        if (!in_array($this->results_disabled, [
-                                            RESULT_DISABLE_SHOW_ONLY_IN_CORRECT_ANSWER,
-                                            //RESULT_DISABLE_SHOW_SCORE_AND_EXPECTED_ANSWERS_AND_RANKING,
-                                            ])
+                                        if (!in_array(
+                                            $this->results_disabled,
+                                            [
+                                                RESULT_DISABLE_SHOW_ONLY_IN_CORRECT_ANSWER,
+                                            ]
+                                        )
                                         ) {
                                             echo '<td>'.$s_answer_label.'</td>';
                                             echo '<td>'.$user_answer.'</td>';
@@ -4364,31 +4406,35 @@ class Exercise
                                         }
 
                                         if ($this->showExpectedChoice()) {
-                                            echo '<td>';
-                                            if (in_array($answerType, [MATCHING, MATCHING_DRAGGABLE])) {
-                                                if (isset($real_list[$i_answer_correct_answer]) &&
-                                                    $showTotalScoreAndUserChoicesInLastAttempt == true
-                                                ) {
-                                                    echo Display::span(
-                                                        $real_list[$i_answer_correct_answer]
-                                                    );
+                                            if ($this->showExpectedChoiceColumn()) {
+                                                echo '<td>';
+                                                if (in_array($answerType, [MATCHING, MATCHING_DRAGGABLE])) {
+                                                    if (isset($real_list[$i_answer_correct_answer]) &&
+                                                        $showTotalScoreAndUserChoicesInLastAttempt == true
+                                                    ) {
+                                                        echo Display::span(
+                                                            $real_list[$i_answer_correct_answer]
+                                                        );
+                                                    }
                                                 }
+                                                echo '</td>';
                                             }
-                                            echo '</td>';
                                             echo '<td>'.$status.'</td>';
                                         } else {
-                                            echo '<td>';
                                             if (in_array($answerType, [MATCHING, MATCHING_DRAGGABLE])) {
                                                 if (isset($real_list[$i_answer_correct_answer]) &&
                                                     $showTotalScoreAndUserChoicesInLastAttempt === true
                                                 ) {
-                                                    echo Display::span(
-                                                        $real_list[$i_answer_correct_answer],
-                                                        ['style' => 'color: #008000; font-weight: bold;']
-                                                    );
+                                                    if ($this->showExpectedChoiceColumn()) {
+                                                        echo '<td>';
+                                                        echo Display::span(
+                                                            $real_list[$i_answer_correct_answer],
+                                                            ['style' => 'color: #008000; font-weight: bold;']
+                                                        );
+                                                        echo '</td>';
+                                                    }
                                                 }
                                             }
-                                            echo '</td>';
                                         }
                                         echo '</tr>';
                                         break;
@@ -4696,6 +4742,7 @@ class Exercise
                             );
                         } elseif ($answerType == MULTIPLE_ANSWER_TRUE_FALSE_DEGREE_CERTAINTY) {
                             ExerciseShowFunctions::displayMultipleAnswerTrueFalseDegreeCertainty(
+                                $this,
                                 $feedback_type,
                                 $studentChoice,
                                 $studentChoiceDegree,
@@ -4722,6 +4769,7 @@ class Exercise
                             );
                         } elseif ($answerType == FILL_IN_BLANKS) {
                             ExerciseShowFunctions::display_fill_in_blanks_answer(
+                                $this,
                                 $feedback_type,
                                 $answer,
                                 0,
@@ -5092,6 +5140,7 @@ class Exercise
                         case MULTIPLE_ANSWER_TRUE_FALSE_DEGREE_CERTAINTY:
                             if ($answerId == 1) {
                                 ExerciseShowFunctions::displayMultipleAnswerTrueFalseDegreeCertainty(
+                                    $this,
                                     $feedback_type,
                                     $studentChoice,
                                     $studentChoiceDegree,
@@ -5103,6 +5152,7 @@ class Exercise
                                 );
                             } else {
                                 ExerciseShowFunctions::displayMultipleAnswerTrueFalseDegreeCertainty(
+                                    $this,
                                     $feedback_type,
                                     $studentChoice,
                                     $studentChoiceDegree,
@@ -5116,6 +5166,7 @@ class Exercise
                             break;
                         case FILL_IN_BLANKS:
                             ExerciseShowFunctions::display_fill_in_blanks_answer(
+                                $this,
                                 $feedback_type,
                                 $answer,
                                 $exeId,
@@ -7885,6 +7936,76 @@ class Exercise
         $this->exerciseCategoryId = (int) $value;
     }
 
+    /**
+     * @param array $values
+     *
+     * @throws \Doctrine\DBAL\DBALException
+     */
+    public function setPageResultConfiguration($values)
+    {
+        $pageConfig = api_get_configuration_value('allow_quiz_results_page_config');
+        if ($pageConfig) {
+            $params = [
+                'hide_expected_answer' => isset($values['hide_expected_answer']) ? $values['hide_expected_answer'] : '',
+                'hide_question_score' => isset($values['hide_question_score']) ? $values['hide_question_score'] : '',
+                'hide_total_score' => isset($values['hide_total_score']) ? $values['hide_total_score'] : ''
+            ];
+            $type = Type::getType('array');
+            $platform = Database::getManager()->getConnection()->getDatabasePlatform();
+            $this->pageResultConfiguration = $type->convertToDatabaseValue($params, $platform);
+        }
+    }
+
+    /**
+     * @param array $defaults
+     */
+    public function setPageResultConfigurationDefaults(&$defaults)
+    {
+        $configuration = $this->getPageResultConfiguration();
+        if (!empty($configuration) && !empty($defaults)) {
+            $defaults = array_merge($defaults, $configuration);
+        }
+    }
+
+    /**
+     * @return array
+     */
+    public function getPageResultConfiguration()
+    {
+        $pageConfig = api_get_configuration_value('allow_quiz_results_page_config');
+        if ($pageConfig) {
+            /*$params = [
+                'hide_expected_answer' => isset($values['hide_expected_answer']) ? $values['hide_expected_answer'] : '',
+                'hide_question_score' => isset($values['hide_question_score']) ? $values['hide_question_score'] : '',
+                'hide_total_score' => isset($values['hide_total_score']) ? $values['hide_total_score'] : ''
+            ];*/
+            $type = \Doctrine\DBAL\Types\Type::getType('array');
+            $platform = Database::getManager()->getConnection()->getDatabasePlatform();
+            $result = $type->convertToPHPValue($this->pageResultConfiguration, $platform);
+
+            return $result;
+        }
+
+        return $this->pageResultConfiguration;
+    }
+
+    /**
+     * @param string $attribute
+     *
+     * @return mixed|null
+     */
+    public function getPageConfigurationAttribute($attribute)
+    {
+        $result = $this->getPageResultConfiguration();
+
+        if (!empty($result)) {
+            $value = isset($result[$attribute]) ? $result[$attribute] : null;
+            return $value;
+        }
+
+        return null;
+    }
+
     /**
      * @param bool $showPreviousButton
      *
@@ -7921,6 +8042,26 @@ class Exercise
         return api_get_configuration_value('show_exercise_expected_choice');
     }
 
+    /**
+     * @return bool
+     */
+    public function showExpectedChoiceColumn()
+    {
+        if (!in_array($this->results_disabled, [
+            RESULT_DISABLE_SHOW_ONLY_IN_CORRECT_ANSWER
+        ])
+        ) {
+            $hide = (int) $this->getPageConfigurationAttribute('hide_expected_answer');
+            if ($hide === 1) {
+                return false;
+            }
+
+            return true;
+        }
+
+        return false;
+    }
+
     /**
      * @param string $class
      * @param string $scoreLabel
@@ -7931,6 +8072,11 @@ class Exercise
      */
     public function getQuestionRibbon($class, $scoreLabel, $result, $array)
     {
+        $hide = (int) $this->getPageConfigurationAttribute('hide_question_score');
+        if ($hide === 1) {
+            return '';
+        }
+
         if ($this->showExpectedChoice()) {
             $html = null;
             $hideLabel = api_get_configuration_value('exercise_hide_label');

+ 4 - 6
main/exercise/global_multiple_answer.class.php

@@ -266,13 +266,11 @@ class GlobalMultipleAnswer extends Question
         $header = parent::return_header($exercise, $counter, $score);
         $header .= '<table class="'.$this->question_table_class.'"><tr>';
 
-        if (!in_array($exercise->results_disabled, [
-            RESULT_DISABLE_SHOW_ONLY_IN_CORRECT_ANSWER,
-            //RESULT_DISABLE_SHOW_SCORE_AND_EXPECTED_ANSWERS_AND_RANKING,
-        ])
-        ) {
+        if (!in_array($exercise->results_disabled, [RESULT_DISABLE_SHOW_ONLY_IN_CORRECT_ANSWER])) {
             $header .= '<th>'.get_lang('Choice').'</th>';
-            $header .= '<th>'.get_lang('ExpectedChoice').'</th>';
+            if ($exercise->showExpectedChoiceColumn()) {
+                $header .= '<th>'.get_lang('ExpectedChoice').'</th>';
+            }
         }
 
         $header .= '<th>'.get_lang('Answer').'</th>';

+ 6 - 2
main/exercise/matching.class.php

@@ -292,13 +292,17 @@ class Matching extends Question
         ])
         ) {
             $header .= '<th>'.get_lang('Choice').'</th>';
-            $header .= '<th>'.get_lang('ExpectedChoice').'</th>';
+            //if ($exercise->showExpectedChoiceColumn()) {
+                //$header .= '<th>'.get_lang('ExpectedChoice').'</th>';
+            //}
         }
 
         if ($exercise->showExpectedChoice()) {
             $header .= '<th>'.get_lang('Status').'</th>';
         } else {
-            $header .= '<th>'.get_lang('CorrespondsTo').'</th>';
+            if ($exercise->showExpectedChoiceColumn()) {
+                $header .= '<th>'.get_lang('CorrespondsTo').'</th>';
+            }
         }
         $header .= '</tr>';
 

+ 2 - 5
main/exercise/multiple_answer.class.php

@@ -235,11 +235,8 @@ class MultipleAnswer extends Question
         $header .= '<table class="'.$this->question_table_class.'"><tr>';
 
         $header .= '<th>'.get_lang('Choice').'</th>';
-        if (!in_array($exercise->results_disabled, [
-            RESULT_DISABLE_SHOW_ONLY_IN_CORRECT_ANSWER,
-            //RESULT_DISABLE_SHOW_SCORE_AND_EXPECTED_ANSWERS_AND_RANKING,
-        ])
-        ) {
+
+        if ($exercise->showExpectedChoiceColumn()) {
             $header .= '<th>'.get_lang('ExpectedChoice').'</th>';
         }
 

+ 4 - 3
main/exercise/multiple_answer_combination.class.php

@@ -233,12 +233,13 @@ class MultipleAnswerCombination extends Question
         $header .= '<table class="'.$this->question_table_class.'"><tr>';
 
         if (!in_array($exercise->results_disabled, [
-            RESULT_DISABLE_SHOW_ONLY_IN_CORRECT_ANSWER,
-            //RESULT_DISABLE_SHOW_SCORE_AND_EXPECTED_ANSWERS_AND_RANKING,
+            RESULT_DISABLE_SHOW_ONLY_IN_CORRECT_ANSWER
         ])
         ) {
             $header .= '<th>'.get_lang('Choice').'</th>';
-            $header .= '<th>'.get_lang('ExpectedChoice').'</th>';
+            if ($exercise->showExpectedChoiceColumn()) {
+                $header .= '<th>'.get_lang('ExpectedChoice').'</th>';
+            }
         }
 
         $header .= '<th>'.get_lang('Answer').'</th>';

+ 4 - 3
main/exercise/multiple_answer_true_false.class.php

@@ -314,12 +314,13 @@ class MultipleAnswerTrueFalse extends Question
         $header .= '<table class="'.$this->question_table_class.'"><tr>';
 
         if (!in_array($exercise->results_disabled, [
-            RESULT_DISABLE_SHOW_ONLY_IN_CORRECT_ANSWER,
-            //RESULT_DISABLE_SHOW_SCORE_AND_EXPECTED_ANSWERS_AND_RANKING,
+            RESULT_DISABLE_SHOW_ONLY_IN_CORRECT_ANSWER
         ])
         ) {
             $header .= '<th>'.get_lang('Choice').'</th>';
-            $header .= '<th>'.get_lang('ExpectedChoice').'</th>';
+            if ($exercise->showExpectedChoiceColumn()) {
+                $header .= '<th>'.get_lang('ExpectedChoice').'</th>';
+            }
         }
 
         $header .= '<th>'.get_lang('Answer').'</th>';

+ 1 - 5
main/exercise/unique_answer.class.php

@@ -435,11 +435,7 @@ class UniqueAnswer extends Question
         $header .= '<table class="'.$this->question_table_class.'"><tr>';
 
         $header .= '<th>'.get_lang('Choice').'</th>';
-        if (!in_array($exercise->results_disabled, [
-            RESULT_DISABLE_SHOW_ONLY_IN_CORRECT_ANSWER,
-            //RESULT_DISABLE_SHOW_SCORE_AND_EXPECTED_ANSWERS_AND_RANKING,
-        ])
-        ) {
+        if ($exercise->showExpectedChoiceColumn()) {
             $header .= '<th>'.get_lang('ExpectedChoice').'</th>';
         }
 

+ 4 - 3
main/exercise/unique_answer_no_option.class.php

@@ -405,12 +405,13 @@ class UniqueAnswerNoOption extends Question
         $header .= '<table class="'.$this->question_table_class.'"><tr>';
 
         if (!in_array($exercise->results_disabled, [
-            RESULT_DISABLE_SHOW_ONLY_IN_CORRECT_ANSWER,
-            //RESULT_DISABLE_SHOW_SCORE_AND_EXPECTED_ANSWERS_AND_RANKING,
+            RESULT_DISABLE_SHOW_ONLY_IN_CORRECT_ANSWER
         ])
         ) {
             $header .= '<th>'.get_lang('Choice').'</th>';
-            $header .= '<th>'.get_lang('ExpectedChoice').'</th>';
+            if ($exercise->showExpectedChoiceColumn()) {
+                $header .= '<th>'.get_lang('ExpectedChoice').'</th>';
+            }
         }
         $header .= '<th>'.get_lang('Answer').'</th>';
         if ($exercise->showExpectedChoice()) {

+ 1 - 3
main/gradebook/lib/be/category.class.php

@@ -523,9 +523,7 @@ class Category implements GradebookItem
         $result = Database::query($sql);
         $categories = [];
         if (Database::num_rows($result) > 0) {
-            $categories = self::create_category_objects_from_sql_result(
-                $result
-            );
+            $categories = self::create_category_objects_from_sql_result($result);
         }
 
         return $categories;

+ 6 - 0
main/inc/lib/exercise.lib.php

@@ -5061,6 +5061,7 @@ EOT;
             $ribbon .= '<h3>'.get_lang('YourTotalScore').':&nbsp;';
             $ribbon .= self::show_score($score, $weight, false, true);
             $ribbon .= '</h3>';
+
             $ribbon .= '</div>';
         }
 
@@ -5093,6 +5094,11 @@ EOT;
         $checkPassPercentage = false,
         $countPendingQuestions = 0
     ) {
+        $hide = (int) $objExercise->getPageConfigurationAttribute('hide_total_score');
+        if ($hide === 1) {
+            return '';
+        }
+
         $passPercentage = $objExercise->selectPassPercentage();
         $ribbon = '<div class="title-score">';
         if ($checkPassPercentage) {

+ 84 - 55
main/inc/lib/exercise_show_functions.lib.php

@@ -22,15 +22,17 @@ class ExerciseShowFunctions
     /**
      * Shows the answer to a fill-in-the-blanks question, as HTML.
      *
-     * @param int    $feedbackType
-     * @param string $answer
-     * @param int    $id                           Exercise ID
-     * @param int    $questionId                   Question ID
-     * @param int    $resultsDisabled
-     * @param string $originalStudentAnswer
-     * @param bool   $showTotalScoreAndUserChoices
+     * @param Exercise $exercise
+     * @param int      $feedbackType
+     * @param string   $answer
+     * @param int      $id         Exercise ID
+     * @param int      $questionId Question ID
+     * @param int      $resultsDisabled
+     * @param string   $originalStudentAnswer
+     * @param bool     $showTotalScoreAndUserChoices
      */
     public static function display_fill_in_blanks_answer(
+        $exercise,
         $feedbackType,
         $answer,
         $id,
@@ -82,7 +84,10 @@ class ExerciseShowFunctions
             if (empty($id)) {
                 echo '<tr><td>'.Security::remove_XSS($answer).'</td>';
                 echo '<td>'.Security::remove_XSS($choice).'</td>';
-                echo '<td>'.Security::remove_XSS($expectedChoice).'</td>';
+                if ($exercise->showExpectedChoiceColumn()) {
+                    echo '<td>'.Security::remove_XSS($expectedChoice).'</td>';
+                }
+
                 echo '<td>'.Security::remove_XSS($status).'</td>';
                 echo '</tr>';
             } else {
@@ -90,9 +95,13 @@ class ExerciseShowFunctions
                 echo Security::remove_XSS($answer);
                 echo '</td><td>';
                 echo Security::remove_XSS($choice);
-                echo '</td><td>';
-                echo Security::remove_XSS($expectedChoice);
-                echo '</td><td>';
+                echo '</td>';
+                if ($exercise->showExpectedChoiceColumn()) {
+                    echo '<td>';
+                    echo Security::remove_XSS($expectedChoice);
+                    echo '</td>';
+                }
+                echo '<td>';
                 echo Security::remove_XSS($status);
                 echo '</td>';
                 echo '</tr>';
@@ -135,7 +144,7 @@ class ExerciseShowFunctions
             if ($questionScore > 0 || !empty($comments)) {
             } else {
                 echo '<tr>';
-                echo Display::tag('td', ExerciseLib::getNotCorrectedYetText(), []);
+                echo Display::tag('td', ExerciseLib::getNotCorrectedYetText());
                 echo '</tr>';
             }
         }
@@ -344,7 +353,6 @@ class ExerciseShowFunctions
         $showComment = false;
         switch ($resultsDisabled) {
             case RESULT_DISABLE_SHOW_ONLY_IN_CORRECT_ANSWER:
-            //case RESULT_DISABLE_SHOW_SCORE_AND_EXPECTED_ANSWERS_AND_RANKING:
                 $hideStudentChoice = false;
                 $hide_expected_answer = true;
                 $status = Display::label(get_lang('Correct'), 'success');
@@ -375,10 +383,13 @@ class ExerciseShowFunctions
         $iconAnswer .= '.png';
 
         $studentChoiceClass = '';
-        if (in_array($resultsDisabled, [
-            RESULT_DISABLE_SHOW_ONLY_IN_CORRECT_ANSWER,
-            RESULT_DISABLE_SHOW_SCORE_AND_EXPECTED_ANSWERS_AND_RANKING,
-        ])
+        if (in_array(
+            $resultsDisabled,
+            [
+                RESULT_DISABLE_SHOW_ONLY_IN_CORRECT_ANSWER,
+                RESULT_DISABLE_SHOW_SCORE_AND_EXPECTED_ANSWERS_AND_RANKING,
+            ]
+        )
         ) {
             if ($answerCorrect) {
                 $studentChoiceClass = 'success';
@@ -393,9 +404,11 @@ class ExerciseShowFunctions
         }
 
         if (!$hide_expected_answer) {
-            echo '<td width="5%">';
-            echo Display::return_icon($iconAnswer, null, null, ICON_SIZE_TINY);
-            echo '</td>';
+            if ($exercise->showExpectedChoiceColumn()) {
+                echo '<td width="5%">';
+                echo Display::return_icon($iconAnswer, null, null, ICON_SIZE_TINY);
+                echo '</td>';
+            }
         }
 
         echo '<td width="40%">';
@@ -498,13 +511,15 @@ class ExerciseShowFunctions
 
         // Expected choice
         if (!$hide_expected_answer) {
-            $content .= '<td width="5%">';
-            if (isset($new_options[$answerCorrect])) {
-                $content .= get_lang($new_options[$answerCorrect]['name']);
-            } else {
-                $content .= '-';
+            if ($exercise->showExpectedChoiceColumn()) {
+                $content .= '<td width="5%">';
+                if (isset($new_options[$answerCorrect])) {
+                    $content .= get_lang($new_options[$answerCorrect]['name']);
+                } else {
+                    $content .= '-';
+                }
+                $content .= '</td>';
             }
-            $content .= '</td>';
         }
 
         $content .= '<td width="40%">';
@@ -553,16 +568,18 @@ class ExerciseShowFunctions
     /**
      * Display the answers to a multiple choice question.
      *
-     * @param int    $feedbackType
-     * @param int    $studentChoice
-     * @param int    $studentChoiceDegree
-     * @param string $answer
-     * @param string $answerComment
-     * @param int    $answerCorrect
-     * @param int    $questionId
-     * @param bool   $inResultsDisabled
+     * @param Exercise $exercise
+     * @param int      $feedbackType
+     * @param int      $studentChoice
+     * @param int      $studentChoiceDegree
+     * @param string   $answer
+     * @param string   $answerComment
+     * @param int      $answerCorrect
+     * @param int      $questionId
+     * @param bool     $inResultsDisabled
      */
     public static function displayMultipleAnswerTrueFalseDegreeCertainty(
+        $exercise,
         $feedbackType,
         $studentChoice,
         $studentChoiceDegree,
@@ -582,26 +599,30 @@ class ExerciseShowFunctions
         $courseId = api_get_course_int_id();
         $newOptions = Question::readQuestionOption($questionId, $courseId);
 
-        //Your choice
+        // Your choice
         if (isset($newOptions[$studentChoice])) {
             echo get_lang($newOptions[$studentChoice]['name']);
         } else {
             echo '-';
         }
-        echo '</td><td width="5%">';
+        echo '</td>';
 
         // Expected choice
-        if (!$hideExpectedAnswer) {
-            if (isset($newOptions[$answerCorrect])) {
-                echo get_lang($newOptions[$answerCorrect]['name']);
+        if ($exercise->showExpectedChoiceColumn()) {
+            echo '<td width="5%">';
+            if (!$hideExpectedAnswer) {
+                if (isset($newOptions[$answerCorrect])) {
+                    echo get_lang($newOptions[$answerCorrect]['name']);
+                } else {
+                    echo '-';
+                }
             } else {
                 echo '-';
             }
-        } else {
-            echo '-';
+            echo '</td>';
         }
 
-        echo '</td><td width="20%">';
+        echo '<td width="20%">';
         echo $answer;
         echo '</td><td width="5%" style="text-align:center;">';
         if (isset($newOptions[$studentChoiceDegree])) {
@@ -609,12 +630,18 @@ class ExerciseShowFunctions
         }
         echo '</td>';
 
+        $position = isset($newOptions[$studentChoiceDegree]) ? $newOptions[$studentChoiceDegree]['position'] : '';
         $degreeInfo = $question->getResponseDegreeInfo(
             $studentChoice,
             $answerCorrect,
-            $newOptions[$studentChoiceDegree]['position']
+            $position
         );
 
+        $degreeInfo['color'] = isset($degreeInfo['color']) ? $degreeInfo['color'] : '';
+        $degreeInfo['background-color'] = isset($degreeInfo['background-color']) ? $degreeInfo['background-color'] : '';
+        $degreeInfo['description'] = isset($degreeInfo['description']) ? $degreeInfo['description'] : '';
+        $degreeInfo['label'] = isset($degreeInfo['label']) ? $degreeInfo['label'] : '';
+
         echo '
             <td width="15%">
                 <div style="text-align:center;color: '.$degreeInfo['color'].';
@@ -701,14 +728,16 @@ class ExerciseShowFunctions
         }
 
         // Expected choice
-        if (!$hide_expected_answer) {
-            echo '<td width="5%">';
-            if (isset($question->options[$answerCorrect])) {
-                echo $question->options[$answerCorrect];
-            } else {
-                echo $question->options[2];
+        if ($exercise->showExpectedChoiceColumn()) {
+            if (!$hide_expected_answer) {
+                echo '<td width="5%">';
+                if (isset($question->options[$answerCorrect])) {
+                    echo $question->options[$answerCorrect];
+                } else {
+                    echo $question->options[2];
+                }
+                echo '</td>';
             }
-            echo '</td>';
         }
 
         echo '<td width="40%">';
@@ -753,20 +782,20 @@ class ExerciseShowFunctions
     }
 
     /**
-     * @param $feedbackType
-     * @param $exe_id
-     * @param $questionId
+     * @param int  $feedbackType
+     * @param int  $exeId
+     * @param int  $questionId
      * @param null $questionScore
      * @param int  $resultsDisabled
      */
     public static function displayAnnotationAnswer(
         $feedbackType,
-        $exe_id,
+        $exeId,
         $questionId,
         $questionScore = null,
         $resultsDisabled = 0
     ) {
-        $comments = Event::get_comments($exe_id, $questionId);
+        $comments = Event::get_comments($exeId, $questionId);
         if ($feedbackType != EXERCISE_FEEDBACK_TYPE_EXAM) {
             if ($questionScore <= 0 && empty($comments)) {
                 echo '<br />'.ExerciseLib::getNotCorrectedYetText();

+ 4 - 0
main/install/configuration.dist.php

@@ -1227,6 +1227,10 @@ $_configuration['required_extra_fields_in_profile'] = [
 // Send new user inscription notification only to general admins (table settings_current = emailAdministrator)
 //$_configuration['send_inscription_notification_to_general_admin_only'] = false;
 
+// Allow extra settings for the quiz results page
+// ALTER TABLE c_quiz ADD page_result_configuration LONGTEXT DEFAULT NULL COMMENT '(DC2Type:array)';
+//$_configuration['allow_quiz_results_page_config'] = false;
+
 // KEEP THIS AT THE END
 // -------- Custom DB changes
 // Add user activation by confirmation email