diff --git a/public/main/exercise/TestCategory.php b/public/main/exercise/TestCategory.php index 1ce554d229..56eb3d454b 100644 --- a/public/main/exercise/TestCategory.php +++ b/public/main/exercise/TestCategory.php @@ -205,13 +205,13 @@ class TestCategory $table = Database::get_course_table(TABLE_QUIZ_QUESTION_CATEGORY); $categories = []; if (empty($field)) { - $sql = "SELECT id FROM $table + $sql = "SELECT iid FROM $table WHERE c_id = $courseId ORDER BY title ASC"; $res = Database::query($sql); while ($row = Database::fetch_array($res)) { $category = new TestCategory(); - $categories[] = $category->getCategory($row['id'], $courseId); + $categories[] = $category->getCategory($row['iid'], $courseId); } } else { $field = Database::escape_string($field); @@ -265,7 +265,7 @@ class TestCategory $table = Database::get_course_table(TABLE_QUIZ_QUESTION_REL_CATEGORY); $sql = "SELECT * FROM $table - WHERE question_id = $questionId AND c_id = $courseId"; + WHERE question_id = $questionId"; $res = Database::query($sql); if (Database::num_rows($res) > 0) { return Database::fetch_array($res, 'ASSOC'); @@ -294,7 +294,7 @@ class TestCategory $table = Database::get_course_table(TABLE_QUIZ_QUESTION_CATEGORY); $sql = "SELECT title FROM $table - WHERE id = $categoryId AND c_id = $courseId"; + WHERE iid = $categoryId AND c_id = $courseId"; $res = Database::query($sql); $data = Database::fetch_array($res); $result = ''; diff --git a/public/main/exercise/admin.php b/public/main/exercise/admin.php index 668fa92c5e..3f6860934b 100644 --- a/public/main/exercise/admin.php +++ b/public/main/exercise/admin.php @@ -147,7 +147,7 @@ if ($objExercise->sessionId != $sessionId) { // doesn't select the exercise ID if we come from the question pool if (!$fromExercise) { // gets the right exercise ID, and if 0 creates a new exercise - if (!$exerciseId = $objExercise->selectId()) { + if (!$exerciseId = $objExercise->getId()) { $modifyExercise = 'yes'; } } @@ -171,7 +171,7 @@ if ($editQuestion || $newQuestion || $modifyQuestion || $modifyAnswers) { // checks if the object exists if (is_object($objQuestion)) { // gets the question ID - $questionId = $objQuestion->selectId(); + $questionId = $objQuestion->getId(); } } @@ -436,7 +436,7 @@ if ($newQuestion || $editQuestion) { echo ''; } else { require 'question_admin.inc.php'; - ExerciseLib::showTestsWhereQuestionIsUsed($objQuestion->iid, $objExercise->selectId()); + ExerciseLib::showTestsWhereQuestionIsUsed($objQuestion->iid, $objExercise->getId()); } } } diff --git a/public/main/exercise/exercise.class.php b/public/main/exercise/exercise.class.php index 947be43d16..ab04f5543f 100644 --- a/public/main/exercise/exercise.class.php +++ b/public/main/exercise/exercise.class.php @@ -1227,10 +1227,10 @@ class Exercise $table = Database::get_course_table(TABLE_QUIZ_TEST_QUESTION); $tableQuestion = Database::get_course_table(TABLE_QUIZ_QUESTION); - $sql = "SELECT q.id + $sql = "SELECT q.iid FROM $table e INNER JOIN $tableQuestion q - ON (e.question_id = q.id AND e.c_id = q.c_id) + ON (e.question_id = q.iid AND e.c_id = q.c_id) WHERE q.type = $type AND e.c_id = {$this->course_id} AND @@ -2084,7 +2084,7 @@ class Exercise 'hide_question_score', null, get_lang('Hide question score') - ), + ), $form->createElement( 'checkbox', 'hide_category_table', @@ -3541,7 +3541,7 @@ class Exercise $questionName = $objQuestionTmp->selectTitle(); $questionWeighting = $objQuestionTmp->selectWeighting(); $answerType = $objQuestionTmp->selectType(); - $quesId = $objQuestionTmp->selectId(); + $quesId = $objQuestionTmp->getId(); $extra = $objQuestionTmp->extra; $next = 1; //not for now $totalWeighting = 0; @@ -5682,8 +5682,8 @@ class Exercise $message .= '

'.$comment.'

'; echo $message; - $_SESSION['hotspot_delineation_result'][$this->selectId()][$questionId][0] = $message; - $_SESSION['hotspot_delineation_result'][$this->selectId()][$questionId][1] = $_SESSION['exerciseResultCoordinates'][$questionId]; + $_SESSION['hotspot_delineation_result'][$this->getId()][$questionId][0] = $message; + $_SESSION['hotspot_delineation_result'][$this->selgetIdectId()][$questionId][1] = $_SESSION['exerciseResultCoordinates'][$questionId]; } else { echo $hotspot_delineation_result[0]; } diff --git a/public/main/exercise/exercise_admin.php b/public/main/exercise/exercise_admin.php index 80544e4f75..8b9d77e2ca 100644 --- a/public/main/exercise/exercise_admin.php +++ b/public/main/exercise/exercise_admin.php @@ -131,7 +131,7 @@ if (!empty($exerciseId)) { $form = new FormValidator( 'exercise_admin', 'post', - api_get_self().'?'.api_get_cidreq().'&id='.$exerciseId + api_get_self().'?'.api_get_cidreq().'&exerciseId='.$exerciseId ); $objExercise->read($exerciseId, false); $form->addElement('hidden', 'edit', 'true'); @@ -160,7 +160,7 @@ if ($form->validate()) { } $exercise_id = $objExercise->getId(); Session::erase('objExercise'); - header('Location:admin.php?id='.$exercise_id.'&'.api_get_cidreq()); + header('Location:admin.php?exerciseId='.$exercise_id.'&'.api_get_cidreq()); exit; } else { if (api_is_in_gradebook()) { @@ -175,7 +175,7 @@ if ($form->validate()) { 'name' => get_lang('Tests'), ]; $interbreadcrumb[] = [ - 'url' => 'admin.php?id='.$objExercise->getId().'&'.api_get_cidreq(), + 'url' => 'admin.php?exerciseId='.$objExercise->getId().'&'.api_get_cidreq(), 'name' => $objExercise->selectTitle(true), ]; diff --git a/public/main/exercise/exercise_report.php b/public/main/exercise/exercise_report.php index 9f5b1a57be..4d6c42937c 100644 --- a/public/main/exercise/exercise_report.php +++ b/public/main/exercise/exercise_report.php @@ -2,7 +2,6 @@ /* For licensing terms, see /license.txt */ - use Chamilo\CoreBundle\Entity\TrackEAttemptRecording; /** diff --git a/public/main/exercise/exercise_result.php b/public/main/exercise/exercise_result.php index f7a204ac4a..6b8ee93ec6 100644 --- a/public/main/exercise/exercise_result.php +++ b/public/main/exercise/exercise_result.php @@ -110,7 +110,7 @@ if (api_is_course_admin() && !in_array($origin, ['learnpath', 'embeddable'])) { ] ); } -$exercise_stat_info = $objExercise->get_stat_track_exercise_info_by_exe_id($exe_id); +$exercise_stat_info = $objExercise->get_stat_track_exercise_info_by_exe_id($exeId); $learnpath_id = isset($exercise_stat_info['orig_lp_id']) ? $exercise_stat_info['orig_lp_id'] : 0; $learnpath_item_id = isset($exercise_stat_info['orig_lp_item_id']) ? $exercise_stat_info['orig_lp_item_id'] : 0; $learnpath_item_view_id = isset($exercise_stat_info['orig_lp_item_view_id']) @@ -165,7 +165,7 @@ $attempt_count = Event::get_attempt_count( $learnpath_item_id, $learnpath_item_view_id ); - + if ($objExercise->selectAttempts() > 0) { if ($attempt_count >= $objExercise->selectAttempts()) { Display::addFlash( diff --git a/public/main/exercise/exercise_show.php b/public/main/exercise/exercise_show.php index 75f3d4621c..290564c4de 100644 --- a/public/main/exercise/exercise_show.php +++ b/public/main/exercise/exercise_show.php @@ -881,7 +881,7 @@ if (MULTIPLE_ANSWER_TRUE_FALSE_DEGREE_CERTAINTY != $answerType) { $pluginEvaluation = QuestionOptionsEvaluationPlugin::create(); if ('true' === $pluginEvaluation->get(QuestionOptionsEvaluationPlugin::SETTING_ENABLE)) { - $formula = $pluginEvaluation->getFormulaForExercise($objExercise->selectId()); + $formula = $pluginEvaluation->getFormulaForExercise($objExercise->getId()); if (!empty($formula)) { $totalScore = $pluginEvaluation->getResultWithFormula($id, $formula); diff --git a/public/main/exercise/exercise_submit_modal.php b/public/main/exercise/exercise_submit_modal.php index 9a530d38f6..af3473bb6d 100644 --- a/public/main/exercise/exercise_submit_modal.php +++ b/public/main/exercise/exercise_submit_modal.php @@ -8,6 +8,7 @@ use ChamiloSession as Session; * @author Julio Montoya */ require_once __DIR__.'/../inc/global.inc.php'; +$current_course_tool = TOOL_QUIZ; api_protect_course_script(); @@ -36,7 +37,32 @@ $questionNum = (int) $_GET['num']; $questionId = $questionList[$questionNum]; $choiceValue = isset($_GET['choice']) ? $_GET['choice'] : ''; $hotSpot = isset($_GET['hotspot']) ? $_GET['hotspot'] : ''; +$tryAgain = isset($_GET['tryagain']) && 1 === (int) $_GET['tryagain']; + +$allowTryAgain = false; +if ($tryAgain) { + // Check if try again exists in this question, otherwise only allow one attempt BT#15827. + $objQuestionTmp = Question::read($questionId); + $answerType = $objQuestionTmp->selectType(); + $showResult = false; + $objAnswerTmp = new Answer($questionId, api_get_course_int_id()); + $answers = $objAnswerTmp->getAnswers(); + if (!empty($answers)) { + foreach ($answers as $answerData) { + if (isset($answerData['destination'])) { + $itemList = explode('@@', $answerData['destination']); + if (isset($itemList[0]) && !empty($itemList[0])) { + $allowTryAgain = true; + break; + } + } + } + } +} $loaded = isset($_GET['loaded']); +if ($allowTryAgain) { + unset($exerciseResult[$questionId]); +} if (empty($choiceValue) && isset($exerciseResult[$questionId])) { $choiceValue = $exerciseResult[$questionId]; @@ -54,6 +80,15 @@ if (!empty($choiceValue)) { } } +$header = ''; +$exeId = 0; +if ($objExercise->getFeedbackType() === EXERCISE_FEEDBACK_TYPE_POPUP) { + $exeId = Session::read('exe_id'); + $header = ' + '; +} echo ''; -$header = ''; -if (EXERCISE_FEEDBACK_TYPE_POPUP === $objExercise->getFeedbackType()) { - $header = ' - '; -} echo '
'; // Getting the options by js @@ -169,6 +197,7 @@ $choice[$questionId] = isset($choiceValue) ? $choiceValue : null; if (!is_array($exerciseResult)) { $exerciseResult = []; } +$saveResults = (int) $objExercise->getFeedbackType() == EXERCISE_FEEDBACK_TYPE_POPUP; // if the user has answered at least one question if (is_array($choice)) { @@ -232,12 +261,12 @@ switch ($answerType) { ob_start(); $result = $objExercise->manage_answer( - 0, + $exeId, $questionId, $choiceValue, 'exercise_result', - null, - false, + [], + $saveResults, false, $showResult, null, diff --git a/public/main/exercise/export/aiken/aiken_import.inc.php b/public/main/exercise/export/aiken/aiken_import.inc.php index 9ae39393ae..b5943d645b 100644 --- a/public/main/exercise/export/aiken/aiken_import.inc.php +++ b/public/main/exercise/export/aiken/aiken_import.inc.php @@ -177,7 +177,7 @@ function aiken_import_exercise($file) $exercise = new Exercise(); $exercise->exercise = $exercise_info['name']; $exercise->save(); - $last_exercise_id = $exercise->selectId(); + $last_exercise_id = $exercise->getId(); $tableQuestion = Database::get_course_table(TABLE_QUIZ_QUESTION); $tableAnswer = Database::get_course_table(TABLE_QUIZ_ANSWER); if (!empty($last_exercise_id)) { @@ -196,7 +196,7 @@ function aiken_import_exercise($file) $type = $question->selectType(); $question->type = constant($type); $question->save($exercise); - $last_question_id = $question->selectId(); + $last_question_id = $question->getId(); // 3. Create answer $answer = new Answer($last_question_id, $courseId, $exercise, false); diff --git a/public/main/exercise/export/exercise_import.inc.php b/public/main/exercise/export/exercise_import.inc.php index 40e391961e..1f43e2f1ff 100644 --- a/public/main/exercise/export/exercise_import.inc.php +++ b/public/main/exercise/export/exercise_import.inc.php @@ -162,7 +162,7 @@ function import_exercise($file) } $exercise->save(); - $last_exercise_id = $exercise->selectId(); + $last_exercise_id = $exercise->getId(); $courseId = api_get_course_int_id(); if (!empty($last_exercise_id)) { // For each question found... @@ -210,7 +210,7 @@ function import_exercise($file) $question->updateDescription($description); $question->save($exercise); - $last_question_id = $question->selectId(); + $last_question_id = $question->getId(); //3. Create answer $answer = new Answer($last_question_id); $answerList = $question_array['answer']; @@ -733,10 +733,10 @@ function qtiProcessManifest($filePath) $specialHref = Database::escape_string(preg_replace('/_/', '-', strtolower($href))); $specialHref = preg_replace('/(-){2,8}/', '-', $specialHref); - $sql = "SELECT iid FROM $tableDocuments + $sql = "SELECT iid FROM $tableDocuments WHERE - c_id = ".$course['real_id']." AND - session_id = $sessionId AND + c_id = ".$course['real_id']." AND + session_id = $sessionId AND path = '/".$specialHref."'"; $result = Database::query($sql); $documentId = 0; diff --git a/public/main/exercise/export/qti2/qti2_export.php b/public/main/exercise/export/qti2/qti2_export.php index 404c7ad1c1..bdc1c3a556 100644 --- a/public/main/exercise/export/qti2/qti2_export.php +++ b/public/main/exercise/export/qti2/qti2_export.php @@ -168,9 +168,9 @@ class ImsSection public function start_section() { - return '
'."\n"; } @@ -317,7 +317,7 @@ class ImsItem { $this->question = $question; $this->answer = $question->answer; - $this->questionIdent = 'QST_'.$question->selectId(); + $this->questionIdent = 'QST_'.$question->getId(); } /** diff --git a/public/main/exercise/fill_blanks.class.php b/public/main/exercise/fill_blanks.class.php index 08308708d6..44c6e8d05e 100644 --- a/public/main/exercise/fill_blanks.class.php +++ b/public/main/exercise/fill_blanks.class.php @@ -250,6 +250,10 @@ class FillBlanks extends Question function changeBlankSeparator() { + var definedSeparator = $("[name=select_separator] option:selected").text(); + $("[name=select_separator] option").each(function (index, value) { + $("#defineoneblank").html($("#defineoneblank").html().replace($(value).html(), definedSeparator)) + }); var separatorNumber = $("#select_separator").val(); var tabSeparator = getSeparatorFromNumber(separatorNumber); blankSeparatorStart = tabSeparator[0]; @@ -1127,18 +1131,6 @@ class FillBlanks extends Question $result = ''; $listStudentAnswerInfo = self::getAnswerInfo($answer, true); - /*if (in_array($resultsDisabled, [ - RESULT_DISABLE_SHOW_SCORE_ATTEMPT_SHOW_ANSWERS_LAST_ATTEMPT, - RESULT_DISABLE_DONT_SHOW_SCORE_ONLY_IF_USER_FINISHES_ATTEMPTS_SHOW_ALWAYS_FEEDBACK, - ] - ) - ) { - $resultsDisabled = true; - if ($showTotalScoreAndUserChoices) { - $resultsDisabled = false; - } - }*/ - // rebuild the answer with good HTML style // this is the student answer, right or wrong for ($i = 0; $i < count($listStudentAnswerInfo['student_answer']); $i++) { @@ -1163,6 +1155,11 @@ class FillBlanks extends Question // rebuild the sentence with student answer inserted for ($i = 0; $i < count($listStudentAnswerInfo['common_words']); $i++) { + if ($resultsDisabled == RESULT_DISABLE_SHOW_SCORE_ATTEMPT_SHOW_ANSWERS_LAST_ATTEMPT_NO_FEEDBACK) { + if (empty($listStudentAnswerInfo['student_answer'][$i])) { + continue; + } + } $result .= isset($listStudentAnswerInfo['common_words'][$i]) ? $listStudentAnswerInfo['common_words'][$i] : ''; $studentLabel = isset($listStudentAnswerInfo['student_answer'][$i]) ? $listStudentAnswerInfo['student_answer'][$i] : ''; $result .= $studentLabel; @@ -1209,6 +1206,7 @@ class FillBlanks extends Question break; case RESULT_DISABLE_DONT_SHOW_SCORE_ONLY_IF_USER_FINISHES_ATTEMPTS_SHOW_ALWAYS_FEEDBACK: + case RESULT_DISABLE_SHOW_SCORE_ATTEMPT_SHOW_ANSWERS_LAST_ATTEMPT_NO_FEEDBACK: case RESULT_DISABLE_SHOW_SCORE_ATTEMPT_SHOW_ANSWERS_LAST_ATTEMPT: $hideExpectedAnswer = true; if ($showTotalScoreAndUserChoices) { @@ -1318,6 +1316,9 @@ class FillBlanks extends Question $resultsDisabled = false, $showTotalScoreAndUserChoices = false ) { + if ($resultsDisabled == RESULT_DISABLE_SHOW_SCORE_ATTEMPT_SHOW_ANSWERS_LAST_ATTEMPT_NO_FEEDBACK) { + return ''; + } return self::getHtmlAnswer( $answer, $correct, diff --git a/public/main/exercise/hotspot_answers.as.php b/public/main/exercise/hotspot_answers.as.php index c1d23a1bab..80a0258805 100644 --- a/public/main/exercise/hotspot_answers.as.php +++ b/public/main/exercise/hotspot_answers.as.php @@ -24,6 +24,9 @@ $userId = api_get_user_id(); $courseId = api_get_course_int_id(); $objExercise = new Exercise($courseId); $debug = false; +if ($debug) { + error_log("Call to hotspot_answers.as.php"); +} $trackExerciseInfo = $objExercise->get_stat_track_exercise_info_by_exe_id($exeId); // Check if student has access to the hotspot answers @@ -94,10 +97,12 @@ $data['image_height'] = $pictureHeight; $data['courseCode'] = $_course['path']; $data['hotspots'] = []; +$resultDisable = $objExercise->selectResultsDisabled(); $showTotalScoreAndUserChoicesInLastAttempt = true; if (in_array( - $objExercise->selectResultsDisabled(), [ + $resultDisable, [ RESULT_DISABLE_SHOW_SCORE_ATTEMPT_SHOW_ANSWERS_LAST_ATTEMPT, + RESULT_DISABLE_SHOW_SCORE_ATTEMPT_SHOW_ANSWERS_LAST_ATTEMPT_NO_FEEDBACK, RESULT_DISABLE_DONT_SHOW_SCORE_ONLY_IF_USER_FINISHES_ATTEMPTS_SHOW_ALWAYS_FEEDBACK, ] ) @@ -128,14 +133,14 @@ if (in_array( } $hideExpectedAnswer = false; -if (0 == $objExercise->getFeedbackType() && - RESULT_DISABLE_SHOW_SCORE_ONLY == $objExercise->selectResultsDisabled() +if ($objExercise->getFeedbackType() == 0 && + $resultDisable == RESULT_DISABLE_SHOW_SCORE_ONLY ) { $hideExpectedAnswer = true; } if (in_array( - $objExercise->selectResultsDisabled(), [ + $resultDisable, [ RESULT_DISABLE_SHOW_SCORE_ATTEMPT_SHOW_ANSWERS_LAST_ATTEMPT, RESULT_DISABLE_DONT_SHOW_SCORE_ONLY_IF_USER_FINISHES_ATTEMPTS_SHOW_ALWAYS_FEEDBACK, ] @@ -144,6 +149,36 @@ if (in_array( $hideExpectedAnswer = $showTotalScoreAndUserChoicesInLastAttempt ? false : true; } +if (in_array( + $resultDisable, [ + RESULT_DISABLE_SHOW_SCORE_ATTEMPT_SHOW_ANSWERS_LAST_ATTEMPT_NO_FEEDBACK, + ] +) +) { + $hideExpectedAnswer = false; +} + +$hotSpotWithAnswer = []; +$data['answers'] = []; +$rs = $em + ->getRepository('ChamiloCoreBundle:TrackEHotspot') + ->findBy( + [ + 'hotspotQuestionId' => $questionId, + 'cId' => $courseId, + 'hotspotExeId' => $exeId, + ], + ['hotspotAnswerId' => 'ASC'] + ); + +/** @var TrackEHotspot $row */ +foreach ($rs as $row) { + $data['answers'][] = $row->getHotspotCoordinate(); + + if ($row->getHotspotCorrect()) { + $hotSpotWithAnswer[] = $row->getHotspotAnswerId(); + } +} if (!$hideExpectedAnswer) { $qb = $em->createQueryBuilder(); $qb @@ -165,8 +200,15 @@ if (!$hideExpectedAnswer) { $result = $qb->getQuery()->getResult(); - /** @var CQuizAnswer $hotSpotAnswer */ foreach ($result as $hotSpotAnswer) { + if (RESULT_DISABLE_SHOW_SCORE_ATTEMPT_SHOW_ANSWERS_LAST_ATTEMPT_NO_FEEDBACK == $resultDisable) { + if (false === $showTotalScoreAndUserChoicesInLastAttempt) { + if (!in_array($hotSpotAnswer->getIid(), $hotSpotWithAnswer)) { + continue; + } + } + } + /** @var CQuizAnswer $hotSpotAnswer */ $hotSpot = []; $hotSpot['id'] = $hotSpotAnswer->getIid(); $hotSpot['answer'] = $hotSpotAnswer->getAnswer(); diff --git a/public/main/exercise/hotspot_savescore.inc.php b/public/main/exercise/hotspot_savescore.inc.php index 60939b774c..9bc45835ef 100644 --- a/public/main/exercise/hotspot_savescore.inc.php +++ b/public/main/exercise/hotspot_savescore.inc.php @@ -19,7 +19,7 @@ $courseCode = $_GET['coursecode']; $questionId = $_GET['questionId']; $coordinates = $_GET['coord']; $objExercise = Session::read('objExercise'); -$exerciseId = $objExercise->selectId(); +$exerciseId = $objExercise->getId(); // Save clicking order $answerOrderId = count($_SESSION['exerciseResult'][$questionId]['ids']) + 1; if ('0' == $_GET['answerId']) { diff --git a/public/main/exercise/hotspot_updatescore.inc.php b/public/main/exercise/hotspot_updatescore.inc.php index 7b139a2d7b..bead319600 100644 --- a/public/main/exercise/hotspot_updatescore.inc.php +++ b/public/main/exercise/hotspot_updatescore.inc.php @@ -20,7 +20,7 @@ $questionId = $_GET['questionId']; $coordinates = $_GET['coord']; $objExercise = Session::read('objExercise'); $hotspotId = $_GET['hotspotId']; -$exerciseId = $objExercise->selectId(); +$exerciseId = $objExercise->getId(); if ('0' == $_GET['answerId']) { // click is NOT on a hotspot $hit = 0; $answerId = $hotspotId; @@ -48,8 +48,8 @@ $TBL_TRACK_E_HOTSPOT = Database::get_main_table(TABLE_STATISTIC_TRACK_E_HOTSPOT) // update db $update_id = $_SESSION['exerciseResult'][$questionId]['ids'][$answerId]; -$sql = "UPDATE $TBL_TRACK_E_HOTSPOT +$sql = "UPDATE $TBL_TRACK_E_HOTSPOT SET coordinate = '".Database::escape_string($coordinates)."' - WHERE id = ".(int) $update_id.' + WHERE id = ".(int) $update_id.' LIMIT 1'; $result = Database::query($sql); diff --git a/public/main/exercise/live_stats.php b/public/main/exercise/live_stats.php index f73561220d..dd4f6625c4 100644 --- a/public/main/exercise/live_stats.php +++ b/public/main/exercise/live_stats.php @@ -24,7 +24,7 @@ $interbreadcrumb[] = [ 'name' => get_lang('Tests'), ]; $interbreadcrumb[] = [ - 'url' => "admin.php?id=$exercise_id&".api_get_cidreq(), + 'url' => "admin.php?exerciseId=$exercise_id&".api_get_cidreq(), 'name' => $objExercise->selectTitle(true), ]; @@ -108,7 +108,7 @@ $(function() { '. +$actions = ''. Display::return_icon('back.png', get_lang('Go back to the questions list'), '', ICON_SIZE_MEDIUM).''; echo $actions = Display::div($actions, ['class' => 'actions']); diff --git a/public/main/exercise/multiple_answer.class.php b/public/main/exercise/multiple_answer.class.php index 2168db63c1..e3d7782e24 100644 --- a/public/main/exercise/multiple_answer.class.php +++ b/public/main/exercise/multiple_answer.class.php @@ -235,7 +235,9 @@ class MultipleAnswer extends Question $header .= ''.get_lang('Status').''; } - $header .= ''.get_lang('Comment').''; + if (false === $exercise->hideComment) { + $header .= ''.get_lang('Comment').''; + } $header .= ''; return $header; diff --git a/public/main/exercise/multiple_answer_combination.class.php b/public/main/exercise/multiple_answer_combination.class.php index e342802767..ddc72f7f7b 100644 --- a/public/main/exercise/multiple_answer_combination.class.php +++ b/public/main/exercise/multiple_answer_combination.class.php @@ -236,7 +236,9 @@ class MultipleAnswerCombination extends Question if ($exercise->showExpectedChoice()) { $header .= ''.get_lang('Status').''; } - $header .= ''.get_lang('Comment').''; + if (false === $exercise->hideComment) { + $header .= ''.get_lang('Comment').''; + } $header .= ''; return $header; diff --git a/public/main/exercise/multiple_answer_true_false.class.php b/public/main/exercise/multiple_answer_true_false.class.php index 4003fe004b..b5c2220312 100644 --- a/public/main/exercise/multiple_answer_true_false.class.php +++ b/public/main/exercise/multiple_answer_true_false.class.php @@ -117,7 +117,11 @@ class MultipleAnswerTrueFalse extends Question $j = 1; if (!empty($optionData)) { foreach ($optionData as $id => $data) { - $form->addElement('radio', 'correct['.$i.']', null, null, $id); + $rdoCorrect = $form->addElement('radio', 'correct['.$i.']', null, null, $id); + + if (isset($_POST['correct']) && isset($_POST['correct'][$i]) && $id == $_POST['correct'][$i]) { + $rdoCorrect->setValue(Security::remove_XSS($_POST['correct'][$i])); + } $j++; if (3 == $j) { break; @@ -141,6 +145,9 @@ class MultipleAnswerTrueFalse extends Question ['ToolbarSet' => 'TestProposedAnswer', 'Width' => '100%', 'Height' => '100'] ); + if (isset($_POST['answer']) && isset($_POST['answer'][$i])) { + $form->getElement("answer[$i]")->setValue(Security::remove_XSS($_POST['answer'][$i])); + } // show comment when feedback is enable if (EXERCISE_FEEDBACK_TYPE_EXAM != $obj_ex->getFeedbackType()) { $form->addElement( @@ -154,6 +161,9 @@ class MultipleAnswerTrueFalse extends Question 'Height' => '100', ] ); + if (isset($_POST['comment']) && isset($_POST['comment'][$i])) { + $txtComment->setValue(Security::remove_XSS($_POST['comment'][$i])); + } } $form->addHtml(''); @@ -206,9 +216,9 @@ class MultipleAnswerTrueFalse extends Question $scores = explode(':', $this->extra); if (!empty($scores)) { - for ($i = 1; $i <= 3; $i++) { - $defaults['option['.$i.']'] = $scores[$i - 1]; - } + $txtOption1->setValue($scores[0]); + $txtOption2->setValue($scores[1]); + $txtOption3->setValue($scores[2]); } } @@ -224,9 +234,7 @@ class MultipleAnswerTrueFalse extends Question $form->addGroup($buttonGroup); } - if (!empty($this->id)) { - $form->setDefaults($defaults); - } else { + if (!empty($this->id) && !$form->isSubmitted()) { $form->setDefaults($defaults); } $form->setConstants(['nb_answers' => $nb_answers]); @@ -327,7 +335,9 @@ class MultipleAnswerTrueFalse extends Question ] ) ) { - $header .= ''.get_lang('Comment').''; + if (false === $exercise->hideComment) { + $header .= ''.get_lang('Comment').''; + } } $header .= ''; diff --git a/public/main/exercise/overview.php b/public/main/exercise/overview.php index 690a1207f2..3240d5e95f 100644 --- a/public/main/exercise/overview.php +++ b/public/main/exercise/overview.php @@ -10,7 +10,9 @@ require_once __DIR__.'/../inc/global.inc.php'; // Clear the exercise session just in case +$current_course_tool = TOOL_QUIZ; Exercise::cleanSessionVariables(); +$this_section = SECTION_COURSES; $js = ''; $htmlHeadXtra[] = $js; @@ -19,7 +21,7 @@ $htmlHeadXtra[] = $js; api_protect_course_script(true); $sessionId = api_get_session_id(); $courseCode = api_get_course_id(); -$exercise_id = isset($_REQUEST['id']) ? (int) $_REQUEST['id'] : 0; +$exercise_id = isset($_REQUEST['exerciseId']) ? (int) $_REQUEST['exerciseId'] : 0; $objExercise = new Exercise(); $result = $objExercise->read($exercise_id, true); @@ -28,15 +30,21 @@ if (!$result) { api_not_allowed(true); } -$learnpath_id = isset($_REQUEST['learnpath_id']) ? (int) ($_REQUEST['learnpath_id']) : null; -$learnpath_item_id = isset($_REQUEST['learnpath_item_id']) ? (int) ($_REQUEST['learnpath_item_id']) : null; -$learnpathItemViewId = isset($_REQUEST['learnpath_item_view_id']) ? (int) ($_REQUEST['learnpath_item_view_id']) : null; +if ('true' === api_get_plugin_setting('positioning', 'tool_enable')) { + $plugin = Positioning::create(); + if ($plugin->blockFinalExercise(api_get_user_id(), $exercise_id, api_get_course_int_id(), $sessionId)) { + api_not_allowed(true); + } +} + +$learnpath_id = isset($_REQUEST['learnpath_id']) ? (int) $_REQUEST['learnpath_id'] : null; +$learnpath_item_id = isset($_REQUEST['learnpath_item_id']) ? (int) $_REQUEST['learnpath_item_id'] : null; +$learnpathItemViewId = isset($_REQUEST['learnpath_item_view_id']) ? (int) $_REQUEST['learnpath_item_view_id'] : null; $origin = api_get_origin(); $logInfo = [ 'tool' => TOOL_QUIZ, 'tool_id' => $exercise_id, - 'tool_id_detail' => 0, 'action' => isset($_REQUEST['learnpath_id']) ? 'learnpath_id' : '', 'action_details' => isset($_REQUEST['learnpath_id']) ? (int) $_REQUEST['learnpath_id'] : '', ]; @@ -96,12 +104,12 @@ if ($is_allowed_to_edit) { if ($objExercise->sessionId == $sessionId) { $editLink = Display::url( Display::return_icon('edit.png', get_lang('Edit'), [], ICON_SIZE_SMALL), - api_get_path(WEB_CODE_PATH).'exercise/admin.php?'.api_get_cidreq().'&id='.$objExercise->id + api_get_path(WEB_CODE_PATH).'exercise/admin.php?'.api_get_cidreq().'&exerciseId='.$objExercise->id ); } $editLink .= Display::url( Display::return_icon('test_results.png', get_lang('Results and feedback and feedback'), [], ICON_SIZE_SMALL), - api_get_path(WEB_CODE_PATH).'exercise/exercise_report.php?'.api_get_cidreq().'&id='.$objExercise->id, + api_get_path(WEB_CODE_PATH).'exercise/exercise_report.php?'.api_get_cidreq().'&exerciseId='.$objExercise->id, ['title' => get_lang('Results and feedback and feedback')] ); } @@ -218,6 +226,7 @@ if (in_array( $objExercise->results_disabled, [ RESULT_DISABLE_SHOW_SCORE_ATTEMPT_SHOW_ANSWERS_LAST_ATTEMPT, + RESULT_DISABLE_SHOW_SCORE_ATTEMPT_SHOW_ANSWERS_LAST_ATTEMPT_NO_FEEDBACK, RESULT_DISABLE_DONT_SHOW_SCORE_ONLY_IF_USER_FINISHES_ATTEMPTS_SHOW_ALWAYS_FEEDBACK, ]) ) { @@ -280,6 +289,7 @@ if (!empty($attempts)) { RESULT_DISABLE_SHOW_SCORE_ONLY, RESULT_DISABLE_SHOW_FINAL_SCORE_ONLY_WITH_CATEGORIES, RESULT_DISABLE_SHOW_SCORE_ATTEMPT_SHOW_ANSWERS_LAST_ATTEMPT, + RESULT_DISABLE_SHOW_SCORE_ATTEMPT_SHOW_ANSWERS_LAST_ATTEMPT_NO_FEEDBACK, RESULT_DISABLE_DONT_SHOW_SCORE_ONLY_IF_USER_FINISHES_ATTEMPTS_SHOW_ALWAYS_FEEDBACK, RESULT_DISABLE_RANKING, RESULT_DISABLE_SHOW_ONLY_IN_CORRECT_ANSWER, @@ -295,6 +305,7 @@ if (!empty($attempts)) { RESULT_DISABLE_SHOW_SCORE_AND_EXPECTED_ANSWERS_AND_RANKING, RESULT_DISABLE_SHOW_FINAL_SCORE_ONLY_WITH_CATEGORIES, RESULT_DISABLE_SHOW_SCORE_ATTEMPT_SHOW_ANSWERS_LAST_ATTEMPT, + RESULT_DISABLE_SHOW_SCORE_ATTEMPT_SHOW_ANSWERS_LAST_ATTEMPT_NO_FEEDBACK, RESULT_DISABLE_DONT_SHOW_SCORE_ONLY_IF_USER_FINISHES_ATTEMPTS_SHOW_ALWAYS_FEEDBACK, RESULT_DISABLE_RANKING, RESULT_DISABLE_SHOW_ONLY_IN_CORRECT_ANSWER, @@ -347,6 +358,7 @@ if (!empty($attempts)) { } break; + case RESULT_DISABLE_SHOW_SCORE_ATTEMPT_SHOW_ANSWERS_LAST_ATTEMPT_NO_FEEDBACK: case RESULT_DISABLE_SHOW_SCORE_ATTEMPT_SHOW_ANSWERS_LAST_ATTEMPT: if ($blockShowAnswers) { $header_names = [get_lang('Attempt'), get_lang('Start Date'), get_lang('IP'), get_lang('Score')]; diff --git a/public/main/exercise/question.class.php b/public/main/exercise/question.class.php index 032609a010..9cf97ba32d 100644 --- a/public/main/exercise/question.class.php +++ b/public/main/exercise/question.class.php @@ -109,6 +109,11 @@ abstract class Question ]; } + public function getId() + { + return $this->iid; + } + /** * @return int|null */ @@ -214,18 +219,6 @@ abstract class Question return false; } - /** - * returns the question ID. - * - * @author Olivier Brouckaert - * - * @return int - question ID - */ - public function selectId() - { - return $this->id; - } - /** * returns the question title. * @@ -395,9 +388,15 @@ abstract class Question c_id = ".$courseId; $res = Database::query($sql); $row = Database::fetch_array($res); + $allowMandatory = api_get_configuration_value('allow_mandatory_question_in_category'); if ($row['nb'] > 0) { + $extraMandatoryCondition = ''; + if ($allowMandatory) { + $extraMandatoryCondition = ", mandatory = {$this->mandatory}"; + } $sql = "UPDATE $table SET category_id = $categoryId + $extraMandatoryCondition WHERE question_id = $question_id "; Database::query($sql); @@ -405,6 +404,14 @@ abstract class Question $sql = "INSERT INTO $table (question_id, category_id) VALUES ($question_id, $categoryId)"; Database::query($sql); + if ($allowMandatory) { + $id = Database::insert_id(); + if ($id) { + $sql = "UPDATE $table SET mandatory = {$this->mandatory} + WHERE iid = $id"; + Database::query($sql); + } + } } return true; @@ -1537,7 +1544,7 @@ abstract class Question $explanation = $type->getExplanation(); echo '
  • '; echo '
    '; - $icon = ''. + $icon = ''. Display::return_icon($img, $explanation, null, ICON_SIZE_BIG).''; if (false === $objExercise->force_edit_exercise_in_lp) { diff --git a/public/main/exercise/question_admin.inc.php b/public/main/exercise/question_admin.inc.php index 535824518a..53778d011e 100644 --- a/public/main/exercise/question_admin.inc.php +++ b/public/main/exercise/question_admin.inc.php @@ -61,13 +61,13 @@ if (is_object($objQuestion)) { if (isset($_GET['editQuestion'])) { if (empty($exerciseId)) { Display::addFlash(Display::return_message(get_lang('Item updated'))); - $url = api_get_path(WEB_CODE_PATH).'exercise/admin.php?id='.$exerciseId.'&'.api_get_cidreq().'&editQuestion='.$objQuestion->id; + $url = api_get_path(WEB_CODE_PATH).'exercise/admin.php?exerciseId='.$exerciseId.'&'.api_get_cidreq().'&editQuestion='.$objQuestion->id; header("Location: $url"); exit; } Display::addFlash(Display::return_message(get_lang('Item updated'))); - $url = api_get_path(WEB_CODE_PATH).'exercise/admin.php?id='.$exerciseId.'&'.api_get_cidreq().'&page='.$page; + $url = api_get_path(WEB_CODE_PATH).'exercise/admin.php?exerciseId='.$exerciseId.'&'.api_get_cidreq().'&page='.$page; header("Location: $url"); exit; } else { @@ -78,12 +78,12 @@ if (is_object($objQuestion)) { $page = round($objExercise->getQuestionCount() / $length); } Display::addFlash(Display::return_message(get_lang('Item added'))); - $url = api_get_path(WEB_CODE_PATH).'exercise/admin.php?id='.$exerciseId.'&'.api_get_cidreq().'&page='.$page; + $url = api_get_path(WEB_CODE_PATH).'exercise/admin.php?exerciseId='.$exerciseId.'&'.api_get_cidreq().'&page='.$page; header("Location: $url"); exit; } } else { - echo ''; + echo ''; } } else { if (isset($questionName)) { diff --git a/public/main/exercise/question_create.php b/public/main/exercise/question_create.php index 4a2bb2ee22..2038c0fd74 100644 --- a/public/main/exercise/question_create.php +++ b/public/main/exercise/question_create.php @@ -94,7 +94,7 @@ if ($form->validate()) { header('Location: question_create.php?'.api_get_cidreq().'&error=true'); exit; } - header('Location: admin.php?id='.$values['exercise'].'&newQuestion=yes&isContent='.$values['is_content'].'&answerType='.$answer_type); + header('Location: admin.php?exerciseId='.$values['exercise'].'&newQuestion=yes&isContent='.$values['is_content'].'&answerType='.$answer_type); exit; } else { // header diff --git a/public/main/exercise/question_list_admin.inc.php b/public/main/exercise/question_list_admin.inc.php index 7bacd4293f..fea1534637 100644 --- a/public/main/exercise/question_list_admin.inc.php +++ b/public/main/exercise/question_list_admin.inc.php @@ -161,6 +161,7 @@ if (!$inATest) { // In the building exercise mode show question list ordered as is. $objExercise->setCategoriesGrouping(false); + $originalQuestionSelectType = $objExercise->questionSelectionType; // In building mode show all questions not render by teacher order. $objExercise->questionSelectionType = EX_Q_SELECTION_ORDERED; $allowQuestionOrdering = true; @@ -195,6 +196,7 @@ if (!$inATest) { // Classic order $questionList = $objExercise->selectQuestionList(true, true); } + $objExercise->questionSelectionType = $originalQuestionSelectType; echo '