Fixing new session page fixes several bugs + adding columns see BT#2806 - BT#2807- BT#2808- BT#2809

skala
Julio Montoya 14 years ago
parent 74d1f6eab3
commit 5b4a5cdceb
  1. 33
      main/exercice/exercise.class.php
  2. 20
      main/exercice/exercise.lib.php
  3. 3
      main/exercice/exercise_submit.php
  4. 21
      main/inc/lib/array.lib.php
  5. 45
      main/inc/lib/events.lib.inc.php
  6. 470
      main/inc/lib/tracking.lib.php
  7. 2
      main/session/index.php

@ -3233,7 +3233,38 @@ class Exercise {
return $result;
}
public function is_visible_for_student() {
public function is_visible() {
$is_visible = true;
//$this->id;
if ($this->active == 0) {
return false;
}
$limit_time_exists = ((!empty($this->start_time) && $this->start_time != '0000-00-00 00:00:00') || (!empty($this->end_time) && $this->end_time != '0000-00-00 00:00:00')) ? true : false;
if ($limit_time_exists) {
$time_now = time();
if ($this->start_time != '0000-00-00 00:00:00') {
$permission_to_start = (($time_now - $this->start_time) > 0) ? true : false;
} else {
$permission_to_start = true;
}
if ($this->end_time != '0000-00-00 00:00:00') {
$exercise_timeover = (($time_now - $this->end_time) > 0) ? true : false;
} else {
$exercise_timeover = false;
}
if (!$permission_to_start || $exercise_timeover) {
$is_visible = false;
}
}
return $is_visible;
}
}
endif;

