diff --git a/main/exercise/TestCategory.php b/main/exercise/TestCategory.php index 60662b2981..20bf2a5303 100644 --- a/main/exercise/TestCategory.php +++ b/main/exercise/TestCategory.php @@ -667,7 +667,7 @@ class TestCategory */ public static function getCatScoreForExeidForUserid($in_cat_id, $in_exe_id, $in_user_id) { - $tbl_track_attempt = Database::get_statistic_table(TABLE_STATISTIC_TRACK_E_ATTEMPT); + $tbl_track_attempt = Database::get_main_table(TABLE_STATISTIC_TRACK_E_ATTEMPT); $tbl_question_rel_category = Database::get_course_table(TABLE_QUIZ_QUESTION_REL_CATEGORY); $in_cat_id = intval($in_cat_id); $in_exe_id = intval($in_exe_id); @@ -681,11 +681,12 @@ class TestCategory qrc.category_id=$in_cat_id AND exe_id=$in_exe_id AND user_id=$in_user_id"; $res = Database::query($query); - $totalcatscore = ""; + $score = ''; while ($data = Database::fetch_array($res)) { - $totalcatscore += $data['marks']; + $score += $data['marks']; } - return $totalcatscore; + + return $score; } /** diff --git a/main/exercise/exercise.class.php b/main/exercise/exercise.class.php index 7263de7ff4..00f4a54dec 100755 --- a/main/exercise/exercise.class.php +++ b/main/exercise/exercise.class.php @@ -2658,7 +2658,7 @@ class Exercise public function clean_results($cleanLpTests = false, $cleanResultBeforeDate = null) { $table_track_e_exercises = Database::get_main_table(TABLE_STATISTIC_TRACK_E_EXERCISES); - $table_track_e_attempt = Database::get_main_table(TABLE_STATISTIC_TRACK_E_ATTEMPT); + $table_track_e_attempt = Database::get_main_table(TABLE_STATISTIC_TRACK_E_ATTEMPT); $sql_where = ' AND orig_lp_id = 0 AND diff --git a/main/exercise/exercise_history.php b/main/exercise/exercise_history.php index a9f29e5f05..a89e104615 100755 --- a/main/exercise/exercise_history.php +++ b/main/exercise/exercise_history.php @@ -29,9 +29,9 @@ $interbreadcrumb[]= array ('url' => 'exercise_report.php?'.api_get_cidreq(),'nam $interbreadcrumb[]= array ('url' => 'exercise_report.php?filter=2&'.api_get_cidreq(),'name' => get_lang('StudentScore')); $interbreadcrumb[]= array ('url' => 'exercise_history.php?exe_id='.intval($_GET['exe_id']).'&'.api_get_cidreq(), 'name' => get_lang('Details')); -$TBL_USER = Database::get_main_table(TABLE_MAIN_USER); -$TBL_EXERCISES = Database::get_course_table(TABLE_QUIZ_TEST); -$TBL_EXERCISES_QUESTION = Database::get_course_table(TABLE_QUIZ_QUESTION); +$TBL_USER = Database::get_main_table(TABLE_MAIN_USER); +$TBL_EXERCISES = Database::get_course_table(TABLE_QUIZ_TEST); +$TBL_EXERCISES_QUESTION = Database::get_course_table(TABLE_QUIZ_QUESTION); $TBL_TRACK_ATTEMPT_RECORDING= Database::get_main_table(TABLE_STATISTIC_TRACK_E_ATTEMPT_RECORDING); Display::display_header($nameTools,get_lang('Exercise')); @@ -59,8 +59,14 @@ echo ''; = "'.$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 self::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; + // 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 = '.$courseId.' + AND exe_exo_id = '.$testId.' + + WHERE + tee.c_id = '.$courseId.' 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 self::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; } /** @@ -838,16 +840,17 @@ class FillBlanks extends Question { $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) { + foreach ($resultList as $userId => $tabValue) { + $found = false; + // for each bracket, if student has at least one answer ( choice > -2) then he pass the question + foreach ($tabValue as $i => $choice) { + if ($choice > -2 && !$found) { $outRes++; - $trouve = true; + $found = true; } } } + return $outRes; } @@ -1044,8 +1047,11 @@ class FillBlanks extends Question * * @return string */ - public static function getHtmlDisplayForAnswer($answer, $resultsDisabled = false, $showTotalScoreAndUserChoices = false) - { + public static function getHtmlDisplayForAnswer( + $answer, + $resultsDisabled = false, + $showTotalScoreAndUserChoices = false + ) { $result = ''; $listStudentAnswerInfo = self::getAnswerInfo($answer, true); @@ -1075,7 +1081,6 @@ class FillBlanks extends Question } } - // rebuild the sentence with student answer inserted for ($i=0; $i < count($listStudentAnswerInfo['commonwords']); $i++) { $result .= isset($listStudentAnswerInfo['commonwords'][$i]) ? $listStudentAnswerInfo['commonwords'][$i] : ''; diff --git a/main/inc/lib/events.lib.php b/main/inc/lib/events.lib.php index 0a6cdf6967..7c440d194a 100644 --- a/main/inc/lib/events.lib.php +++ b/main/inc/lib/events.lib.php @@ -1203,7 +1203,8 @@ class Event $list = array(); while ($row = Database::fetch_array($res, 'ASSOC')) { $list[$row['exe_id']] = $row; - $sql = "SELECT * FROM $table_track_attempt WHERE exe_id = {$row['exe_id']}"; + $sql = "SELECT * FROM $table_track_attempt + WHERE exe_id = {$row['exe_id']}"; $res_question = Database::query($sql); while ($row_q = Database::fetch_array($res_question, 'ASSOC')) { $list[$row['exe_id']]['question_list'][$row_q['question_id']] = $row_q; @@ -1243,7 +1244,8 @@ class Event $list = array(); while ($row = Database::fetch_array($res, 'ASSOC')) { $list[$row['exe_id']] = $row; - $sql = "SELECT * FROM $table_track_attempt WHERE exe_id = {$row['exe_id']}"; + $sql = "SELECT * FROM $table_track_attempt + WHERE exe_id = {$row['exe_id']}"; $res_question = Database::query($sql); while ($row_q = Database::fetch_array($res_question, 'ASSOC')) { $list[$row['exe_id']]['question_list'][$row_q['question_id']] = $row_q; @@ -1279,7 +1281,8 @@ class Event //Checking if this attempt was revised by a teacher $sql_revised = 'SELECT exe_id FROM '.$table_track_attempt_recording.' - WHERE author != "" AND exe_id = '.$exe_id.' LIMIT 1'; + WHERE author != "" AND exe_id = '.$exe_id.' + LIMIT 1'; $res_revised = Database::query($sql_revised); $row['attempt_revised'] = 0; if (Database::num_rows($res_revised) > 0) { @@ -1287,7 +1290,8 @@ class Event } $list[$exe_id] = $row; $sql = "SELECT * FROM $table_track_attempt - WHERE exe_id = $exe_id ORDER BY tms ASC"; + WHERE exe_id = $exe_id + ORDER BY tms ASC"; $res_question = Database::query($sql); while ($row_q = Database::fetch_array($res_question, 'ASSOC')) { $list[$exe_id]['question_list'][$row_q['question_id']] = $row_q; @@ -1346,7 +1350,7 @@ class Event $res = Database::query($sql); $list = array(); while ($row = Database::fetch_array($res, 'ASSOC')) { - //Checking if this attempt was revised by a teacher + // Checking if this attempt was revised by a teacher $sql = 'SELECT exe_id FROM '.$table_track_attempt_recording.' WHERE author != "" AND exe_id = '.$row['exe_id'].' LIMIT 1'; @@ -1432,7 +1436,8 @@ class Event $list = array(); while ($row = Database::fetch_array($res, 'ASSOC')) { $list[$row['exe_id']] = $row; - $sql = "SELECT * FROM $table_track_attempt WHERE exe_id = {$row['exe_id']}"; + $sql = "SELECT * FROM $table_track_attempt + WHERE exe_id = {$row['exe_id']}"; $res_question = Database::query($sql); while ($row_q = Database::fetch_array($res_question, 'ASSOC')) { $list[$row['exe_id']]['question_list'][$row_q['question_id']] = $row_q; @@ -1597,7 +1602,8 @@ class Event $list = array(); while ($row = Database::fetch_array($res, 'ASSOC')) { $list[$row['exe_id']] = $row; - $sql = "SELECT * FROM $table_track_attempt WHERE exe_id = {$row['exe_id']}"; + $sql = "SELECT * FROM $table_track_attempt + WHERE exe_id = {$row['exe_id']}"; $res_question = Database::query($sql); while ($row_q = Database::fetch_array($res_question, 'ASSOC')) { $list[$row['exe_id']]['question_list'][$row_q['question_id']] = $row_q; @@ -1737,10 +1743,11 @@ class Event } $sql = "DELETE FROM $table_track_attempt - WHERE hotspot_exe_id = $exe_id AND - hotspot_user_id = $user_id AND - c_id = $courseId AND - hotspot_question_id = $question_id "; + WHERE + hotspot_exe_id = $exe_id AND + hotspot_user_id = $user_id AND + c_id = $courseId AND + hotspot_question_id = $question_id "; Database::query($sql); Event::addEvent( LOG_QUESTION_RESULT_DELETE, diff --git a/main/inc/lib/exercise.lib.php b/main/inc/lib/exercise.lib.php index 25fe142742..cfc8c02425 100644 --- a/main/inc/lib/exercise.lib.php +++ b/main/inc/lib/exercise.lib.php @@ -2865,14 +2865,9 @@ HOTSPOT; $exercise_id, $course_code, $session_id - ) - { - $track_exercises = Database::get_main_table( - TABLE_STATISTIC_TRACK_E_EXERCISES - ); - $track_attempt = Database::get_main_table( - TABLE_STATISTIC_TRACK_E_ATTEMPT - ); + ) { + $track_exercises = Database::get_main_table(TABLE_STATISTIC_TRACK_E_EXERCISES); + $track_attempt = Database::get_main_table(TABLE_STATISTIC_TRACK_E_ATTEMPT); $question_id = intval($question_id); $exercise_id = intval($exercise_id); @@ -2966,14 +2961,9 @@ HOTSPOT; $course_code, $session_id, $questionType = '' - ) - { - $track_exercises = Database::get_main_table( - TABLE_STATISTIC_TRACK_E_EXERCISES - ); - $track_attempt = Database::get_main_table( - TABLE_STATISTIC_TRACK_E_ATTEMPT - ); + ) { + $track_exercises = Database::get_main_table(TABLE_STATISTIC_TRACK_E_EXERCISES); + $track_attempt = Database::get_main_table(TABLE_STATISTIC_TRACK_E_ATTEMPT); $courseUser = Database::get_main_table(TABLE_MAIN_COURSE_USER); $courseTable = Database::get_main_table(TABLE_MAIN_COURSE); $courseUserSession = Database::get_main_table( @@ -3140,14 +3130,9 @@ HOTSPOT; $question_type = null, $correct_answer = null, $current_answer = null - ) - { - $track_exercises = Database::get_main_table( - TABLE_STATISTIC_TRACK_E_EXERCISES - ); - $track_attempt = Database::get_main_table( - TABLE_STATISTIC_TRACK_E_ATTEMPT - ); + ) { + $track_exercises = Database::get_main_table(TABLE_STATISTIC_TRACK_E_EXERCISES); + $track_attempt = Database::get_main_table(TABLE_STATISTIC_TRACK_E_ATTEMPT); $courseTable = Database::get_main_table(TABLE_MAIN_COURSE); $courseUser = Database::get_main_table(TABLE_MAIN_COURSE_USER); $courseUserSession = Database::get_main_table( @@ -3380,27 +3365,23 @@ HOTSPOT; $exercise_id, $course_code, $session_id - ) - { - $track_exercises = Database::get_main_table( - TABLE_STATISTIC_TRACK_E_EXERCISES - ); - $track_attempt = Database::get_main_table( - TABLE_STATISTIC_TRACK_E_ATTEMPT - ); + ) { + $track_exercises = Database::get_main_table(TABLE_STATISTIC_TRACK_E_EXERCISES); + $track_attempt = Database::get_main_table(TABLE_STATISTIC_TRACK_E_ATTEMPT); $exercise_id = intval($exercise_id); $course_code = Database::escape_string($course_code); $session_id = intval($session_id); $sql = "SELECT DISTINCT exe_user_id - FROM $track_exercises e - INNER JOIN $track_attempt a ON (a.exe_id = e.exe_id) - WHERE - exe_exo_id = $exercise_id AND - course_code = '$course_code' AND - e.session_id = $session_id AND - status = ''"; + FROM $track_exercises e + INNER JOIN $track_attempt a + ON (a.exe_id = e.exe_id) + WHERE + exe_exo_id = $exercise_id AND + course_code = '$course_code' AND + e.session_id = $session_id AND + status = ''"; $result = Database::query($sql); $return = 0; if ($result) { diff --git a/main/inc/lib/tracking.lib.php b/main/inc/lib/tracking.lib.php index 9795e2605f..6e12ccf0d2 100755 --- a/main/inc/lib/tracking.lib.php +++ b/main/inc/lib/tracking.lib.php @@ -5654,7 +5654,7 @@ class Tracking $tquiz_question = Database::get_course_table(TABLE_QUIZ_QUESTION); $tquiz_rel_question = Database::get_course_table(TABLE_QUIZ_TEST_QUESTION); $ttrack_exercises = Database::get_main_table(TABLE_STATISTIC_TRACK_E_EXERCISES); - $ttrack_attempt = Database::get_main_table(TABLE_STATISTIC_TRACK_E_ATTEMPT); + $ttrack_attempt = Database::get_main_table(TABLE_STATISTIC_TRACK_E_ATTEMPT); $sessions = array(); $courses = array(); @@ -5756,9 +5756,12 @@ class Tracking q.title as quiz_title, qq.description as description FROM $ttrack_exercises te - INNER JOIN $ttrack_attempt ta ON ta.exe_id = te.exe_id - INNER JOIN $tquiz q ON q.id = te.exe_exo_id - INNER JOIN $tquiz_rel_question rq ON rq.exercice_id = q.id AND rq.c_id = q.c_id + INNER JOIN $ttrack_attempt ta + ON ta.exe_id = te.exe_id + INNER JOIN $tquiz q + ON q.id = te.exe_exo_id + INNER JOIN $tquiz_rel_question rq + ON rq.exercice_id = q.id AND rq.c_id = q.c_id INNER JOIN $tquiz_question qq ON qq.id = rq.question_id AND