@@ -728,8 +728,11 @@ public static function get_avg_student_score($student_id, $course_code, $lp_ids
728728
729729 if ($ get_only_latest_attempt_results ) {
730730 //Getting lp_items done by the user
731- $ sql = "SELECT DISTINCT lp_item_id FROM $ lp_item_view_table
732- WHERE c_id = $ course_id AND lp_view_id = $ lp_view_id ORDER BY lp_item_id " ;
731+ $ sql = "SELECT DISTINCT lp_item_id
732+ FROM $ lp_item_view_table
733+ WHERE c_id = $ course_id AND
734+ lp_view_id = $ lp_view_id
735+ ORDER BY lp_item_id " ;
733736 $ res_lp_item = Database::query ($ sql );
734737
735738 while ($ row_lp_item = Database::fetch_array ($ res_lp_item ,'ASSOC ' )) {
@@ -825,18 +828,22 @@ public static function get_avg_student_score($student_id, $course_code, $lp_ids
825828
826829 // Within the last attempt number tracking, get the sum of
827830 // the max_scores of all questions that it was
828- // made of (we need to make this call dynamic
829- // because of random questions selection)
831+ // made of (we need to make this call dynamic because of random questions selection)
830832 $ sql = "SELECT SUM(t.ponderation) as maxscore FROM
831- ( SELECT distinct question_id, marks, ponderation FROM $ tbl_stats_attempts AS at INNER JOIN $ tbl_quiz_questions AS q ON (q.id = at.question_id)
832- WHERE exe_id =' $ id_last_attempt' ) AS t " ;
833+ (
834+ SELECT distinct question_id, marks, ponderation
835+ FROM $ tbl_stats_attempts AS at INNER JOIN $ tbl_quiz_questions AS q ON (q.id = at.question_id)
836+ WHERE exe_id =' $ id_last_attempt' AND q.c_id = $ course_id
837+ )
838+ AS t " ;
839+ if ($ debug ) echo '$sql: ' .$ sql .' <br /> ' ;
833840 $ res_max_score_bis = Database::query ($ sql );
834841 $ row_max_score_bis = Database :: fetch_array ($ res_max_score_bis );
835842 if (!empty ($ row_max_score_bis ['maxscore ' ])) {
836843 $ max_score = $ row_max_score_bis ['maxscore ' ];
837844 }
838845 if (!empty ($ max_score )) {
839- $ lp_partial_total += $ score /$ max_score ;
846+ $ lp_partial_total += $ score /$ max_score ;
840847 }
841848 if ($ debug ) echo '$lp_partial_total, $score, $max_score <b> ' .$ lp_partial_total .' ' .$ score .' ' .$ max_score .'</b><br /> ' ;
842849 }
@@ -870,7 +877,8 @@ public static function get_avg_student_score($student_id, $course_code, $lp_ids
870877 if ($ debug ) var_dump ($ lp_list );
871878 foreach ($ lp_list as $ lp_id ) {
872879 //Check if LP have a score we asume that all SCO have an score
873- $ sql = "SELECT count(id) as count FROM $ lp_item_table WHERE c_id = $ course_id AND (item_type = 'quiz' OR item_type = 'sco') AND lp_id = " .$ lp_id ;
880+ $ sql = "SELECT count(id) as count FROM $ lp_item_table
881+ WHERE c_id = $ course_id AND (item_type = 'quiz' OR item_type = 'sco') AND lp_id = " .$ lp_id ;
874882 if ($ debug ) echo $ sql ;
875883 $ result_have_quiz = Database::query ($ sql );
876884
0 commit comments