@ -1446,6 +1446,26 @@ function get_average_score($exercise_id, $course_code, $session_id) {
*/
function get_average_score_by_course($course_code, $session_id) {
$user_results = get_all_exercise_results_by_course($course_code, $session_id, false);
//echo $course_code.' - '.$session_id.'<br />';
$avg_score = 0;
if (!empty($user_results)) {
foreach($user_results as $result) {
if (!empty($result['exe_weighting']) && intval($result['exe_weighting']) != 0) {
$score = $result['exe_result']/$result['exe_weighting'];
//var_dump($score);
$avg_score +=$score;
}
}
//We asume that all exe_weighting
//$avg_score = show_score( $avg_score / count($user_results) , $result['exe_weighting']);
$avg_score = ($avg_score / count($user_results));
}
//var_dump($avg_score);
return $avg_score;
}
function get_average_score_by_course_by_user($user_id, $course_code, $session_id) {
$user_results = get_all_exercise_results_by_user($user_id, $course_code, $session_id, false);
$avg_score = 0;
if (!empty($user_results)) {
foreach($user_results as $result) {

@ -495,7 +495,7 @@ if ($objExercise->selectAttempts() > 0) {
if ($objExercise->results_disabled == 0 && $origin != 'learnpath') {
//Showing latest attempt according with task BT#1628
$exercise_stat_info = get_all_exercise_results_by_user($user_id, $exerciseId, api_get_course_id(), api_get_session_id());
$exercise_stat_info = get_exercise_results_by_user($user_id, $exerciseId, api_get_course_id(), api_get_session_id());
if (!empty($exercise_stat_info)) {
$max_exe_id = max(array_keys($exercise_stat_info));
@ -532,6 +532,7 @@ if ($objExercise->selectAttempts() > 0) {
}
}
//@todo create a function and move to the exercise class
$limit_time_exists = (($objExercise->start_time != '0000-00-00 00:00:00') || ($objExercise->end_time != '0000-00-00 00:00:00')) ? true : false;
if ($limit_time_exists) {

@ -87,3 +87,24 @@ function array_walk_recursive_limited(&$array, $function, $apply_to_keys_also =
}
$recursive_counter--;
}
function utf8_sort($array) {
$old_locale = setlocale(LC_ALL, null);
$code = api_get_language_isocode();
$locale_list = array($code.'.utf8', 'en.utf8','en_US.utf8','en_GB.utf8');
$try_sort = false;
foreach($locale_list as $locale) {
$my_local = setlocale(LC_COLLATE, $locale);
if ($my_local) {
$try_sort = true;
break;
}
}
if ($try_sort) {
uasort($array, 'strcoll');
}
setlocale(LC_COLLATE, $old_locale);
return $array;
}

@ -683,7 +683,6 @@ function get_all_exercise_results($exercise_id, $course_code, $session_id = 0) {
/**
* Gets all exercise results (NO Exercises in LPs ) from a given exercise id, course, session
* @param int exercise id
* @param string course code
* @param int session id
* @return array with the results
@ -699,7 +698,7 @@ function get_all_exercise_results_by_course($course_code, $session_id = 0, $get_
if ($get_count) {
$select = 'count(*) as count';
}
$sql = "SELECT $select FROM $table_track_exercises WHERE status = '' AND exe_cours_id = '$course_code' AND session_id = $session_id AND orig_lp_id =0 AND orig_lp_item_id = 0 ORDER BY exe_id";
$sql = "SELECT $select FROM $table_track_exercises WHERE status = '' AND exe_cours_id = '$course_code' AND session_id = $session_id AND orig_lp_id = 0 AND orig_lp_item_id = 0 ORDER BY exe_id";
$res = Database::query($sql);
if ($get_count) {
$row = Database::fetch_array($res,'ASSOC');
@ -718,17 +717,51 @@ function get_all_exercise_results_by_course($course_code, $session_id = 0, $get_
}
}
/**
* Gets all exercise results (NO Exercises in LPs) from a given exercise id, course, session
* @param int exercise id
* @param string course code
* @param int session id
* @return array with the results
*
*/
function get_all_exercise_results_by_user($user_id, $course_code, $session_id = 0) {
$table_track_exercises = Database::get_statistic_table(TABLE_STATISTIC_TRACK_E_EXERCICES);
$table_track_attempt = Database::get_statistic_table(TABLE_STATISTIC_TRACK_E_ATTEMPT);
$course_code = Database::escape_string($course_code);
$exercise_id = intval($exercise_id);
$session_id = intval($session_id);
$user_id = intval($user_id);
$sql = "SELECT * FROM $table_track_exercises WHERE status = '' AND exe_user_id = $user_id AND exe_cours_id = '$course_code' AND session_id = $session_id AND orig_lp_id = 0 AND orig_lp_item_id = 0 ORDER by exe_id";
$res = Database::query($sql);
$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']}";
$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;
}
}
//echo '<pre>'; print_r($list);
return $list;
}
/**
* Gets all exercise results (NO Exercises in LPs) from a given exercise id, course, session
* Gets exercise results (NO Exercises in LPs) from a given exercise id, course, session
* @param int exercise id
* @param string course code
* @param int session id
* @return array with the results
*
*/
function get_all_exercise_results_by_user($user_id, $exercise_id, $course_code, $session_id = 0) {
function get_exercise_results_by_user($user_id, $exercise_id, $course_code, $session_id = 0) {
$table_track_exercises = Database::get_statistic_table(TABLE_STATISTIC_TRACK_E_EXERCICES);
$table_track_attempt = Database::get_statistic_table(TABLE_STATISTIC_TRACK_E_ATTEMPT);
$course_code = Database::escape_string($course_code);
@ -770,8 +803,8 @@ function count_exercise_attempts_by_user($user_id, $exercise_id, $course_code, $
$session_id = intval($session_id);
$user_id = intval($user_id);
$sql = "SELECT count(*) as count FROM $TABLETRACK_EXERCICES WHERE status = '' AND exe_user_id = '$user_id' AND exe_cours_id = '$course_code' AND exe_exo_id = '$exercise_id' AND session_id = $session_id AND orig_lp_id =0 AND orig_lp_item_id = 0 ORDER BY exe_id";
$sql = "SELECT count(*) as count FROM $TABLETRACK_EXERCICES
WHERE status = '' AND exe_user_id = '$user_id' AND exe_cours_id = '$course_code' AND exe_exo_id = '$exercise_id' AND session_id = $session_id AND orig_lp_id =0 AND orig_lp_item_id = 0 ORDER BY exe_id";
$res = Database::query($sql);
$result = 0;
if (Database::num_rows($res) > 0 ) {

@ -269,7 +269,9 @@ class Tracking {
// protect data
$month_filter = '';
if ($start < 0) { $start = 0; }
if ($start < 0) {
$start = 0;
}
if (!isset($stop) or ($stop < 0)) {
$stop = api_get_utc_datetime();
}
@ -542,7 +544,9 @@ class Tracking {
*/
public static function get_avg_student_score($student_id, $course_code, $lp_ids = array(), $session_id = null, $return_array = false, $get_only_latest_attempt_results = false) {
$debug = false;
if (empty($lp_ids)) { $debug = false; }
if (empty($lp_ids)) {
$debug = false;
}
if ($debug) echo '<h1>Tracking::get_avg_student_score</h1>';
// get global tables names
@ -598,7 +602,9 @@ class Tracking {
$use_max_score[$row_lp['id']] = $row_lp['use_max_score'];
}
if ($debug) { echo 'Use max score or not list '; var_dump($use_max_score);}
if ($debug) {
echo 'Use max score or not list '; var_dump($use_max_score);
}
// Init local variables that will be used through the calculation
$progress = 0;
@ -1767,7 +1773,8 @@ class Tracking {
$sql_list_view='';
$rs_last_lp_view_id='';
} elseif ($row_type['lp_type']==2) {//lp scorm
} elseif ($row_type['lp_type']==2) {
//lp scorm
$sql = "SELECT id FROM $lp_view_table WHERE user_id = '".intval($user_id)."' and lp_id='".$row_type['id']."'";
$rs_last_lp_view_id = Database::query($sql);
$lp_view_id = intval(Database::result($rs_last_lp_view_id,0,'id'));
@ -1929,8 +1936,11 @@ class Tracking {
*/
function show_user_progress($user_id, $session_id = 0, $extra_params = '', $show_courses = true) {
require_once api_get_path(LIBRARY_PATH).'sessionmanager.lib.php';
require_once api_get_path(SYS_CODE_PATH).'exercice/exercise.class.php';
global $_configuration;
$tbl_course = Database :: get_main_table(TABLE_MAIN_COURSE);
$tbl_session = Database :: get_main_table(TABLE_MAIN_SESSION);
$tbl_course_user = Database :: get_main_table(TABLE_MAIN_COURSE_USER);
$tbl_access_rel_course = Database :: get_main_table(TABLE_MAIN_ACCESS_URL_REL_COURSE);
$tbl_session_course_user = Database :: get_main_table(TABLE_MAIN_SESSION_COURSE_USER);
@ -1940,33 +1950,66 @@ class Tracking {
// get course list
if ($_configuration['multiple_access_urls']) {
$sql = 'SELECT cu.course_code FROM '.$tbl_course_user.' cu INNER JOIN '.$tbl_access_rel_course.' a ON(a.course_code = cu.course_code) WHERE user_id='.$user_id.' AND relation_type<>'.COURSE_RELATION_TYPE_RRHH.' AND access_url_id = '.api_get_current_access_url_id().'';
$sql = 'SELECT cu.course_code as code, title
FROM '.$tbl_course_user.' cu INNER JOIN '.$tbl_access_rel_course.' a ON(a.course_code = cu.course_code) INNER JOIN '.$tbl_course.' c ON( cu.course_code = c.code)
WHERE user_id='.$user_id.' AND relation_type<>'.COURSE_RELATION_TYPE_RRHH.' AND access_url_id = '.api_get_current_access_url_id().' ORDER BY title ';
} else {
$sql = 'SELECT course_code FROM '.$tbl_course_user.' WHERE user_id='.$user_id.' AND relation_type<>'.COURSE_RELATION_TYPE_RRHH.' ';
$sql = 'SELECT course_code as code, title FROM '.$tbl_course_user.' u INNER JOIN '.$tbl_course.' c ON(course_code = c.code)
WHERE u.user_id='.$user_id.' AND relation_type<>'.COURSE_RELATION_TYPE_RRHH.' ORDER BY title ';
}
$rs = Database::query($sql);
$courses = $course_in_session = array();
$courses = $course_in_session = $temp_course_in_session = array();
while($row = Database :: fetch_array($rs)) {
$courses[$row['course_code']] = CourseManager::get_course_information($row['course_code']);
$courses = array();
while($row = Database :: fetch_array($rs, 'ASSOC')) {
$courses[$row['code']] = $row['title'];
}
/*
if (!empty($courses)) {
//sort need to be improved
sort($courses);
}*/
// Get the list of sessions where the user is subscribed as student
if ($_configuration['multiple_access_urls']) {
$sql = 'SELECT DISTINCT cu.course_code, id_session as session_id FROM '.$tbl_session_course_user.' cu INNER JOIN '.$tbl_access_rel_session.' a ON(a.session_id = cu.id_session) WHERE id_user='.$user_id.' AND access_url_id = '.api_get_current_access_url_id().'';
$sql = 'SELECT DISTINCT cu.course_code, id_session as session_id, name FROM '.$tbl_session_course_user.' cu INNER JOIN '.$tbl_access_rel_session.' a ON(a.session_id = cu.id_session) INNER JOIN '.$tbl_session.' s ON(s.id = a.session_id)
WHERE id_user='.$user_id.' AND access_url_id = '.api_get_current_access_url_id().' ORDER BY name ';
} else {
$sql = 'SELECT DISTINCT course_code, id_session as session_id FROM '.$tbl_session_course_user.' WHERE id_user='.$user_id;
$sql = 'SELECT DISTINCT course_code, id_session as session_id, name FROM '.$tbl_session_course_user.' u INNER JOIN '.$tbl_session.' s ON(s.id = u.id_session)
WHERE id_user='.$user_id.' ORDER BY name ';
}
$rs = Database::query($sql);
$simple_session_array = array();
while ($row = Database :: fetch_array($rs)) {
$course_in_session[$row['session_id']][$row['course_code']] = CourseManager::get_course_information($row['course_code']);
$course_info = CourseManager::get_course_information($row['course_code']);
$temp_course_in_session[$row['session_id']]['course_list'][$course_info['id']] = $course_info;
$temp_course_in_session[$row['session_id']]['name'] = $row['name'];
$simple_session_array[$row['session_id']] = $row['name'];
}
foreach($simple_session_array as $my_session_id => $session_name) {
$course_list = $temp_course_in_session[$my_session_id]['course_list'];
$my_course_data = array();
foreach($course_list as $course_data) {
$my_course_data[$course_data['id']] = $course_data['title'];
}
$my_course_data = utf8_sort($my_course_data);
$final_course_data = array();
foreach($my_course_data as $course_id => $value) {
$final_course_data[$course_id] = $course_list[$course_id];
}
$course_in_session[$my_session_id]['course_list'] = $final_course_data;
$course_in_session[$my_session_id]['name'] = $session_name;
}
$html = '';
//Courses list
// Course list
if ($show_courses) {
if (!empty($courses)) {
$html .= Display::tag('h1', Display::return_icon('course.png', get_lang('MyCourses'), array(), 22).' '.get_lang('MyCourses'));
@ -1975,27 +2018,27 @@ class Tracking {
'.Display::tag('th', get_lang('Course'), array('width'=>'300px')).'
'.Display::tag('th', get_lang('Time'), array('class'=>'head')).'
'.Display::tag('th', get_lang('Progress'), array('class'=>'head')).'
'.Display::tag('th', get_lang('Score').Display :: return_icon('info3.gif', get_lang('ScormAndLPTestTotalAverage'), array('align' => 'absmiddle', 'hspace' => '3px')),array('class'=>'head')).'
'.Display::tag('th', get_lang('Score').Display::return_icon('info3.gif', get_lang('ScormAndLPTestTotalAverage'), array('align' => 'absmiddle', 'hspace' => '3px')),array('class'=>'head')).'
'.Display::tag('th', get_lang('LastConnexion'), array('class'=>'head')).'
'.Display::tag('th', get_lang('Details'), array('class'=>'head')).'
</tr>';
foreach ($courses as $enreg) {
foreach ($courses as $course_code => $course_title) {
$weighting = 0;
$total_time_login = Tracking :: get_time_spent_on_the_course($user_id, $enreg['code']);
$total_time_login = Tracking :: get_time_spent_on_the_course($user_id, $course_code);
$time = api_time_to_hms($total_time_login);
$progress = Tracking :: get_avg_student_progress($user_id, $enreg['code']);
$percentage_score = Tracking :: get_avg_student_score($user_id, $enreg['code'], array());
$last_connection = Tracking :: get_last_connection_date_on_the_course($user_id, $enreg['code']);
$progress = Tracking :: get_avg_student_progress($user_id, $course_code);
$percentage_score = Tracking :: get_avg_student_score($user_id, $course_code, array());
$last_connection = Tracking :: get_last_connection_date_on_the_course($user_id, $course_code);
if ($enreg['code'] == $_GET['course'] && empty($_GET['session_id'])) {
if ($course_code == $_GET['course'] && empty($_GET['session_id'])) {
$html .= '<tr class="row_odd" style="background-color:#FBF09D">';
} else {
$html .= '<tr class="row_even">';
}
$url = api_get_course_url($enreg['code'], $session_id);
$course_url = Display::url($enreg['title'], $url, array('target'=>SESSION_LINK_TARGET));
$url = api_get_course_url($course_code, $session_id);
$course_url = Display::url($course_title, $url, array('target'=>SESSION_LINK_TARGET));
$html .= '<td>'.$course_url.'</td>';
$html .= '<td align="center">'.$time.'</td>';
@ -2010,11 +2053,11 @@ class Tracking {
$html .= '</td>';
$html .= '<td align="center">'.$last_connection.'</td>';
$html .= '<td align="center">';
if ($enreg['code'] == $_GET['course'] && empty($_GET['session_id'])) {
if ($course_code == $_GET['course'] && empty($_GET['session_id'])) {
$html .= '<a href="#">';
$html .= Display::return_icon('2rightarrow_na.gif', get_lang('Details'));
} else {
$html .= '<a href="'.api_get_self().'?course='.$enreg['code'].$extra_params.'">';
$html .= '<a href="'.api_get_self().'?course='.$course_code.$extra_params.'">';
$html .= Display::return_icon('2rightarrow.gif', get_lang('Details'));
}
$html .= '</a>';
@ -2024,25 +2067,44 @@ class Tracking {
}
}
//Session
// Session list
if (!empty($course_in_session)) {
$html .= Display::tag('h1',Display::return_icon('session.png', get_lang('Sessions'), array(), 22).' '.get_lang('Sessions'));
$main_session_graph = '';
$exercise_graph_list = array();
$exercise_graph_name_list = array();
if (!isset($_GET['session_id']) && !isset($_GET['course'])) {
//Load graphics only when calling to an specific session
$session_graph = array();
foreach ($course_in_session as $my_session_id=>$course_list) {
$session_name = api_get_session_name($my_session_id);
$user_count = count(SessionManager::get_users_by_session($session_id));
$all_exercise_graph_name_list = array();
$all_user_results = array();
$all_exercise_graph_list = array();
$all_exercise_start_time = array();
foreach ($course_in_session as $my_session_id => $session_data) {
$course_list = $session_data['course_list'];
$session_name = $session_data['name'];
$user_count = count(SessionManager::get_users_by_session($my_session_id));
$exercise_graph_name_list = array();
$user_results = array();
$exercise_graph_list = array();
foreach ($course_list as $course_data) {
$exercise_list = get_all_exercises($course_data, $my_session_id);
foreach($exercise_list as $exercise_data) {
if (!empty($exercise_data['start_time']) && $exercise_data['start_time'] != '0000-00-00 00:00:00') {
//echo $session_name.' - '.$course_data['title']." \n ".$exercise_data['title'].'<br />';
$exercise_graph_list[] = intval(get_best_average_score_by_exercise($exercise_data['id'], $course_data['code'], $my_session_id, $user_count));
$exercise_obj = New Exercise($course_data['id']);
$exercise_obj->read($exercise_data['id']);
if ($exercise_obj->is_visible()) {
$best_average = intval(get_best_average_score_by_exercise($exercise_data['id'], $course_data['code'], $my_session_id, $user_count));
$exercise_graph_list[] = $best_average;
$all_exercise_graph_list[] = $best_average;
$user_result_data = get_best_attempt_by_user(api_get_user_id(), $exercise_data['id'], $course_data['code'], $my_session_id);
$score = 0;
if (!empty($user_result_data['exe_weighting']) && intval($user_result_data['exe_weighting']) != 0) {
@ -2050,95 +2112,162 @@ class Tracking {
}
//$user_results[] = 100;
$user_results[] = $score;
$time = api_strtotime($exercise_data['start_time']) ? api_strtotime($exercise_data['start_time']) : 0;
$all_exercise_start_time[] = $time ;
$all_user_results[] = $score;
if (count($exercise_list)<=10) {
$exercise_graph_name_list[]= cut($course_data['title'], 20)." \n ".cut($exercise_data['title'], 20);
$title = cut($course_data['title'], 30)." \n ".cut($exercise_data['title'], 30);
$exercise_graph_name_list[]= $title;
$all_exercise_graph_name_list[] = $title;
} else {
// if there are more than 10 results, space becomes difficult to find, so only show the title of the exercise, not the tool
$exercise_graph_name_list[]= cut($exercise_data['title'], 20);
$title = cut($exercise_data['title'], 30);
$exercise_graph_name_list[]= $title;
$all_exercise_graph_name_list[]= $title;
}
}
}
}
//Graph per session
if (!empty($user_results) && !empty($exercise_graph_list)) {
$session_graph[$my_session_id] = self::generate_session_exercise_graph($exercise_graph_name_list, $user_results, $exercise_graph_list);
//$session_graph[$my_session_id] = self::generate_session_exercise_graph($exercise_graph_name_list, $user_results, $exercise_graph_list);
}
}
//Complete graph
if (!empty($all_user_results) && !empty($all_exercise_graph_list)) {
asort($all_exercise_start_time);
//Fix exams order
$final_all_exercise_graph_name_list = array();
$final_all_user_results = array();
$final_all_exercise_graph_list = array();
foreach($all_exercise_start_time as $key => $time) {
$label_time = '';
if (!empty($time)) {
$label_time = date('d-m-y', $time);
//$label_time = api_format_date($time, DATE_FORMAT_NUMBER);
}
$final_all_exercise_graph_name_list[] = $all_exercise_graph_name_list[$key].' '.$label_time;
$final_all_user_results[] = $all_user_results[$key];
$final_all_exercise_graph_list[] = $all_exercise_graph_list[$key];
}
//var_dump($final_all_exercise_graph_name_list, $final_all_user_results, $final_all_exercise_graph_list);
$main_session_graph = self::generate_session_exercise_graph($final_all_exercise_graph_name_list, $final_all_user_results, $final_all_exercise_graph_list);
}
}
$html .= Display::tag('h1',Display::return_icon('session.png', get_lang('Sessions'), array(), 22).' '.get_lang('Sessions'));
$html .= '<table class="data_table" width="100%">';
//'.Display::tag('th', get_lang('DoneExercises'), array('class'=>'head')).'
$html .= '<tr>
'.Display::tag('th', get_lang('Session'), array('width'=>'300px')).'
'.Display::tag('th', get_lang('PublishedExercises'), array('width'=>'300px')).'
'.Display::tag('th', get_lang('DoneExercises'), array('class'=>'head')).'
'.Display::tag('th', get_lang('NewExercises'), array('class'=>'head')).'
'.Display::tag('th', get_lang('AverageExerciseResult'), array('class'=>'head')).'
'.Display::tag('th', get_lang('Details'), array('class'=>'head')).'
</tr>';
foreach ($course_in_session as $key => $course_list) {
foreach ($course_in_session as $my_session_id => $session_data) {
$course_list = $session_data['course_list'];
$session_name = $session_data['name'];
if (isset($session_id) && !empty($session_id)) {
if ($session_id != $key) {
if ($session_id != $my_session_id) {
continue;
}
}
$all_exercises = 0;
$all_unanswered_exercises_by_user = 0;
$all_done_exercise = 0;
$all_average = 0;
$stats_array = array();
foreach ($course_list as $enreg) {
foreach($course_list as $course_data) {
//All exercises in the course @todo change for a real count
$exercises = count(get_all_exercises($enreg, $key));
$exercises = get_all_exercises($course_data, $my_session_id);
$count_exercises = 0;
if (!empty($exercises)) {
$count_exercises = count($exercises);
}
//Count of user results
//$done_exercises = get_best_exercise_results_by_course($enreg['code'], $key);
$done_exercises = get_count_exercises_attempted_by_course($enreg['code'], $key);
//$done_exercises = get_count_exercises_attempted_by_course($course_data['code'], $my_session_id);
$done_exercises = null;
$answered_exercises = 0;
if (!empty($exercises)) {
foreach($exercises as $exercise_item) {
$attempts = count_exercise_attempts_by_user(api_get_user_id(), $exercise_item['id'], $course_data['code'], $my_session_id);
if ($attempts > 1) {
$answered_exercises++;
}
}
}
//Average
$average = get_average_score_by_course($enreg['code'], $key);
$average = get_average_score_by_course($course_data['code'], $my_session_id);
$all_exercises += $count_exercises;
$all_exercises += $exercises;
$all_done_exercise += $done_exercises;
$all_unanswered_exercises_by_user += $count_exercises - $answered_exercises;
//$all_done_exercise += $done_exercises;
$all_average += $average;
$stats_array[$enreg['code']] = array('exercises'=>$exercises, 'done_exercises'=>$done_exercises, 'average'=>$average);
//$stats_array[$course_data['code']] = array('exercises'=>$count_exercises, 'unanswered_exercises_by_user'=>$answered_exercises,'done_exercises'=>$done_exercises, 'average'=>$average);
}
$all_average = $all_average / count($course_list);
if (isset($_GET['session_id']) && $key == $_GET['session_id']) {
if (isset($_GET['session_id']) && $my_session_id == $_GET['session_id']) {
$html .= '<tr style="background-color:#FBF09D">';
} else {
$html .= '<tr>';
}
$url = api_get_path(WEB_CODE_PATH)."session/?session_id={$my_session_id}";
$html .= Display::tag('td', api_get_session_name($key));
$html .= Display::tag('td', Display::url($session_name, $url, array('target'=>SESSION_LINK_TARGET)));
$html .= Display::tag('td', $all_exercises);
$html .= Display::tag('td', $all_done_exercise);
$html .= Display::tag('td', $all_unanswered_exercises_by_user);
//$html .= Display::tag('td', $all_done_exercise);
$html .= Display::tag('td', convert_to_percentage($all_average));
if (isset($_GET['session_id']) && $key == $_GET['session_id']) {
$icon = Display::url(Display::return_icon('2rightarrow_na.gif', get_lang('Details')), '?session_id='.$key);
if (isset($_GET['session_id']) && $my_session_id == $_GET['session_id']) {
$icon = Display::url(Display::return_icon('2rightarrow_na.gif', get_lang('Details')), '?session_id='.$my_session_id);
} else {
$icon = Display::url(Display::return_icon('2rightarrow.gif', get_lang('Details')), '?session_id='.$key);
$icon = Display::url(Display::return_icon('2rightarrow.gif', get_lang('Details')), '?session_id='.$my_session_id);
}
$html .= Display::tag('td', $icon);
$html .= '</tr>';
}
$html .='</table><br />';
$html .= '</table><br />';
$html .= Display::div($main_session_graph, array('id'=>'session_graph','class'=>'chart-session', 'style'=>'position:relative; text-align: center;') );
//Checking selected session
if (isset($_GET['session_id'])) {
$key = intval($_GET['session_id']);
$html .= Display::tag('h2',api_get_session_name($key).' - '.get_lang('CourseList'));
$session_id_from_get = intval($_GET['session_id']);
$session_data = $course_in_session[$session_id_from_get];
$course_list = $session_data['course_list'];
$course_list = $course_in_session[$key];
$html .= Display::tag('h2',$session_data['name'].' - '.get_lang('CourseList'));
$html .= '<table class="data_table" width="100%">';
//'.Display::tag('th', get_lang('DoneExercises'), array('class'=>'head')).'
$html .= '
<tr>
<th width="300px">'.get_lang('Course').'</th>
'.Display::tag('th', get_lang('PublishedExercises'), array('class'=>'head')).'
'.Display::tag('th', get_lang('DoneExercises'), array('class'=>'head')).'
'.Display::tag('th', get_lang('NewExercises'), array('class'=>'head')).'
'.Display::tag('th', get_lang('MyAverage'), array('class'=>'head')).'
'.Display::tag('th', get_lang('AverageExerciseResult'), array('class'=>'head')).'
'.Display::tag('th', get_lang('Time') , array('class'=>'head')).'
'.Display::tag('th', get_lang('LPProgress') , array('class'=>'head')).'
@ -2147,38 +2276,64 @@ class Tracking {
'.Display::tag('th', get_lang('Details'), array('class'=>'head')).'
</tr>';
foreach ($course_list as $enreg) {
foreach ($course_list as $course_data) {
$course_code = $course_data['code'];
$course_title = $course_data['title'];
//All exercises in the course @todo change for a real count
$exercises = count(get_all_exercises($enreg, $key));
$exercises = get_all_exercises($course_data, $session_id_from_get);
$count_exercises = 0;
if (!empty($exercises)) {
$count_exercises = count($exercises);
}
//Count of user results
//$done_exercises = get_best_exercise_results_by_course($enreg['code'], $key);
$done_exercises = get_count_exercises_attempted_by_course($enreg['code'], $key);
//$done_exercises = get_best_exercise_results_by_course($course_code, $session_id_from_get);
//From course exercises NOT from LP exercises!!!
//$done_exercises = get_count_exercises_attempted_by_course($course_code, $session_id_from_get);
$answered_exercises = 0;
foreach($exercises as $exercise_item) {
$attempts = count_exercise_attempts_by_user(api_get_user_id(), $exercise_item['id'], $course_code, $session_id_from_get);
if ($attempts > 1) {
$answered_exercises++;
}
}
$unanswered_exercises = $count_exercises - $answered_exercises;
//Average
$average = get_average_score_by_course($enreg['code'], $key);
$average = get_average_score_by_course($course_code, $session_id_from_get);
$my_average = get_average_score_by_course_by_user(api_get_user_id(), $course_code, $session_id_from_get);
$stats_array[$enreg['code']] = array('exercises'=>$exercises, 'done_exercises'=>$done_exercises, 'average'=>$average);
$stats_array[$course_code] = array( 'exercises' => $count_exercises,
'unanswered_exercises_by_user' => $unanswered_exercises,
'done_exercises' => $done_exercises,
'average' => $average,
'my_average' => $my_average);
$weighting = 0;
$last_connection = Tracking :: get_last_connection_date_on_the_course($user_id, $enreg['code'], $key);
$progress = Tracking :: get_avg_student_progress($user_id, $enreg['code'],array(), $key);
$total_time_login = Tracking :: get_time_spent_on_the_course($user_id, $enreg['code'], $key);
$last_connection = Tracking :: get_last_connection_date_on_the_course($user_id, $course_code, $session_id_from_get);
$progress = Tracking :: get_avg_student_progress($user_id, $course_code,array(), $session_id_from_get);
$total_time_login = Tracking :: get_time_spent_on_the_course($user_id, $course_code, $session_id_from_get);
$time = api_time_to_hms($total_time_login);
$percentage_score = Tracking :: get_avg_student_score($user_id, $enreg['code'], array(), $key);
$percentage_score = Tracking :: get_avg_student_score($user_id, $course_code, array(), $session_id_from_get);
if ($enreg['code'] == $_GET['course'] && $_GET['session_id'] == $key) {
if ($course_code == $_GET['course'] && $_GET['session_id'] == $session_id_from_get) {
$html .= '<tr class="row_odd" style="background-color:#FBF09D" >';
} else {
$html .= '<tr class="row_even">';
}
$url = api_get_course_url($enreg['code'], $key);
$course_url = Display::url($enreg['title'], $url, array('target'=>SESSION_LINK_TARGET));
$url = api_get_course_url($course_code, $session_id_from_get);
$course_url = Display::url($course_title, $url, array('target'=>SESSION_LINK_TARGET));
$html .= Display::tag('td', $course_url);
$html .= Display::tag('td', $stats_array[$enreg['code']]['exercises']);
$html .= Display::tag('td', $stats_array[$enreg['code']]['done_exercises']);
$html .= Display::tag('td', convert_to_percentage($stats_array[$enreg['code']]['average']));
$html .= Display::tag('td', $stats_array[$course_code]['exercises']);
$html .= Display::tag('td', $stats_array[$course_code]['unanswered_exercises_by_user']);
//$html .= Display::tag('td', $stats_array[$course_code]['done_exercises']);
$html .= Display::tag('td', convert_to_percentage($stats_array[$course_code]['my_average']));
$html .= Display::tag('td', $stats_array[$course_code]['average'] == 0 ? '-' : '('.convert_to_percentage($stats_array[$course_code]['average']).')');
$html .= Display::tag('td', $time, array('align'=>'center'));
if (is_numeric($progress)) {
@ -2186,20 +2341,22 @@ class Tracking {
} else {
$progress = '0%';
}
//Progress
$html .= Display::tag('td', $progress, array('align'=>'center'));
if (is_numeric($percentage_score)) {
$percentage_score = $percentage_score.'%';
} else {
$percentage_score = '0%';
}
//Score
$html .= Display::tag('td', $percentage_score, array('align'=>'center'));
$html .= Display::tag('td', $last_connection, array('align'=>'center'));
if ($enreg['code'] == $_GET['course'] && $_GET['session_id'] == $key) {
if ($course_code == $_GET['course'] && $_GET['session_id'] == $session_id_from_get) {
$details = '<a href="#">';
$details .=Display::return_icon('2rightarrow_na.gif', get_lang('Details'));
} else {
$details = '<a href="'.api_get_self().'?course='.$enreg['code'].'&session_id='.$key.$extra_params.'">';
$details = '<a href="'.api_get_self().'?course='.$course_code.'&session_id='.$session_id_from_get.$extra_params.'">';
$details .=Display::return_icon('2rightarrow.gif', get_lang('Details'));
}
$details .= '</a>';
@ -2208,9 +2365,10 @@ class Tracking {
}
$html .= '</table>';
if (!empty($session_graph[$key])) {
$html .= Display::div($session_graph[$my_session_id], array('id'=>'session_graph_'.$key,'class'=>'chart-session', 'style'=>'position:relative; text-align: center;') );
if (!empty($session_graph[$session_id_from_get])) {
//$html .= Display::div($session_graph[$session_id_from_get], array('id'=>'session_graph','class'=>'chart-session', 'style'=>'position:relative; text-align: center;') );
}
}
}
if (!empty($html)) {
@ -2249,60 +2407,8 @@ class Tracking {
$session_name = api_get_session_name($session_id);
$html .= Display::tag('h2', $course_info['title']);
$html .='<table class="data_table" width="100%">';
$html .= Display::tag('th', get_lang('Learnpaths'), array('class'=>'head', 'style'=>'color:#000'));
$html .= Display::tag('th', get_lang('Time'), array('class'=>'head', 'style'=>'color:#000'));
$html .= Display::tag('th', get_lang('Progress'), array('class'=>'head', 'style'=>'color:#000'));
$html .= Display::tag('th', get_lang('Score'), array('class'=>'head', 'style'=>'color:#000'));
$html .= Display::tag('th', get_lang('LastConnexion'), array('class'=>'head', 'style'=>'color:#000'));
$html .= '</tr>';
if (empty($session_id)) {
$sql_learnpath = "SELECT lp.name,lp.id FROM ".$tbl_course_lp." AS lp WHERE session_id = 0 ORDER BY lp.display_order";
} else {
$sql_learnpath = "SELECT lp.name,lp.id FROM ".$tbl_course_lp." AS lp ORDER BY lp.display_order";
}
$result_learnpath = Database::query($sql_learnpath);
if (Database::num_rows($result_learnpath) > 0) {
while($learnpath = Database::fetch_array($result_learnpath)) {
$progress = Tracking::get_avg_student_progress($user_id, $course, array($learnpath['id']), $session_id);
$last_connection_in_lp = Tracking::get_last_connection_time_in_lp($user_id, $course, $learnpath['id'], $session_id);
$time_spent_in_lp = Tracking::get_time_spent_in_lp($user_id, $course, array($learnpath['id']), $session_id);
$percentage_score = Tracking::get_avg_student_score($user_id, $course, array($learnpath['id']), $session_id);
if (is_numeric($percentage_score)) {
$percentage_score = $percentage_score.'%';
} else {
$percentage_score = '0%';
}
$time_spent_in_lp = api_time_to_hms($time_spent_in_lp);
$html .= '<tr class="row_even">';
$html .= Display::tag('td', $learnpath['name']);
$html .= Display::tag('td', $time_spent_in_lp, array('align'=>'center'));
if (is_numeric($progress)) {
$progress = $progress.'%';
}
$html .= Display::tag('td', $progress, array('align'=>'center'));
$html .= Display::tag('td', $percentage_score);
$last_connection = '-';
if (!empty($last_connection_in_lp)) {
$last_connection = api_convert_and_format_date($last_connection_in_lp, DATE_TIME_FORMAT_LONG);
}
$html .= Display::tag('td', $last_connection, array('align'=>'center','width'=>'180px'));
$html .= "</tr>";
}
} else {
$html .= '<tr>
<td colspan="4" align="center">
'.get_lang('NoLearnpath').'
</td>
</tr>';
}
$html .='</table><br />
<table class="data_table" width="100%">';
$html .= '<table class="data_table" width="100%">';
// This code was commented on purpose see BT#924
@ -2406,6 +2512,66 @@ class Tracking {
$html .= '<tr><td colspan="5" align="center">'.get_lang('NoEx').'</td></tr>';
}
$html .= '</table>';
//LP table results
$html .='<table class="data_table" width="100%">';
$html .= Display::tag('th', get_lang('Learnpaths'), array('class'=>'head', 'style'=>'color:#000'));
$html .= Display::tag('th', get_lang('Time'), array('class'=>'head', 'style'=>'color:#000'));
$html .= Display::tag('th', get_lang('Progress'), array('class'=>'head', 'style'=>'color:#000'));
$html .= Display::tag('th', get_lang('Score'), array('class'=>'head', 'style'=>'color:#000'));
$html .= Display::tag('th', get_lang('LastConnexion'), array('class'=>'head', 'style'=>'color:#000'));
$html .= '</tr>';
if (empty($session_id)) {
$sql_learnpath = "SELECT lp.name,lp.id FROM ".$tbl_course_lp." AS lp WHERE session_id = 0 ORDER BY lp.display_order";
} else {
$sql_learnpath = "SELECT lp.name,lp.id FROM ".$tbl_course_lp." AS lp ORDER BY lp.display_order";
}
$result_learnpath = Database::query($sql_learnpath);
if (Database::num_rows($result_learnpath) > 0) {
while($learnpath = Database::fetch_array($result_learnpath)) {
$progress = Tracking::get_avg_student_progress($user_id, $course, array($learnpath['id']), $session_id);
$last_connection_in_lp = Tracking::get_last_connection_time_in_lp($user_id, $course, $learnpath['id'], $session_id);
$time_spent_in_lp = Tracking::get_time_spent_in_lp($user_id, $course, array($learnpath['id']), $session_id);
$percentage_score = Tracking::get_avg_student_score($user_id, $course, array($learnpath['id']), $session_id);
if (is_numeric($percentage_score)) {
$percentage_score = $percentage_score.'%';
} else {
$percentage_score = '0%';
}
$time_spent_in_lp = api_time_to_hms($time_spent_in_lp);
$html .= '<tr class="row_even">';
$url = api_get_path(WEB_CODE_PATH)."newscorm/lp_controller.php?cidReq={$course_code}&id_session=$session_id&lp_id={$learnpath['id']}&action=view";
$html .= Display::tag('td', Display::url($learnpath['name'], $url, array('target'=>SESSION_LINK_TARGET)));
$html .= Display::tag('td', $time_spent_in_lp, array('align'=>'center'));
if (is_numeric($progress)) {
$progress = $progress.'%';
}
$html .= Display::tag('td', $progress, array('align'=>'center'));
$html .= Display::tag('td', $percentage_score);
$last_connection = '-';
if (!empty($last_connection_in_lp)) {
$last_connection = api_convert_and_format_date($last_connection_in_lp, DATE_TIME_FORMAT_LONG);
}
$html .= Display::tag('td', $last_connection, array('align'=>'center','width'=>'180px'));
$html .= "</tr>";
}
} else {
$html .= '<tr>
<td colspan="4" align="center">
'.get_lang('NoLearnpath').'
</td>
</tr>';
}
$html .='</table>';
}
if (!empty($html)) {
$html = Display::div($html, array('class'=>'rounded_div', 'style'=>'position:relative; float:none; width:95%'));
@ -2439,20 +2605,22 @@ class Tracking {
$data_set->SetSerieName(get_lang('AverageScore'),"Serie1");
$data_set->SetSerieName(get_lang('MyResults'), "Serie2");
//$data_set->SetXAxisName(get_lang("Exercises"));
$data_set->SetYAxisName(get_lang("Percentage"));
//$data_set->SetYAxisName(get_lang("Percentage"));
$data_set->SetYAxisUnit("%");
// Initialise the graph
$main_width = 820;
$main_height = 440;
$y_label_angle = 35;
$main_width = 860;
$main_height = 500;
$y_label_angle = 50;
$data_set->RemoveSerie("Serie3");
$graph = new pChart($main_width, $main_height);
//$graph->setFixedScale(0,100);
//See 3.2 BT#2797
$graph->setFixedScale(0,100);
$graph->setFontProperties(api_get_path(LIBRARY_PATH).'pchart/fonts/tahoma.ttf',8);
$graph->setGraphArea(75,50,$main_width-140, $main_height-120);
$graph->setGraphArea(65,50,$main_width-20, $main_height-140);
$graph->drawFilledRoundedRectangle(7,7,$main_width-7,$main_height-7,5,240,240,240);
$graph->drawRoundedRectangle(5,5,$main_width-5,$main_height -5,5,230,230,230);
$graph->drawGraphArea(255,255,255,TRUE);
@ -2466,21 +2634,21 @@ class Tracking {
$graph->drawTreshold(0,143,55,72,TRUE,TRUE);
// Draw the cubic curve graph
//$graph->drawCubicCurve($data_set->GetData(),$data_set->GetDataDescription());
$graph->drawLineGraph($data_set->GetData(),$data_set->GetDataDescription());
$graph->drawPlotGraph($data_set->GetData(),$data_set->GetDataDescription(),1,1,230,255,255);
// Finish the graph
$graph->setFontProperties(api_get_path(LIBRARY_PATH).'pchart/fonts/tahoma.ttf',8);
$graph->drawLegend($main_width - 130,50,$data_set->GetDataDescription(),255,255,255);
$graph->setFontProperties(api_get_path(LIBRARY_PATH).'pchart/fonts/tahoma.ttf',10);
$graph->drawLegend($main_width - 150,70,$data_set->GetDataDescription(),255,255,255);
$graph->setFontProperties(api_get_path(LIBRARY_PATH).'pchart/fonts/tahoma.ttf',11);
$graph->drawTitle(50, 30, get_lang('ExercisesInTimeProgressChart'), 50,50,50,$main_width-110, true);
// $main_graph = new pChart($main_width,$main_height);
$graph_id = 'generate_session_exercise_graph'.Security::remove_XSS($_GET['course']).'-'.intval($_GET['session_id']).'-'.api_get_user_id();
if ($cache->IsInCache($graph_id, $data_set->GetData())) {
//if (0) {
//if ($cache->IsInCache($graph_id, $data_set->GetData())) {
if (0) {
//if we already created the img
//echo 'in cache';
$img_file = $cache->GetHash($graph_id,$data_set->GetData());
@ -2831,7 +2999,9 @@ class TrackingCourseLog {
$sql .= " AND tool IN ('document', 'learnpath', 'quiz', 'glossary', 'link', 'course_description', 'announcement', 'thematic', 'thematic_advance', 'thematic_plan')";
if ($column == 0) { $column = '0'; }
if ($column == 0) {
$column = '0';
}
if ($column != '' && $direction != '') {
if ($column != 2 && $column != 4) {
$sql .= " ORDER BY col$column $direction";
@ -3281,7 +3451,9 @@ class TrackingCourseLog {
$avg_student_score = Tracking::get_avg_student_score($user['user_id'], $course_code, array(), $session_id);
$avg_student_progress = Tracking::get_avg_student_progress($user['user_id'], $course_code, array(), $session_id);
if (empty($avg_student_progress)) { $avg_student_progress=0; }
if (empty($avg_student_progress)) {
$avg_student_progress=0;
}
$user['average_progress'] = $avg_student_progress.'%';
if (is_numeric($avg_student_score)) {
@ -3485,9 +3657,11 @@ class TrackingUserLog {
<tr>
<td class="content"><?php echo $title; ?></td>
<td class="content" align="center"><?php echo $display_date; ?></td>
<td class="content" align="center"><?php echo $hpresults[$i][1]; ?> / <?php echo $hpresults[$i][2]; ?></td>
<td class="content" align="center"><?php echo $hpresults[$i][1]; ?> / <?php echo $hpresults[$i][2]; ?>
</td>
</tr>
<?php }
<?php }
} else {
$NoHPTestRes = 1;
}

@ -110,7 +110,7 @@ if (!empty($new_session_list)) {
$exercise->read($exercise_item['id']);
//$exercise_course_list[$exercise_item['id']] = $exercise;
//Reading all Exercise results by user, exercise_id, code, and session
$user_results = get_all_exercise_results_by_user(api_get_user_id(), $exercise_item['id'], $my_course['code'], $my_session_id);
$user_results = get_exercise_results_by_user(api_get_user_id(), $exercise_item['id'], $my_course['code'], $my_session_id);
$course['exercises'][$exercise_item['id']]['data']['exercise_data'] = $exercise;
$course['exercises'][$exercise_item['id']]['data']['results'] = $user_results;
}

Loading…
Cancel
Save