');
}
@@ -378,9 +351,11 @@ class UniqueAnswerImage extends UniqueAnswer
if ($exercise->showExpectedChoice()) {
$header = '
-
'.get_lang('Choice').'
-
'.get_lang('ExpectedChoice').'
-
'.get_lang('Answer').'
';
+
'.get_lang('Choice').'
';
+ if ($exercise->showExpectedChoiceColumn()) {
+ $header .= '
'.get_lang('ExpectedChoice').'
';
+ }
+ $header .= '
'.get_lang('Answer').'
';
$header .= '
'.get_lang('Status').'
';
$header .= '
'.get_lang('Comment').'
';
$header .= '
';
diff --git a/main/exercise/admin.php b/main/exercise/admin.php
index 393e9330bc..7a99f35983 100755
--- a/main/exercise/admin.php
+++ b/main/exercise/admin.php
@@ -453,7 +453,7 @@ if (!$newQuestion && !$modifyQuestion && !$editQuestion && !isset($_GET['hotspot
// if we are in question authoring, display warning to user is feedback not shown at the end of the test -ref #6619
// this test to display only message in the question authoring page and not in the question list page too
-if ($objExercise->selectFeedbackType() == EXERCISE_FEEDBACK_TYPE_EXAM) {
+if ($objExercise->getFeedbackType() == EXERCISE_FEEDBACK_TYPE_EXAM) {
echo Display::return_message(get_lang('TestFeedbackNotShown'), 'normal');
}
diff --git a/main/exercise/calculated_answer.class.php b/main/exercise/calculated_answer.class.php
index 4df19a690a..94ea1e7420 100644
--- a/main/exercise/calculated_answer.class.php
+++ b/main/exercise/calculated_answer.class.php
@@ -252,7 +252,9 @@ class CalculatedAnswer extends Question
$header .= '
'.get_lang('Answer').'
';
if ($exercise->showExpectedChoice()) {
$header .= '
'.get_lang('YourChoice').'
';
- $header .= '
'.get_lang('ExpectedChoice').'
';
+ if ($exercise->showExpectedChoiceColumn()) {
+ $header .= '
'.get_lang('ExpectedChoice').'
';
+ }
$header .= '
'.get_lang('Status').'
';
}
$header .= '';
diff --git a/main/exercise/exercise.class.php b/main/exercise/exercise.class.php
index d85e615b3a..8aaf59c986 100755
--- a/main/exercise/exercise.class.php
+++ b/main/exercise/exercise.class.php
@@ -1,8 +1,10 @@
globalCategoryId = null;
$this->notifications = [];
$this->exerciseCategoryId = 0;
+ $this->pageResultConfiguration;
if (!empty($courseId)) {
$courseInfo = api_get_course_info_by_id($courseId);
@@ -201,6 +205,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;
}
@@ -219,7 +227,6 @@ class Exercise
}
$this->force_edit_exercise_in_lp = api_get_setting('lp.show_invisible_exercise_in_lp_toc') === 'true';
-
$this->edit_exercise_in_lp = true;
if ($this->exercise_was_added_in_lp) {
$this->edit_exercise_in_lp = $this->force_edit_exercise_in_lp == true;
@@ -309,14 +316,15 @@ class Exercise
return $this->attempts;
}
- /** returns the number of FeedbackType *
- * 0=>Feedback , 1=>DirectFeedback, 2=>NoFeedback.
+ /**
+ * Returns the number of FeedbackType
+ * 0: Feedback , 1: DirectFeedback, 2: NoFeedback.
*
* @return int - exercise attempts
*/
- public function selectFeedbackType()
+ public function getFeedbackType()
{
- return $this->feedback_type;
+ return (int) $this->feedback_type;
}
/**
@@ -416,7 +424,7 @@ class Exercise
*
* @return string html text : the text to display ay the end of the test
*/
- public function selectTextWhenFinished()
+ public function getTextWhenFinished()
{
return $this->text_when_finished;
}
@@ -644,10 +652,10 @@ class Exercise
ON (e.question_id = q.id AND e.c_id = ".$this->course_id." )
WHERE e.exercice_id = '".$this->id."' ";
- $orderCondition = "ORDER BY question_order";
+ $orderCondition = ' ORDER BY question_order ';
if (!empty($sidx) && !empty($sord)) {
- if ($sidx == 'question') {
+ if ($sidx === 'question') {
if (in_array(strtolower($sord), ['desc', 'asc'])) {
$orderCondition = " ORDER BY q.$sidx $sord";
}
@@ -657,8 +665,8 @@ class Exercise
$sql .= $orderCondition;
$limitCondition = null;
if (isset($start) && isset($limit)) {
- $start = intval($start);
- $limit = intval($limit);
+ $start = (int) $start;
+ $limit = (int) $limit;
$limitCondition = " LIMIT $start, $limit";
}
$sql .= $limitCondition;
@@ -677,7 +685,7 @@ class Exercise
);
if (empty($category_labels)) {
- $category_labels = "-";
+ $category_labels = '-';
}
// Question type
@@ -1088,7 +1096,7 @@ class Exercise
/**
* @return int
*/
- public function selectSaveCorrectAnswers()
+ public function getSaveCorrectAnswers()
{
return $this->saveCorrectAnswers;
}
@@ -1257,7 +1265,7 @@ class Exercise
*/
public function updateSaveCorrectAnswers($value)
{
- $this->saveCorrectAnswers = $value;
+ $this->saveCorrectAnswers = (int) $value;
}
/**
@@ -1502,7 +1510,7 @@ class Exercise
$random_answers = $this->random_answers;
$active = $this->active;
$propagate_neg = (int) $this->propagate_neg;
- $saveCorrectAnswers = isset($this->saveCorrectAnswers) && $this->saveCorrectAnswers ? 1 : 0;
+ $saveCorrectAnswers = isset($this->saveCorrectAnswers) ? (int) $this->saveCorrectAnswers : 0;
$review_answers = isset($this->review_answers) && $this->review_answers ? 1 : 0;
$randomByCat = (int) $this->randomByCat;
$text_when_finished = $this->text_when_finished;
@@ -1512,7 +1520,7 @@ class Exercise
// If direct we do not show results
$results_disabled = (int) $this->results_disabled;
- if ($feedback_type == EXERCISE_FEEDBACK_TYPE_DIRECT) {
+ if (in_array($feedback_type, [EXERCISE_FEEDBACK_TYPE_DIRECT, EXERCISE_FEEDBACK_TYPE_POPUP])) {
$results_disabled = 0;
}
$expired_time = (int) $this->expired_time;
@@ -1576,6 +1584,10 @@ class Exercise
$notifications = implode(',', $notifications);
$paramsExtra['notifications'] = $notifications;
}
+
+ if (!empty($this->pageResultConfiguration)) {
+ $paramsExtra['page_result_configuration'] = $this->pageResultConfiguration;
+ }
}
$params = array_merge($params, $paramsExtra);
@@ -1636,7 +1648,7 @@ class Exercise
'text_when_finished' => $text_when_finished,
'display_category_name' => $display_category_name,
'pass_percentage' => $pass_percentage,
- 'save_correct_answers' => (int) $saveCorrectAnswers,
+ 'save_correct_answers' => $saveCorrectAnswers,
'propagate_neg' => $propagate_neg,
'hide_question_title' => $this->getHideQuestionTitle(),
];
@@ -1661,6 +1673,10 @@ class Exercise
}
}
+ if (!empty($this->pageResultConfiguration)) {
+ $params['page_result_configuration'] = $this->pageResultConfiguration;
+ }
+
$this->id = $this->iId = Database::insert($TBL_EXERCISES, $params);
if ($this->id) {
@@ -1875,14 +1891,13 @@ class Exercise
$type = 'full';
}
- // form title
+ // Form title
+ $form_title = get_lang('NewEx');
if (!empty($_GET['exerciseId'])) {
$form_title = get_lang('ModifyExercise');
- } else {
- $form_title = get_lang('NewEx');
}
- $form->addElement('header', $form_title);
+ $form->addHeader($form_title);
// Title.
if (api_get_configuration_value('save_titles_as_html')) {
@@ -1929,6 +1944,7 @@ class Exercise
'Width' => '100%',
'Height' => '150',
];
+
if (is_array($type)) {
$editor_config = array_merge($editor_config, $type);
}
@@ -1943,56 +1959,9 @@ class Exercise
$skillList = [];
if ($type === 'full') {
- //Can't modify a DirectFeedback question
- if ($this->selectFeedbackType() != EXERCISE_FEEDBACK_TYPE_DIRECT) {
- // feedback type
- $radios_feedback = [];
- $radios_feedback[] = $form->createElement(
- 'radio',
- 'exerciseFeedbackType',
- null,
- get_lang('ExerciseAtTheEndOfTheTest'),
- '0',
- [
- 'id' => 'exerciseType_0',
- 'onclick' => 'check_feedback()',
- ]
- );
-
- if (api_get_setting('enable_quiz_scenario') === 'true') {
- // Can't convert a question from one feedback to another
- // if there is more than 1 question already added
- if ($this->selectNbrQuestions() == 0) {
- $radios_feedback[] = $form->createElement(
- 'radio',
- 'exerciseFeedbackType',
- null,
- get_lang('DirectFeedback'),
- '1',
- [
- 'id' => 'exerciseType_1',
- 'onclick' => 'check_direct_feedback()',
- ]
- );
- }
- }
-
- $radios_feedback[] = $form->createElement(
- 'radio',
- 'exerciseFeedbackType',
- null,
- get_lang('NoFeedback'),
- '2',
- ['id' => 'exerciseType_2']
- );
- $form->addGroup(
- $radios_feedback,
- null,
- [
- get_lang('FeedbackType'),
- get_lang('FeedbackDisplayOptions'),
- ]
- );
+ // Can't modify a DirectFeedback question.
+ if (!in_array($this->getFeedbackType(), [EXERCISE_FEEDBACK_TYPE_DIRECT, EXERCISE_FEEDBACK_TYPE_POPUP])) {
+ $this->setResultFeedbackGroup($form);
// Type of results display on the final page
$this->setResultDisabledGroup($form);
@@ -2026,41 +1995,7 @@ class Exercise
} else {
// if is Direct feedback but has not questions we can allow to modify the question type
if ($this->getQuestionCount() === 0) {
- // feedback type
- $radios_feedback = [];
- $radios_feedback[] = $form->createElement(
- 'radio',
- 'exerciseFeedbackType',
- null,
- get_lang('ExerciseAtTheEndOfTheTest'),
- '0',
- ['id' => 'exerciseType_0', 'onclick' => 'check_feedback()']
- );
-
- if (api_get_setting('enable_quiz_scenario') == 'true') {
- $radios_feedback[] = $form->createElement(
- 'radio',
- 'exerciseFeedbackType',
- null,
- get_lang('DirectFeedback'),
- '1',
- ['id' => 'exerciseType_1', 'onclick' => 'check_direct_feedback()']
- );
- }
- $radios_feedback[] = $form->createElement(
- 'radio',
- 'exerciseFeedbackType',
- null,
- get_lang('NoFeedback'),
- '2',
- ['id' => 'exerciseType_2']
- );
- $form->addGroup(
- $radios_feedback,
- null,
- [get_lang('FeedbackType'), get_lang('FeedbackDisplayOptions')]
- );
-
+ $this->setResultFeedbackGroup($form);
$this->setResultDisabledGroup($form);
// Type of questions disposition on page
@@ -2079,7 +2014,7 @@ class Exercise
$group->freeze();
// we force the options to the DirectFeedback exercisetype
- $form->addElement('hidden', 'exerciseFeedbackType', EXERCISE_FEEDBACK_TYPE_DIRECT);
+ $form->addElement('hidden', 'exerciseFeedbackType', $this->getFeedbackType());
$form->addElement('hidden', 'exerciseType', ONE_PER_PAGE);
// Type of questions disposition on page
@@ -2154,6 +2089,30 @@ class Exercise
]
);
+
+ $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();
@@ -2201,13 +2160,6 @@ class Exercise
$form->addElement('label', null, $cat_form);
$form->addElement('html', '');
- // 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'),
@@ -2215,6 +2167,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'),
@@ -2298,11 +2257,19 @@ class Exercise
null,
get_lang('PropagateNegativeResults')
);
- $form->addCheckBox(
+
+
+ $options = [
+ '' => get_lang('SelectAnOption'),
+ 1 => get_lang('SaveTheCorrectAnswersForTheNextAttempt'),
+ 2 => get_lang('SaveAllAnswers'),
+ ];
+ $form->addSelect(
'save_correct_answers',
- null,
- get_lang('SaveTheCorrectAnswersForTheNextAttempt')
- );
+ get_lang('SaveAnswers'),
+ $options
+ );
+
$form->addElement('html', '
';
Session::write('hot_spot_result', $message);
- $_SESSION['hotspot_delineation_result'][$exerciseId][$questionid] = [$message, $exerciseResult[$questionid]];
- //reseting the exerciseResult variable
+ $_SESSION['hotspot_delineation_result'][$exerciseId][$questionId] = [$message, $exerciseResult[$questionId]];
+ // Resetting the exerciseResult variable
Session::write('exerciseResult', $exerciseResult);
//save this variables just in case the exercise loads an LP with other exercise
@@ -615,10 +597,7 @@ if ($links != '') {
$questionNum++;
echo '';
}
echo '
';
// show column comment when feedback is enable
- if ($obj_ex->selectFeedbackType() != EXERCISE_FEEDBACK_TYPE_EXAM) {
+ if ($obj_ex->getFeedbackType() != EXERCISE_FEEDBACK_TYPE_EXAM) {
$html .= '
'.get_lang('Comment').'
';
}
@@ -146,7 +146,7 @@ class MultipleAnswerTrueFalse extends Question
);
// show comment when feedback is enable
- if ($obj_ex->selectFeedbackType() != EXERCISE_FEEDBACK_TYPE_EXAM) {
+ if ($obj_ex->getFeedbackType() != EXERCISE_FEEDBACK_TYPE_EXAM) {
$form->addElement(
'html_editor',
'comment['.$i.']',
@@ -314,12 +314,13 @@ class MultipleAnswerTrueFalse extends Question
$header .= '