Fix for 4.1 point in -refs BT#7349

1.9.x
Daniel Barreto 11 years ago
parent bfa4f37b72
commit 4554d793d4
  1. 65
      main/inc/lib/tracking.lib.php
  2. 30
      main/mySpace/myStudents.php
  3. 8
      main/newscorm/lp_stats.php

@ -351,13 +351,22 @@ class Tracking
/**
* Gets the score average from all tests in a course by student
*
* @param mixed Student(s) id
* @param string Course code
* @param int Exercise id (optional), filtered by exercise
* @param int Session id (optional), if param $session_id is null it'll return results including sessions, 0 = session is not filtered
* @return string value (number %) Which represents a round integer about the score average.
* @param $student_id
* @param $course_code
* @param int $exercise_id
* @param null $session_id
* @param int $active_filter 2 for consider all tests
* 1 for active <> -1
* 0 for active <> 0
* @param int $into_lp 1 for all exercises
* 0 for whitout LP
* @internal param \Student $mixed id
* @internal param \Course $string code
* @internal param \Exercise $int id (optional), filtered by exercise
* @internal param \Session $int id (optional), if param $session_id is null it'll return results including sessions, 0 = session is not filtered
* @return string value (number %) Which represents a round integer about the score average.
*/
public static function get_avg_student_exercise_score($student_id, $course_code, $exercise_id = 0, $session_id = null) {
public static function get_avg_student_exercise_score($student_id, $course_code, $exercise_id = 0, $session_id = null, $active_filter = 1, $into_lp = 0) {
$course_info = api_get_course_info($course_code);
if (!empty($course_info)) {
@ -378,8 +387,23 @@ class Tracking
$session_id = intval($session_id);
$condition_session = " AND session_id = $session_id ";
}
if ($active_filter == 1) {
$condition_active = 'AND active <> -1';
} elseif ($active_filter == 0) {
$condition_active = 'AND active <> 0';
} else {
$condition_active = '';
}
$condition_into_lp = '';
$select_lp_id = '';
if ($into_lp == 0) {
$condition_into_lp = 'AND orig_lp_id = 0 AND orig_lp_item_id = 0';
} else {
$select_lp_id = ', orig_lp_id as lp_id ';
}
$sql = "SELECT count(id) FROM $tbl_course_quiz
WHERE c_id = {$course_info['real_id']} AND active <> -1 $condition_quiz ";
WHERE c_id = {$course_info['real_id']} $condition_active $condition_quiz ";
$count_quiz = Database::fetch_row(Database::query($sql));
if (!empty($count_quiz[0]) && !empty($student_id)) {
@ -392,7 +416,7 @@ class Tracking
if (empty($exercise_id)) {
$sql = "SELECT id FROM $tbl_course_quiz
WHERE c_id = {$course_info['real_id']} AND active <> -1 $condition_quiz";
WHERE c_id = {$course_info['real_id']} $condition_active $condition_quiz";
$result = Database::query($sql);
$exercise_list = array();
$exercise_id = null;
@ -409,17 +433,19 @@ class Tracking
$count_quiz = Database::fetch_row(Database::query($sql));
$sql = "SELECT SUM(exe_result/exe_weighting*100) as avg_score, COUNT(*) as num_attempts
$select_lp_id
FROM $tbl_stats_exercise
WHERE exe_exo_id IN ('".$exercise_id."')
$condition_user AND
status = '' AND
exe_cours_id = '$course_code'
$condition_session
$condition_into_lp
ORDER BY exe_date DESC";
$res = Database::query($sql);
$row = Database::fetch_array($res);
$quiz_avg_score = 0;
$quiz_avg_score = null;
if (!empty($row['avg_score'])) {
$quiz_avg_score = round($row['avg_score'],2);
@ -431,7 +457,26 @@ class Tracking
if (is_array($student_id)) {
$quiz_avg_score = round($quiz_avg_score / count($student_id), 2);
}
return $quiz_avg_score;
if ($into_lp == 0) {
return $quiz_avg_score;
} else {
if (!empty($row['lp_id'])) {
$tbl_lp = Database::get_course_table(TABLE_LP_MAIN);
$tbl_course = Database::get_main_table(TABLE_MAIN_COURSE);
$sql = "SELECT lp.name FROM $tbl_lp as lp, $tbl_course as c WHERE
c.code = '$course_code' AND
lp.id = ".$row['lp_id']." AND
lp.c_id = c.id
LIMIT 1;
";
$result = Database::query($sql);
$row_lp = Database::fetch_row($result);
$lp_name = $row_lp[0];
return array($quiz_avg_score, $lp_name);
} else {
return array($quiz_avg_score, null);
}
}
}
}
return null;

@ -858,7 +858,8 @@ if (empty($_GET['details'])) {
<table class="data_table">
<tr>
<th><?php echo get_lang('Exercices'); ?></th>
<th><?php echo get_lang('AverageScore').' '.Display :: return_icon('info3.gif', get_lang('AverageScore'), array('align' => 'absmiddle', 'hspace' => '3px')) ?></th>
<th><?php echo get_lang('LearningPath');?></th>
<th><?php echo get_lang('AvgCourseScore').' '.Display :: return_icon('info3.gif', get_lang('AverageScore'), array('align' => 'absmiddle', 'hspace' => '3px')) ?></th>
<th><?php echo get_lang('Attempts'); ?></th>
<th><?php echo get_lang('LatestAttempt'); ?></th>
<th><?php echo get_lang('AllAttempts'); ?></th>
@ -883,14 +884,23 @@ if (empty($_GET['details'])) {
if (Database :: num_rows($result_exercices) > 0) {
while ($exercices = Database :: fetch_array($result_exercices)) {
$exercise_id = intval($exercices['id']);
$lp_name = '';
$count_attempts = Tracking::count_student_exercise_attempts($student_id, $course_code, $exercise_id, 0, 0, $session_id, 2);
$score_percentage = Tracking::get_avg_student_exercise_score($student_id, $course_code, $exercise_id, $session_id);
$score_percentage = Tracking::get_avg_student_exercise_score($student_id, $course_code, $exercise_id, $session_id, 1, 0);
if (!isset($score_percentage) && $count_attempts > 0) {
$scores_lp = Tracking::get_avg_student_exercise_score($student_id, $course_code, $exercise_id, $session_id, 2, 1);
$score_percentage = $scores_lp[0];
$lp_name = $scores_lp[1];
} else {
$lp_name = '-';
}
$lp_name = (!empty($lp_name))? $lp_name: get_lang('NoLearnpath');
$csv_content[] = array (
$exercices['title'],
$score_percentage . '%',
$count_attempts
);
if ($i % 2) $css_class = 'row_odd';
@ -898,7 +908,17 @@ if (empty($_GET['details'])) {
echo '<tr class="'.$css_class.'"><td>'.$exercices['title'].'</td>';
echo '<td>';
echo '<td>';
if (!empty($lp_name)) {
echo $lp_name;
} else {
echo '-';
}
echo '</td>';
echo '<td>';
if ($count_attempts > 0) {
echo $score_percentage . '%';

@ -859,10 +859,10 @@ if (!empty($a_my_id)) {
//var_dump($my_studen_id, $my_course_id,$a_my_id);
if (isset($_GET['extend_attempt'])) {
//"Right green cross" extended
$total_score = Tracking::get_avg_student_score($my_studen_id, $my_course_id, $a_my_id, api_get_session_id(), false, false);
$total_score = Tracking::get_avg_student_score($my_studen_id, $my_course_id, $a_my_id, $session_id, false, false);
} else {
//"Left green cross" extended
$total_score = Tracking::get_avg_student_score($my_studen_id, $my_course_id, $a_my_id, api_get_session_id(), false, true);
$total_score = Tracking::get_avg_student_score($my_studen_id, $my_course_id, $a_my_id, $session_id, false, true);
}
} else {
// Extend all "left green cross"
@ -870,12 +870,12 @@ if (!empty($a_my_id)) {
$my_course_id = Database::escape_string($_GET['course']);
// var_dump($student_id, $my_course_id );
if (!empty($student_id) && !empty($my_course_id)) {
$total_score = Tracking::get_avg_student_score($student_id, $my_course_id, array(intval($_GET['lp_id'])), api_get_session_id(), false, false);
$total_score = Tracking::get_avg_student_score($student_id, $my_course_id, array(intval($_GET['lp_id'])), $session_id, false, false);
} else {
$total_score = 0;
}
} else {
$total_score = Tracking::get_avg_student_score(api_get_user_id(), api_get_course_id(), array(intval($_GET['lp_id'])), api_get_session_id(), false, false);
$total_score = Tracking::get_avg_student_score(api_get_user_id(), api_get_course_id(), array(intval($_GET['lp_id'])), $session_id, false, false);
}
}

Loading…
Cancel
Save