Skip to content
Permalink
Browse files

Add new "result disable" option in exercises "Show only correct answe…

…r" BT#15233
  • Loading branch information...
jmontoyaa committed Mar 20, 2019
1 parent 57f18d1 commit 7c93e972321d371541382a3adbc342f9faff8a48
@@ -3537,8 +3537,10 @@ public function manage_answer(
if (!empty($studentChoice)) {
if ($studentChoice == $answerCorrect) {
// correct answer and student is Unsure or PrettySur
if ($quiz_question_options[$studentChoiceDegree]['position'] >= 3
&& $quiz_question_options[$studentChoiceDegree]['position'] < 9) {
if (isset($quiz_question_options[$studentChoiceDegree]) &&
$quiz_question_options[$studentChoiceDegree]['position'] >= 3 &&
$quiz_question_options[$studentChoiceDegree]['position'] < 9
) {
$questionScore += $true_score;
} else {
// student ignore correct answer
@@ -3629,21 +3631,15 @@ public function manage_answer(
}
$studentChoice = isset($choice[$answerAutoId]) ? $choice[$answerAutoId] : '';
$real_answers[$answerId] = false;
if ($answerCorrect == $studentChoice) {
//$answerCorrect = 1;
$real_answers[$answerId] = true;
} else {
//$answerCorrect = 0;
$real_answers[$answerId] = false;
}
} else {
$studentChoice = isset($choice[$answerAutoId]) ? $choice[$answerAutoId] : '';
$real_answers[$answerId] = false;
if ($answerCorrect == $studentChoice) {
//$answerCorrect = 1;
$real_answers[$answerId] = true;
} else {
//$answerCorrect = 0;
$real_answers[$answerId] = false;
}
}
break;
@@ -3659,31 +3655,27 @@ public function manage_answer(
$studentChoice = isset($choice[$answerAutoId]) ? $choice[$answerAutoId] : null;
if ($answerCorrect == 1) {
$real_answers[$answerId] = false;
if ($studentChoice) {
$real_answers[$answerId] = true;
} else {
$real_answers[$answerId] = false;
}
} else {
$real_answers[$answerId] = true;
if ($studentChoice) {
$real_answers[$answerId] = false;
} else {
$real_answers[$answerId] = true;
}
}
} else {
$studentChoice = isset($choice[$answerAutoId]) ? $choice[$answerAutoId] : null;
if ($answerCorrect == 1) {
$real_answers[$answerId] = false;
if ($studentChoice) {
$real_answers[$answerId] = true;
} else {
$real_answers[$answerId] = false;
}
} else {
$real_answers[$answerId] = true;
if ($studentChoice) {
$real_answers[$answerId] = false;
} else {
$real_answers[$answerId] = true;
}
}
}
@@ -4283,6 +4275,12 @@ public function manage_answer(
}
}
if ($results_disabled == RESULT_DISABLE_SHOW_ONLY_IN_CORRECT_ANSWER) {
if ($s_user_answer != $i_answer_correct_answer) {
continue;
}
}
if ($show_result) {
if ($this->showExpectedChoice() == false &&
$showTotalScoreAndUserChoicesInLastAttempt === false
@@ -4901,6 +4899,7 @@ public function manage_answer(
if ($debug) {
error_log('Showing questions $from '.$from);
}
switch ($answerType) {
case UNIQUE_ANSWER:
case UNIQUE_ANSWER_IMAGE:
@@ -5097,26 +5096,6 @@ public function manage_answer(
case HOT_SPOT_DELINEATION:
$user_answer = $user_array;
if ($next) {
//$tbl_track_e_hotspot = Database::get_main_table(TABLE_STATISTIC_TRACK_E_HOTSPOT);
// Save into db
/* $sql = "INSERT INTO $tbl_track_e_hotspot (
* hotspot_user_id,
* hotspot_course_code,
* hotspot_exe_id,
* hotspot_question_id,
* hotspot_answer_id,
* hotspot_correct,
* hotspot_coordinate
* )
VALUES (
* '".Database::escape_string($_user['user_id'])."',
* '".Database::escape_string($_course['id'])."',
* '".Database::escape_string($exeId)."', '".Database::escape_string($questionId)."',
* '".Database::escape_string($answerId)."',
* '".Database::escape_string($studentChoice)."',
* '".Database::escape_string($user_array)."')";
$result = Database::query($sql,__FILE__,__LINE__);
*/
$user_answer = $user_array;
// we compare only the delineation not the other points
$answer_question = $_SESSION['hotspot_coord'][1];
@@ -5266,7 +5245,6 @@ public function manage_answer(
)
);
echo '</tr>';
break;
case ANNOTATION:
ExerciseShowFunctions::displayAnnotationAnswer(
@@ -5578,16 +5556,17 @@ public function manage_answer(
) {
if ($choice != 0) {
$reply = array_keys($choice);
for ($i = 0; $i < sizeof($reply); $i++) {
$countReply = count($reply);
for ($i = 0; $i < $countReply; $i++) {
$chosenAnswer = $reply[$i];
if ($answerType == MULTIPLE_ANSWER_TRUE_FALSE_DEGREE_CERTAINTY) {
if ($choiceDegreeCertainty != 0) {
$replyDegreeCertainty = array_keys($choiceDegreeCertainty);
$answerDegreeCertainty = $replyDegreeCertainty[$i];
$answerDegreeCertainty = isset($replyDegreeCertainty[$i]) ? $replyDegreeCertainty[$i] : '';
$answerValue = isset($choiceDegreeCertainty[$answerDegreeCertainty]) ? $choiceDegreeCertainty[$answerDegreeCertainty] : '';
Event::saveQuestionAttempt(
$questionScore,
$chosenAnswer.':'.$choice[$chosenAnswer].':'.
$choiceDegreeCertainty[$answerDegreeCertainty],
$chosenAnswer.':'.$choice[$chosenAnswer].':'.$answerValue,
$quesId,
$exeId,
$i,
@@ -8403,14 +8382,14 @@ private function setResultDisabledGroup(FormValidator $form)
['id' => 'result_disabled_6']
);
/*$resultDisabledGroup[] = $form->createElement(
$resultDisabledGroup[] = $form->createElement(
'radio',
'results_disabled',
null,
get_lang('ExerciseShowOnlyCorrectAnswer'),
'7',
['id' => 'result_disabled_7']
);*/
);
$group = $form->addGroup(
$resultDisabledGroup,
@@ -1231,6 +1231,12 @@ public static function getHtmlDisplayForAnswer(
// rebuild the sentence with student answer inserted
for ($i = 0; $i < count($listStudentAnswerInfo['common_words']); $i++) {
if ($resultsDisabled == RESULT_DISABLE_SHOW_ONLY_IN_CORRECT_ANSWER) {
if (isset($listStudentAnswerInfo['student_score'][$i]) &&
$listStudentAnswerInfo['student_score'][$i] != 1) {
continue;
}
}
$result .= isset($listStudentAnswerInfo['common_words'][$i]) ? $listStudentAnswerInfo['common_words'][$i] : '';
$result .= isset($listStudentAnswerInfo['student_answer'][$i]) ? $listStudentAnswerInfo['student_answer'][$i] : '';
}
@@ -163,8 +163,36 @@
/** @var CQuizAnswer $hotSpotAnswer */
foreach ($result as $hotSpotAnswer) {
$hotSpotAnswerId = $hotSpotAnswer->getIid();
// Show only correct hotspots
if ($objExercise->selectResultsDisabled() == RESULT_DISABLE_SHOW_ONLY_IN_CORRECT_ANSWER) {
$TBL_TRACK_HOTSPOT = Database::get_main_table(TABLE_STATISTIC_TRACK_E_HOTSPOT);
// Check auto id
$sql = "SELECT hotspot_correct
FROM $TBL_TRACK_HOTSPOT
WHERE
hotspot_exe_id = $exeId AND
hotspot_question_id= $questionId AND
hotspot_answer_id = ".$hotSpotAnswerId."
ORDER BY hotspot_id ASC";
$result = Database::query($sql);
$studentChoice = false;
if (Database::num_rows($result)) {
$studentChoice = Database::result(
$result,
0,
'hotspot_correct'
);
}
if (!$studentChoice) {
continue;
}
}
$hotSpot = [];
$hotSpot['id'] = $hotSpotAnswer->getIid();
$hotSpot['id'] = $hotSpotAnswerId;
$hotSpot['answer'] = $hotSpotAnswer->getAnswer();
switch ($hotSpotAnswer->getHotspotType()) {
@@ -52,7 +52,7 @@
'url' => 'exercise.php?'.api_get_cidreq(),
'name' => get_lang('Exercises'),
];
$interbreadcrumb[] = ["url" => "#", "name" => $objExercise->selectTitle(true)];
$interbreadcrumb[] = ['url' => '#', 'name' => $objExercise->selectTitle(true)];
$time_control = false;
$clock_expired_time = ExerciseLib::get_session_time_control_key($objExercise->id, $learnpath_id, $learnpath_item_id);
@@ -210,10 +210,7 @@
if (!empty($attempts)) {
$i = $counter;
foreach ($attempts as $attempt_result) {
$score = ExerciseLib::show_score(
$attempt_result['exe_result'],
$attempt_result['exe_weighting']
);
$score = ExerciseLib::show_score($attempt_result['exe_result'], $attempt_result['exe_weighting']);
$attempt_url = api_get_path(WEB_CODE_PATH).'exercise/result.php?';
$attempt_url .= api_get_cidreq().'&show_headers=1&';
$attempt_url .= http_build_query([
@@ -254,6 +251,7 @@
RESULT_DISABLE_SHOW_SCORE_ATTEMPT_SHOW_ANSWERS_LAST_ATTEMPT,
RESULT_DISABLE_DONT_SHOW_SCORE_ONLY_IF_USER_FINISHES_ATTEMPTS_SHOW_ALWAYS_FEEDBACK,
RESULT_DISABLE_RANKING,
RESULT_DISABLE_SHOW_ONLY_IN_CORRECT_ANSWER
]
)) {
$row['result'] = $score;
@@ -267,6 +265,7 @@
RESULT_DISABLE_SHOW_SCORE_ATTEMPT_SHOW_ANSWERS_LAST_ATTEMPT,
RESULT_DISABLE_DONT_SHOW_SCORE_ONLY_IF_USER_FINISHES_ATTEMPTS_SHOW_ALWAYS_FEEDBACK,
RESULT_DISABLE_RANKING,
RESULT_DISABLE_SHOW_ONLY_IN_CORRECT_ANSWER
]
) || (
$objExercise->results_disabled == RESULT_DISABLE_SHOW_SCORE_ONLY &&
@@ -1980,20 +1980,20 @@ public function return_header($exercise, $counter = null, $score = [])
if (!empty($counter)) {
$counterLabel = (int) $counter;
}
$score_label = get_lang('Wrong');
$scoreLabel = get_lang('Wrong');
$class = 'error';
if (isset($score['pass']) && $score['pass'] == true) {
$score_label = get_lang('Correct');
$scoreLabel = get_lang('Correct');
$class = 'success';
}
if (in_array($this->type, [FREE_ANSWER, ORAL_EXPRESSION, ANNOTATION])) {
$score['revised'] = isset($score['revised']) ? $score['revised'] : false;
if ($score['revised'] == true) {
$score_label = get_lang('Revised');
$scoreLabel = get_lang('Revised');
$class = '';
} else {
$score_label = get_lang('NotRevised');
$scoreLabel = get_lang('NotRevised');
$class = 'warning';
if (isset($score['weight'])) {
$weight = float_format($score['weight'], 1);
@@ -2029,7 +2029,10 @@ public function return_header($exercise, $counter = null, $score = [])
// dont display score for certainty degree questions
if ($this->type != MULTIPLE_ANSWER_TRUE_FALSE_DEGREE_CERTAINTY) {
if (isset($score['result'])) {
$header .= $exercise->getQuestionRibbon($class, $score_label, $score['result'], $scoreCurrent);
if ($exercise->results_disabled == RESULT_DISABLE_SHOW_ONLY_IN_CORRECT_ANSWER) {
$score['result'] = null;
}
$header .= $exercise->getQuestionRibbon($class, $scoreLabel, $score['result'], $scoreCurrent);
}
}
@@ -2070,6 +2073,7 @@ public function return_header($exercise, $counter = null, $score = [])
}
/**
* @deprecated
* Create a question from a set of parameters.
*
* @param int Quiz ID
@@ -4429,6 +4429,10 @@ public static function displayQuestionListByAttempt(
$show_results = true;
}
if ($objExercise->results_disabled == RESULT_DISABLE_SHOW_ONLY_IN_CORRECT_ANSWER) {
$show_results = true;
}
if (in_array(
$objExercise->results_disabled,
[

0 comments on commit 7c93e97

Please sign in to comment.
You can’t perform that action at this time.