From 2954d4db70121e980d7145be44bdffba93181c35 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Loguercio?= Date: Wed, 17 Feb 2016 18:45:45 -0500 Subject: [PATCH] Fix getFillTheBlankTabResult() and getNbResultFillBlankAll() is not defined - Refs #8077 --- main/exercice/fill_blanks.class.php | 123 ++++++++++++++++++++++++++++ main/inc/lib/exercise.lib.php | 4 +- 2 files changed, 125 insertions(+), 2 deletions(-) diff --git a/main/exercice/fill_blanks.class.php b/main/exercice/fill_blanks.class.php index ebe8f5a203..983425d9c1 100755 --- a/main/exercice/fill_blanks.class.php +++ b/main/exercice/fill_blanks.class.php @@ -727,6 +727,129 @@ class FillBlanks extends Question return $listAnswerResults; } + + /** + * Return an array of student state answers for fill the blank questions + * for each students that answered the question + * -2 : didn't answer + * -1 : student answer is wrong + * 0 : student answer is correct + * >0 : for fill the blank question with choice menu, is the index of the student answer (right answer indice is 0) + * + * @param $testId + * @param $questionId + * @param $studentsIdList + * @param $startDate + * @param $endDate + * @param bool $useLastAnswerredAttempt + * @return array + * ( + * [student_id] => Array + * ( + * [first fill the blank for question] => -1 + * [second fill the blank for question] => 2 + * [third fill the blank for question] => -1 + * ) + * ) + */ + public static function getFillTheBlankTabResult($testId, $questionId, $studentsIdList, $startDate, $endDate, $useLastAnswerredAttempt = true) { + + $tblTrackEAttempt = Database::get_main_table(TABLE_STATISTIC_TRACK_E_ATTEMPT); + $tblTrackEExercise = Database::get_main_table(TABLE_STATISTIC_TRACK_E_EXERCISES); + $tblCQuizAnswer = Database::get_course_table(TABLE_QUIZ_ANSWER); + $courseCode = api_get_course_id(); + + require_once api_get_path(SYS_PATH).'main/exercice/fill_blanks.class.php'; + + // request to have all the answers of student for this question + // student may have doing it several time + // student may have not answered the bracket id, in this case, is result of the answer is empty + + // we got the less recent attempt first + $sql = ' + SELECT * FROM '.$tblTrackEAttempt.' tea + + LEFT JOIN '.$tblTrackEExercise.' tee + ON tee.exe_id = tea.exe_id + AND tea.c_id = "'.$courseCode.'" + AND exe_exo_id = '.$testId.' + + WHERE course_code = "'.$courseCode.'" + AND question_id = '.$questionId.' + AND tea.user_id IN ('.implode(',', $studentsIdList).') + AND tea.tms >= "'.$startDate.'" + AND tea.tms <= "'.$endDate.'" + ORDER BY user_id, tea.exe_id; + '; + + $res = Database::query($sql); + $tabUserResult = array(); + $bracketNumber = 0; + // foreach attempts for all students starting with his older attempt + while ($data = Database::fetch_array($res)) { + $tabAnswer = FillBlanks::getAnswerInfo($data['answer'], true); + + // for each bracket to find in this question + foreach ($tabAnswer['studentanswer'] as $bracketNumber => $studentAnswer) { + + if ($tabAnswer['studentanswer'][$bracketNumber] != '') { + // student has answered this bracket, cool + switch (FillBlanks::getFillTheBlankAnswerType($tabAnswer['tabwords'][$bracketNumber])) { + case FILL_THE_BLANK_MENU : + // get the indice of the choosen answer in the menu + // we know that the right answer is the first entry of the menu, ie 0 + // (remember, menu entries are shuffled when taking the test) + $tabUserResult[$data['user_id']][$bracketNumber] = FillBlanks::getFillTheBlankMenuAnswerNum($tabAnswer['tabwords'][$bracketNumber], $tabAnswer['studentanswer'][$bracketNumber]); + break; + default : + if (FillBlanks::isGoodStudentAnswer($tabAnswer['studentanswer'][$bracketNumber], $tabAnswer['tabwords'][$bracketNumber])) { + $tabUserResult[$data['user_id']][$bracketNumber] = 0; // right answer + } else { + $tabUserResult[$data['user_id']][$bracketNumber] = -1; // wrong answer + } + } + } else { + // student didn't answer this bracket + if ($useLastAnswerredAttempt) { + // if we take into account the last answered attempt + if (!isset($tabUserResult[$data['user_id']][$bracketNumber])) { + $tabUserResult[$data['user_id']][$bracketNumber] = -2; // not answered + } + } else { + // we take the last attempt, even if the student answer the question before + $tabUserResult[$data['user_id']][$bracketNumber] = -2; // not answered + } + } + } + + + } + return $tabUserResult; + } + + + + /** + * Return the number of student that give at leat an answer in the fill the blank test + * @param $resultList + * @return int + */ + public static function getNbResultFillBlankAll($resultList) + { + $outRes = 0; + // for each student in group + foreach($resultList as $userId => $tabValue) { + $trouve = false; + // for each bracket, if student has at leat one answer ( choice > -2) then he pass the question + foreach($tabValue as $i => $choice) { + if ($choice > -2 && !$trouve) { + $outRes++; + $trouve = true; + } + } + } + return $outRes; + } /** * Replace the occurrence of blank word with [correct answer][student answer][answer is correct] diff --git a/main/inc/lib/exercise.lib.php b/main/inc/lib/exercise.lib.php index 0f95044486..2f6bfae1f8 100644 --- a/main/inc/lib/exercise.lib.php +++ b/main/inc/lib/exercise.lib.php @@ -2907,7 +2907,7 @@ HOTSPOT; $listStudentsId[] = $listStudentInfo['user_id']; } - $listFillTheBlankResult = getFillTheBlankTabResult( + $listFillTheBlankResult = FillBlanks::getFillTheBlankTabResult( $exercise_id, $question_id, $listStudentsId, @@ -2915,7 +2915,7 @@ HOTSPOT; '3000-01-01' ); - return getNbResultFillBlankAll($listFillTheBlankResult); + return FillBlanks::getNbResultFillBlankAll($listFillTheBlankResult); } if (empty($session_id)) {