From 11029d6c05a45c7f0d5ce88d5ff02edb5679621a Mon Sep 17 00:00:00 2001 From: Julio Montoya Date: Mon, 20 Dec 2010 12:42:21 +0100 Subject: [PATCH] Improving exercise result paginations see BT#1901 --- main/exercice/exercice.php | 568 +++++++++++++++++++++---------------- 1 file changed, 330 insertions(+), 238 deletions(-) diff --git a/main/exercice/exercice.php b/main/exercice/exercice.php index 5bdc79876b..36633b554b 100755 --- a/main/exercice/exercice.php +++ b/main/exercice/exercice.php @@ -1028,265 +1028,357 @@ echo ''; // if tracking is enabled if ($_configuration['tracking_enabled'] && ($show == 'result')) { - - $session_id_and = ' AND te.session_id = ' . api_get_session_id() . ' '; - if ($is_allowedToEdit || $is_tutor) { - $user_id_and = ''; - if (!empty ($_POST['filter_by_user'])) { - if ($_POST['filter_by_user'] == 'all') { - $user_id_and = " AND user_id like '%'"; - } else { - $user_id_and = " AND user_id = '" . Database :: escape_string((int) $_POST['filter_by_user']) . "' "; - } - } - if ($_GET['gradebook'] == 'view') { - $exercise_where_query = 'te.exe_exo_id =ce.id AND '; + + $parameters=array('cidReq'=>Security::remove_XSS($_GET['cidReq']),'show'=>Security::remove_XSS($_GET['show']),'filter' => Security::remove_XSS($_GET['filter']),'gradebook' =>Security::remove_XSS($_GET['gradebook'])); + $table = new SortableTable('quiz_results', 'get_count_exam_results', 'get_exam_results_data'); + $table->set_additional_parameters($parameters); + $secuence = 2; + + if ($is_allowedToEdit || $is_tutor) { + $secuence = 0; + if (api_is_western_name_order()) { + $table->set_header(0, get_lang('FirstName')); + $table->set_header(1, get_lang('LastName')); + } else { + $table->set_header(0, get_lang('LastName')); + $table->set_header(1, get_lang('FirstName')); } - + } + + $table->set_header(-$secuence + 2, get_lang('Exercice')); + $table->set_header(-$secuence + 3, get_lang('Duration'),false); + $table->set_header(-$secuence + 4, get_lang('Date')); + $table->set_header(-$secuence + 5, get_lang('Result'),false); + $table->set_header(-$secuence + 6, (($is_allowedToEdit||$is_tutor) ? get_lang('CorrectTest') : get_lang('ViewTest')), false); + $table->display(); + +} +if ($origin != 'learnpath') { //so we are not in learnpath tool + Display :: display_footer(); +} else { +?> + +".COURSE_RELATION_TYPE_RRHH." AND te.exe_exo_id = ce.id AND te.status != 'incomplete' AND cuser.user_id=te.exe_user_id AND te.exe_cours_id='" . Database :: escape_string($_cid) . "' - $user_id_and $session_id_and AND ce.active <>-1 AND orig_lp_id = 0 AND orig_lp_item_id = 0 - AND cuser.course_code=te.exe_cours_id ORDER BY userpart2, te.exe_cours_id ASC, ce.title ASC, te.exe_date DESC";*/ - - $sql="SELECT ".(api_is_western_name_order() ? "firstname as userpart1, lastname userpart2" : "lastname as userpart1, firstname as userpart2").", ce.title as extitle, te.exe_result as exresult , te.exe_weighting as exweight, - te.exe_date as exdate, te.exe_id as exid, email as exemail, te.start_date as exstart, steps_counter as exstep, exe_user_id as excruid,te.exe_duration as exduration + /*$sql="SELECT ".(api_is_western_name_order() ? "firstname as userpart1, lastname col1" : "lastname as userpart1, firstname as col1").", ce.title as extitle, te.exe_result as exresult , + te.exe_weighting as exweight, te.exe_date as exdate, te.exe_id as exid, email as exemail, te.start_date as exstart, steps_counter as exstep,cuser.user_id as excruid,te.exe_duration as exduration + FROM $TBL_EXERCICES AS ce , $TBL_TRACK_EXERCICES AS te, $TBL_USER AS user,$tbl_course_rel_user AS cuser + WHERE user.user_id=cuser.user_id AND cuser.relation_type<>".COURSE_RELATION_TYPE_RRHH." AND te.exe_exo_id = ce.id AND te.status != 'incomplete' AND cuser.user_id=te.exe_user_id AND te.exe_cours_id='" . Database :: escape_string($_cid) . "' + $user_id_and $session_id_and AND ce.active <>-1 AND orig_lp_id = 0 AND orig_lp_item_id = 0 + AND cuser.course_code=te.exe_cours_id ORDER BY col1, te.exe_cours_id ASC, ce.title ASC, te.exe_date DESC";*/ + + $sql="SELECT count(*) as count FROM $TBL_EXERCICES AS ce INNER JOIN $TBL_TRACK_EXERCICES AS te ON (te.exe_exo_id = ce.id) INNER JOIN $TBL_USER AS user ON (user.user_id = exe_user_id) WHERE te.status != 'incomplete' AND te.exe_cours_id='" . Database :: escape_string($_cid) . "' $user_id_and $session_id_and AND ce.active <>-1 AND orig_lp_id = 0 AND orig_lp_item_id = 0"; - - $hpsql="SELECT ".(api_is_western_name_order() ? "firstname as userpart1, lastname userpart2" : "lastname as userpart1, firstname as userpart2").", tth.exe_name, tth.exe_result , tth.exe_weighting, tth.exe_date - FROM $TBL_TRACK_HOTPOTATOES tth, $TBL_USER tu - WHERE tu.user_id=tth.exe_user_id AND tth.exe_cours_id = '" . Database :: escape_string($_cid) . " $user_id_and ' - ORDER BY tth.exe_cours_id ASC, tth.exe_date DESC"; - - - } else { - // get only this user's results - $user_id_and = ' AND te.exe_user_id = ' . api_get_user_id() . ' '; - - /*$sql="SELECT ".(api_is_western_name_order() ? "firstname as userpart1, lastname userpart2" : "lastname as userpart1, firstname as userpart2").", ce.title as extitle, te.exe_result as exresult, " . - "te.exe_weighting as exweight, te.exe_date as exdate, te.exe_id as exid, email as exemail, " . - "te.start_date as exstart, steps_counter as exstep, cuser.user_id as excruid, te.exe_duration as exduration, ce.results_disabled as exdisabled - FROM $TBL_EXERCICES AS ce , $TBL_TRACK_EXERCICES AS te, $TBL_USER AS user,$tbl_course_rel_user AS cuser - WHERE user.user_id=cuser.user_id AND te.exe_exo_id = ce.id AND te.status != 'incomplete' AND cuser.user_id=te.exe_user_id - AND te.exe_cours_id='" . Database :: escape_string($_cid) . "' - AND cuser.relation_type<>".COURSE_RELATION_TYPE_RRHH." $user_id_and $session_id_and AND ce.active <>-1 AND" . - " orig_lp_id = 0 AND orig_lp_item_id = 0 AND cuser.course_code=te.exe_cours_id ORDER BY userpart2, te.exe_cours_id ASC, ce.title ASC, te.exe_date DESC";*/ - - $sql="SELECT ".(api_is_western_name_order() ? "firstname as userpart1, lastname userpart2" : "lastname as userpart1, firstname as userpart2").", ce.title as extitle, te.exe_result as exresult, " . - "te.exe_weighting as exweight, te.exe_date as exdate, te.exe_id as exid, email as exemail, " . - "te.start_date as exstart, steps_counter as exstep, exe_user_id as excruid, te.exe_duration as exduration, ce.results_disabled as exdisabled + $hpsql="SELECT ".(api_is_western_name_order() ? "firstname as col0, lastname col1" : "lastname as col0, firstname as col1").", tth.exe_name, tth.exe_result , tth.exe_weighting, tth.exe_date + FROM $TBL_TRACK_HOTPOTATOES tth, $TBL_USER tu + WHERE tu.user_id=tth.exe_user_id AND tth.exe_cours_id = '" . Database :: escape_string($_cid) . " $user_id_and ' + ORDER BY tth.exe_cours_id ASC, tth.exe_date DESC"; + + + + } else { + // get only this user's results + $user_id_and = ' AND te.exe_user_id = ' . api_get_user_id() . ' '; + + + + /*$sql="SELECT ".(api_is_western_name_order() ? "firstname as col0, lastname col1" : "lastname as col0, firstname as col1").", ce.title as extitle, te.exe_result as exresult, " . + "te.exe_weighting as exweight, te.exe_date as exdate, te.exe_id as exid, email as exemail, " . + "te.start_date as exstart, steps_counter as exstep, cuser.user_id as excruid, te.exe_duration as exduration, ce.results_disabled as exdisabled + FROM $TBL_EXERCICES AS ce , $TBL_TRACK_EXERCICES AS te, $TBL_USER AS user,$tbl_course_rel_user AS cuser + WHERE user.user_id=cuser.user_id AND te.exe_exo_id = ce.id AND te.status != 'incomplete' AND cuser.user_id=te.exe_user_id + AND te.exe_cours_id='" . Database :: escape_string($_cid) . "' + AND cuser.relation_type<>".COURSE_RELATION_TYPE_RRHH." $user_id_and $session_id_and AND ce.active <>-1 AND" . + " orig_lp_id = 0 AND orig_lp_item_id = 0 AND cuser.course_code=te.exe_cours_id ORDER BY col1, te.exe_cours_id ASC, ce.title ASC, te.exe_date DESC";*/ + + $sql="SELECT count(*) as count FROM $TBL_EXERCICES AS ce INNER JOIN $TBL_TRACK_EXERCICES AS te ON (te.exe_exo_id = ce.id) INNER JOIN $TBL_USER AS user ON (user.user_id = exe_user_id) WHERE te.status != 'incomplete' AND te.exe_cours_id='" . Database :: escape_string($_cid) . "' $user_id_and $session_id_and AND ce.active <>-1 AND" . - " orig_lp_id = 0 AND orig_lp_item_id = 0 ORDER BY userpart2, te.exe_cours_id ASC, ce.title ASC, te.exe_date DESC"; + " orig_lp_id = 0 AND orig_lp_item_id = 0 "; - $hpsql = "SELECT '',exe_name, exe_result , exe_weighting, exe_date - FROM $TBL_TRACK_HOTPOTATOES - WHERE exe_user_id = '" . $_user['user_id'] . "' AND exe_cours_id = '" . Database :: escape_string($_cid) . "' - ORDER BY exe_cours_id ASC, exe_date DESC"; - } - $results = array(); - $resx = Database::query($sql); - while ($rowx = Database::fetch_array($resx,'ASSOC')) { - $results[] = $rowx; - } - $hpresults = getManyResultsXCol($hpsql, 5); + $hpsql = "SELECT '',exe_name, exe_result , exe_weighting, exe_date + FROM $TBL_TRACK_HOTPOTATOES + WHERE exe_user_id = '" . $_user['user_id'] . "' AND exe_cours_id = '" . Database :: escape_string($_cid) . "' + ORDER BY exe_cours_id ASC, exe_date DESC"; + } - $has_test_results = false; - $list_info = array(); + $resx = Database::query($sql); + $rowx = Database::fetch_array($resx,'ASSOC'); + return $rowx['count']; +} - // Print test results. - $lang_nostartdate = get_lang('NoStartDate') . ' / '; - if (is_array($results)) { - $has_test_results = true; - $users_array_id = array (); - if ($_GET['gradebook'] == 'view') { - $filter_by_no_revised = true; - $from_gradebook = true; - } - $sizeof = sizeof($results); - - $user_list_id = array (); - $user_last_name = ''; - $user_first_name = ''; - $quiz_name_list = ''; - $duration_list = ''; - $date_list = ''; - $result_list = ''; - $more_details_list = ''; - for ($i = 0; $i < $sizeof; $i++) { - $revised = false; - $sql_exe = 'SELECT exe_id FROM ' . $TBL_TRACK_ATTEMPT_RECORDING . ' - WHERE author != ' . "''" . ' AND exe_id = ' . "'" . Database :: escape_string($results[$i]['exid']) . "'" . ' LIMIT 1'; - $query = Database::query($sql_exe); - - if (Database :: num_rows($query) > 0) { - $revised = true; - } - if ($filter_by_not_revised && $revised) { - continue; - } - if ($filter_by_revised && !$revised) { - continue; - } - if ($from_gradebook && ($is_allowedToEdit || $is_tutor)) { - if (in_array($results[$i]['extitle'] . $results[$i]['userpart1'] . $results[$i]['userpart2'], $users_array_id)) { - continue; - } - $users_array_id[] = $results[$i]['extitle'] . $results[$i]['userpart1'] . $results[$i]['userpart2']; - } - $user_first_name = $results[$i]['userpart1']; - $user_last_name = $results[$i]['userpart2']; - $user_list_id[] = $results[$i]['excruid']; - $id = $results[$i]['exid']; - - $user = $results[$i]['userpart1'] . $results[$i]['userpart2'];; - $test = $results[$i]['extitle']; - $quiz_name_list = $test; - $dt = api_convert_and_format_date($results[$i]['exweight'], null, date_default_timezone_get()); - $res = $results[$i]['exresult']; - - $duration = intval($results[$i]['exduration']); - // we filter the results if we have the permission to - if (isset ($results[$i]['exdisabled'])) - $result_disabled = intval($results[$i]['exdisabled']); - else - $result_disabled = 0; - - if ($result_disabled == 0) { - $add_start_date = $lang_nostartdate; - - if ($is_allowedToEdit || $is_tutor) { - $user = $results[$i]['userpart1'] . $results[$i]['userpart2']; - } - if ($results[$i]['exstart'] != "0000-00-00 00:00:00") { - //echo ceil((($results[$i][4] - $results[$i][7]) / 60)) . ' ' . get_lang('MinMinutes'); - $exe_date_timestamp = api_strtotime($results[$i]['exdate'], date_default_timezone_get()); - $start_date_timestamp = api_strtotime($results[$i]['exstart'], date_default_timezone_get()); - - $my_duration = ceil((($exe_date_timestamp - $start_date_timestamp) / 60)); - if ($my_duration == 1 ) { - $duration_list = $my_duration . ' ' . get_lang('MinMinute'); - } else { - $duration_list = $my_duration. ' ' . get_lang('MinMinutes'); - } - if ($results[$i]['exstep'] > 1) { - //echo ' ( ' . $results[$i][8] . ' ' . get_lang('Steps') . ' )'; - $duration_list = ' ( ' . $results[$i]['exstep'] . ' ' . get_lang('Steps') . ' )'; - } - $add_start_date = api_convert_and_format_date($results[$i]['exstart'], null, date_default_timezone_get()) . ' / '; - } else { - $duration_list = get_lang('NoLogOfDuration'); - //echo get_lang('NoLogOfDuration'); - } - // Date conversion - $date_list = api_get_local_time($results[$i]['exstart']). ' / ' . api_get_local_time($results[$i]['exdate']); - // there are already a duration test period calculated?? - //echo ''.sprintf(get_lang('DurationFormat'), $duration).''; - // if the float look like 10.00 we show only 10 +/** + * Gets the exam'data results + * @todo this function should be moved in a library + no global calls + */ +function get_exam_results_data($from, $number_of_items, $column, $direction) { + + global $is_allowedToEdit, $is_tutor,$_cid,$_user,$TBL_USER, $TBL_EXERCICES,$TBL_TRACK_EXERCICES, $TBL_TRACK_ATTEMPT_RECORDING,$filter_by_not_revised,$filter_by_revised,$documentPath; + $session_id_and = ' AND te.session_id = ' . api_get_session_id() . ' '; + if ($is_allowedToEdit || $is_tutor) { + $user_id_and = ''; + if (!empty ($_POST['filter_by_user'])) { + if ($_POST['filter_by_user'] == 'all') { + $user_id_and = " AND user_id like '%'"; + } else { + $user_id_and = " AND user_id = '" . Database :: escape_string((int) $_POST['filter_by_user']) . "' "; + } + } + if ($_GET['gradebook'] == 'view') { + $exercise_where_query = 'te.exe_exo_id =ce.id AND '; + } + + //@todo fix to work with COURSE_RELATION_TYPE_RRHH in both queries - $my_res = float_format($results[$i]['exresult'],1); - $my_total = float_format($results[$i]['exweight'],1); + /*$sql="SELECT ".(api_is_western_name_order() ? "firstname as col0, lastname col1" : "lastname as col0, firstname as col1").", ce.title as extitle, te.exe_result as exresult , + te.exe_weighting as exweight, te.exe_date as exdate, te.exe_id as exid, email as exemail, te.start_date as exstart, steps_counter as exstep,cuser.user_id as excruid,te.exe_duration as exduration + FROM $TBL_EXERCICES AS ce , $TBL_TRACK_EXERCICES AS te, $TBL_USER AS user,$tbl_course_rel_user AS cuser + WHERE user.user_id=cuser.user_id AND cuser.relation_type<>".COURSE_RELATION_TYPE_RRHH." AND te.exe_exo_id = ce.id AND te.status != 'incomplete' AND cuser.user_id=te.exe_user_id AND te.exe_cours_id='" . Database :: escape_string($_cid) . "' + $user_id_and $session_id_and AND ce.active <>-1 AND orig_lp_id = 0 AND orig_lp_item_id = 0 + AND cuser.course_code=te.exe_cours_id ORDER BY col1, te.exe_cours_id ASC, ce.title ASC, te.exe_date DESC";*/ - $result_list = round(($my_res / ($my_total != 0 ? $my_total : 1)) * 100, 2) . '% (' . $my_res . ' / ' . $my_total . ')'; + $sql="SELECT ".(api_is_western_name_order() ? "firstname as col0, lastname col1" : "lastname as col0, firstname as col1").", ce.title as col2, te.exe_result as exresult , te.exe_weighting as exweight, + te.exe_date as exdate, te.exe_id as exid, email as exemail, te.start_date as col4, steps_counter as exstep, exe_user_id as excruid,te.exe_duration as exduration + FROM $TBL_EXERCICES AS ce INNER JOIN $TBL_TRACK_EXERCICES AS te ON (te.exe_exo_id = ce.id) INNER JOIN $TBL_USER AS user ON (user.user_id = exe_user_id) + WHERE te.status != 'incomplete' AND te.exe_cours_id='" . Database :: escape_string($_cid) . "' $user_id_and $session_id_and AND ce.active <>-1 AND orig_lp_id = 0 AND orig_lp_item_id = 0"; - $html_link = ''; - if ($is_allowedToEdit || $is_tutor) { - if ($revised) { - $html_link.= "".Display :: return_icon('edit.gif', get_lang('Edit')); - $html_link.= ' '; - } else { - $html_link.="".Display :: return_icon('quizz_small.gif', get_lang('Qualify')); - $html_link.=' '; - } - $html_link.=""; - if (api_is_platform_admin() || $is_tutor) { - $html_link.=' '.Display :: return_icon('delete.gif', get_lang('Delete')).''; - $html_link.=' '; - } - if ($is_allowedToEdit) { - if ($filter==2){ - $html_link.=' ' .Display :: return_icon('history.gif', get_lang('ViewHistoryChange')).''; - } - } - } else { - if ($revised) { - $html_link.="" . get_lang('Show') . " "; - } else { - $html_link.=' ' . get_lang('NoResult'); - } - } - $more_details_list = $html_link; - if ($is_allowedToEdit || $is_tutor) { - $list_info [] = array($user_first_name,$user_last_name,$quiz_name_list,$duration_list,$date_list,$result_list,$more_details_list); - } else { - $list_info [] = array($quiz_name_list,$duration_list,$date_list,$result_list,$more_details_list); - } - } - } - } + $hpsql="SELECT ".(api_is_western_name_order() ? "firstname as col0, lastname col1" : "lastname as col0, firstname as col1").", tth.exe_name, tth.exe_result , tth.exe_weighting, tth.exe_date + FROM $TBL_TRACK_HOTPOTATOES tth, $TBL_USER tu + WHERE tu.user_id=tth.exe_user_id AND tth.exe_cours_id = '" . Database :: escape_string($_cid) . " $user_id_and ' + ORDER BY tth.exe_cours_id ASC, tth.exe_date DESC"; - // Print HotPotatoes test results. - if (is_array($hpresults)) { - $has_test_results = true; - for ($i = 0; $i < sizeof($hpresults); $i++) { - $hp_title = GetQuizName($hpresults[$i][1], $documentPath); - if ($hp_title == '') { - $hp_title = basename($hpresults[$i][1]); - } - //$hp_date = api_convert_and_format_date($hpresults[$i][4], null, date_default_timezone_get()); - $hp_date = api_get_local_time($hpresults[$i][4], null, date_default_timezone_get()); - $hp_result = round(($hpresults[$i][2] / ($hpresults[$i][3] != 0 ? $hpresults[$i][3] : 1)) * 100, 2).'% ('.$hpresults[$i][2].' / '.$hpresults[$i][3].')'; - if ($is_allowedToEdit) { - $list_info[] = array($hpresults[$i][0], $hp_title, '-', $hp_date , $hp_result , '-'); - } else { - $list_info[] = array($hp_title, '-', $hp_date , $hp_result , '-'); - } - } - } - if ($has_test_results) { - $parameters=array('cidReq'=>Security::remove_XSS($_GET['cidReq']),'show'=>Security::remove_XSS($_GET['show']),'filter' => Security::remove_XSS($_GET['filter']),'gradebook' =>Security::remove_XSS($_GET['gradebook'])); + } else { + // get only this user's results + $user_id_and = ' AND te.exe_user_id = ' . api_get_user_id() . ' '; + /*$sql="SELECT ".(api_is_western_name_order() ? "firstname as col0, lastname col1" : "lastname as col0, firstname as col1").", ce.title as extitle, te.exe_result as exresult, " . + "te.exe_weighting as exweight, te.exe_date as exdate, te.exe_id as exid, email as exemail, " . + "te.start_date as exstart, steps_counter as exstep, cuser.user_id as excruid, te.exe_duration as exduration, ce.results_disabled as exdisabled + FROM $TBL_EXERCICES AS ce , $TBL_TRACK_EXERCICES AS te, $TBL_USER AS user,$tbl_course_rel_user AS cuser + WHERE user.user_id=cuser.user_id AND te.exe_exo_id = ce.id AND te.status != 'incomplete' AND cuser.user_id=te.exe_user_id + AND te.exe_cours_id='" . Database :: escape_string($_cid) . "' + AND cuser.relation_type<>".COURSE_RELATION_TYPE_RRHH." $user_id_and $session_id_and AND ce.active <>-1 AND" . + " orig_lp_id = 0 AND orig_lp_item_id = 0 AND cuser.course_code=te.exe_cours_id ORDER BY col1, te.exe_cours_id ASC, ce.title ASC, te.exe_date DESC";*/ - $table = new SortableTableFromArrayConfig($list_info, 1,20,'quiz_table'); - $table->set_additional_parameters($parameters); - $secuence = 2; - - if ($is_allowedToEdit || $is_tutor) { - $secuence = 0; - if (api_is_western_name_order()) { - $table->set_header(0, get_lang('FirstName')); - $table->set_header(1, get_lang('LastName')); - } else { - $table->set_header(0, get_lang('LastName')); - $table->set_header(1, get_lang('FirstName')); - } + + + $sql="SELECT ".(api_is_western_name_order() ? "firstname as col0, lastname col1" : "lastname as col0, firstname as col1")." , ce.title as col2, te.exe_result as exresult, " . + "te.exe_weighting as exweight, te.exe_date as exdate, te.exe_id as exid, email as exemail, " . + "te.start_date as col4, steps_counter as exstep, exe_user_id as excruid, te.exe_duration as exduration, ce.results_disabled as exdisabled + FROM $TBL_EXERCICES AS ce INNER JOIN $TBL_TRACK_EXERCICES AS te ON (te.exe_exo_id = ce.id) INNER JOIN $TBL_USER AS user ON (user.user_id = exe_user_id) + WHERE te.status != 'incomplete' AND te.exe_cours_id='" . Database :: escape_string($_cid) . "' $user_id_and $session_id_and AND ce.active <>-1 AND" . + " orig_lp_id = 0 AND orig_lp_item_id = 0 "; + + $hpsql = "SELECT '',exe_name, exe_result , exe_weighting, exe_date + FROM $TBL_TRACK_HOTPOTATOES + WHERE exe_user_id = '" . $_user['user_id'] . "' AND exe_cours_id = '" . Database :: escape_string($_cid) . "' + ORDER BY exe_cours_id ASC, exe_date DESC"; + } + + + $column = intval($column); + $from = intval($from); + $number_of_items = intval($number_of_items); + $sql .= " ORDER BY col$column $direction "; + $sql .= " LIMIT $from,$number_of_items"; + + $results = array(); + + $resx = Database::query($sql); + while ($rowx = Database::fetch_array($resx,'ASSOC')) { + $results[] = $rowx; + } + $hpresults = getManyResultsXCol($hpsql, 5); + + $has_test_results = false; + $list_info = array(); + + // Print test results. + $lang_nostartdate = get_lang('NoStartDate') . ' / '; + + + if (is_array($results)) { + $has_test_results = true; + $users_array_id = array (); + if ($_GET['gradebook'] == 'view') { + $filter_by_no_revised = true; + $from_gradebook = true; } - - $table->set_header(-$secuence + 2, get_lang('Exercice')); - $table->set_header(-$secuence + 3, get_lang('Duration'),false); - $table->set_header(-$secuence + 4, get_lang('Date')); - $table->set_header(-$secuence + 5, get_lang('Result'),false); - $table->set_header(-$secuence + 6, (($is_allowedToEdit||$is_tutor) ? get_lang('CorrectTest') : get_lang('ViewTest')), false); - $table->display(); - } else { - echo get_lang('NoResult'); - } -} -if ($origin != 'learnpath') { //so we are not in learnpath tool - Display :: display_footer(); -} else { -?> - - 0) { + $revised = true; + } + if ($filter_by_not_revised && $revised) { + continue; + } + if ($filter_by_revised && !$revised) { + continue; + } + if ($from_gradebook && ($is_allowedToEdit || $is_tutor)) { + if (in_array($results[$i]['col2'] . $results[$i]['col0'] . $results[$i]['col1'], $users_array_id)) { + continue; + } + $users_array_id[] = $results[$i]['col2'] . $results[$i]['col0'] . $results[$i]['col1']; + } + + $user_first_name = $results[$i]['col0']; + $user_last_name = $results[$i]['col1']; + $user_list_id[] = $results[$i]['excruid']; + $id = $results[$i]['exid']; + + $user = $results[$i]['col0'] . $results[$i]['col1']; + $test = $results[$i]['col2']; + $quiz_name_list = $test; + $dt = api_convert_and_format_date($results[$i]['exweight'], null, date_default_timezone_get()); + $res = $results[$i]['exresult']; + + $duration = intval($results[$i]['exduration']); + // we filter the results if we have the permission to + if (isset ($results[$i]['exdisabled'])) + $result_disabled = intval($results[$i]['exdisabled']); + else + $result_disabled = 0; + + if ($result_disabled == 0) { + $add_start_date = $lang_nostartdate; + + if ($is_allowedToEdit || $is_tutor) { + $user = $results[$i]['col0'] . $results[$i]['col1']; + } + if ($results[$i]['col4'] != "0000-00-00 00:00:00") { + //echo ceil((($results[$i][4] - $results[$i][7]) / 60)) . ' ' . get_lang('MinMinutes'); + $exe_date_timestamp = api_strtotime($results[$i]['exdate'], date_default_timezone_get()); + $start_date_timestamp = api_strtotime($results[$i]['col4'], date_default_timezone_get()); + + $my_duration = ceil((($exe_date_timestamp - $start_date_timestamp) / 60)); + if ($my_duration == 1 ) { + $duration_list = $my_duration . ' ' . get_lang('MinMinute'); + } else { + $duration_list = $my_duration. ' ' . get_lang('MinMinutes'); + } + if ($results[$i]['exstep'] > 1) { + //echo ' ( ' . $results[$i][8] . ' ' . get_lang('Steps') . ' )'; + $duration_list = ' ( ' . $results[$i]['exstep'] . ' ' . get_lang('Steps') . ' )'; + } + $add_start_date = api_convert_and_format_date($results[$i]['col4'], null, date_default_timezone_get()) . ' / '; + } else { + $duration_list = get_lang('NoLogOfDuration'); + //echo get_lang('NoLogOfDuration'); + } + // Date conversion + $date_list = api_get_local_time($results[$i]['col4']). ' / ' . api_get_local_time($results[$i]['exdate']); + // there are already a duration test period calculated?? + //echo ''.sprintf(get_lang('DurationFormat'), $duration).''; + + // if the float look like 10.00 we show only 10 + + $my_res = float_format($results[$i]['exresult'],1); + $my_total = float_format($results[$i]['exweight'],1); + + $result_list = round(($my_res / ($my_total != 0 ? $my_total : 1)) * 100, 2) . '% (' . $my_res . ' / ' . $my_total . ')'; + + $html_link = ''; + if ($is_allowedToEdit || $is_tutor) { + if ($revised) { + $html_link.= "".Display :: return_icon('edit.gif', get_lang('Edit')); + $html_link.= ' '; + } else { + $html_link.="".Display :: return_icon('quizz_small.gif', get_lang('Qualify')); + $html_link.=' '; + } + $html_link.=""; + if (api_is_platform_admin() || $is_tutor) { + $html_link.=' '.Display :: return_icon('delete.gif', get_lang('Delete')).''; + $html_link.=' '; + } + if ($is_allowedToEdit) { + if ($filter==2){ + $html_link.=' ' .Display :: return_icon('history.gif', get_lang('ViewHistoryChange')).''; + } + } + } else { + if ($revised) { + $html_link.="" . get_lang('Show') . " "; + } else { + $html_link.=' ' . get_lang('NoResult'); + } + } + $more_details_list = $html_link; + if ($is_allowedToEdit || $is_tutor) { + $list_info [] = array($user_first_name,$user_last_name,$quiz_name_list,$duration_list,$date_list,$result_list,$more_details_list); + } else { + $list_info [] = array($quiz_name_list,$duration_list,$date_list,$result_list,$more_details_list); + } + } + } + } + // Print HotPotatoes test results. + if (is_array($hpresults)) { + $has_test_results = true; + for ($i = 0; $i < sizeof($hpresults); $i++) { + $hp_title = GetQuizName($hpresults[$i][1], $documentPath); + if ($hp_title == '') { + $hp_title = basename($hpresults[$i][1]); + } + //$hp_date = api_convert_and_format_date($hpresults[$i][4], null, date_default_timezone_get()); + $hp_date = api_get_local_time($hpresults[$i][4], null, date_default_timezone_get()); + $hp_result = round(($hpresults[$i][2] / ($hpresults[$i][3] != 0 ? $hpresults[$i][3] : 1)) * 100, 2).'% ('.$hpresults[$i][2].' / '.$hpresults[$i][3].')'; + if ($is_allowedToEdit) { + $list_info[] = array($hpresults[$i][0], $hp_title, '-', $hp_date , $hp_result , '-'); + } else { + $list_info[] = array($hp_title, '-', $hp_date , $hp_result , '-'); + } + } + } + return $list_info; + } + + ?> \ No newline at end of file