Adding start_date, end_date, duration in reports see #4545

skala
Julio Montoya 13 years ago
parent 14c02d8ae0
commit f11a32b22a
  1. 1
      main/exercice/exercise.lib.php
  2. 3
      main/exercice/exercise_report.php
  3. 133
      main/exercice/exercise_result.class.php
  4. 16
      main/exercice/exercise_result.php
  5. 4
      main/exercice/exercise_submit.php

@ -844,7 +844,6 @@ function get_exam_results_data($from, $number_of_items, $column, $direction, $ex
$sqlFromOption = ""; $sqlFromOption = "";
$sqlWhereOption = ""; // for hpsql $sqlWhereOption = ""; // for hpsql
$sql_inner_join_tbl_user = "";
//@todo fix to work with COURSE_RELATION_TYPE_RRHH in both queries //@todo fix to work with COURSE_RELATION_TYPE_RRHH in both queries

@ -73,9 +73,10 @@ if (!empty($_REQUEST['export_report']) && $_REQUEST['export_report'] == '1') {
if (api_is_platform_admin() || api_is_course_admin() || api_is_course_tutor() || api_is_course_coach()) { if (api_is_platform_admin() || api_is_course_admin() || api_is_course_tutor() || api_is_course_coach()) {
$load_extra_data = false; $load_extra_data = false;
if (isset($_REQUEST['extra_data'])) { if (isset($_REQUEST['extra_data']) && $_REQUEST['extra_data'] == 1) {
$load_extra_data = true; $load_extra_data = true;
} }
require_once 'exercise_result.class.php'; require_once 'exercise_result.class.php';
switch ($_GET['export_format']) { switch ($_GET['export_format']) {
case 'xls' : case 'xls' :

@ -87,18 +87,10 @@ class ExerciseResult
$return = array(); $return = array();
$TBL_EXERCISES = Database::get_course_table(TABLE_QUIZ_TEST); $TBL_EXERCISES = Database::get_course_table(TABLE_QUIZ_TEST);
$TBL_EXERCISE_QUESTION = Database::get_course_table(TABLE_QUIZ_TEST_QUESTION);
$TBL_QUESTIONS = Database::get_course_table(TABLE_QUIZ_QUESTION);
$TBL_USER = Database::get_main_table(TABLE_MAIN_USER); $TBL_USER = Database::get_main_table(TABLE_MAIN_USER);
$TBL_DOCUMENT = Database::get_course_table(TABLE_DOCUMENT);
$TBL_ITEM_PROPERTY = Database::get_course_table(TABLE_ITEM_PROPERTY);
$TBL_TRACK_EXERCISES = Database::get_statistic_table(TABLE_STATISTIC_TRACK_E_EXERCICES); $TBL_TRACK_EXERCISES = Database::get_statistic_table(TABLE_STATISTIC_TRACK_E_EXERCICES);
$TBL_TRACK_HOTPOTATOES = Database::get_statistic_table(TABLE_STATISTIC_TRACK_E_HOTPOTATOES); $TBL_TRACK_HOTPOTATOES = Database::get_statistic_table(TABLE_STATISTIC_TRACK_E_HOTPOTATOES);
$TBL_TRACK_ATTEMPT = Database::get_statistic_table(TABLE_STATISTIC_TRACK_E_ATTEMPT);
$TBL_TRACK_ATTEMPT_RECORDING= Database :: get_statistic_table(TABLE_STATISTIC_TRACK_E_ATTEMPT_RECORDING); $TBL_TRACK_ATTEMPT_RECORDING= Database :: get_statistic_table(TABLE_STATISTIC_TRACK_E_ATTEMPT_RECORDING);
$TBL_COURSE_REL_USER = Database :: get_main_table(TABLE_MAIN_COURSE_USER);
$cid = api_get_course_id(); $cid = api_get_course_id();
$course_id = api_get_course_int_id(); $course_id = api_get_course_int_id();
@ -112,8 +104,17 @@ class ExerciseResult
} }
if (empty($user_id)) { if (empty($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, $sql = "SELECT ".(api_is_western_name_order() ? "firstname as userpart1, lastname userpart2" : "lastname as userpart1, firstname as userpart2").",
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.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 duration
FROM $TBL_EXERCISES AS ce INNER JOIN $TBL_TRACK_EXERCISES AS te ON (te.exe_exo_id = ce.id) INNER JOIN FROM $TBL_EXERCISES AS ce INNER JOIN $TBL_TRACK_EXERCISES AS te ON (te.exe_exo_id = ce.id) INNER JOIN
$TBL_USER AS user ON (user.user_id = exe_user_id) $TBL_USER AS user ON (user.user_id = exe_user_id)
WHERE ce.c_id = $course_id AND WHERE ce.c_id = $course_id AND
@ -122,8 +123,12 @@ class ExerciseResult
ce.active <>-1 AND ce.active <>-1 AND
orig_lp_id = 0 AND orig_lp_id = 0 AND
orig_lp_item_id = 0"; orig_lp_item_id = 0";
$hpsql="SELECT ".(api_is_western_name_order() ? "firstname as userpart1, lastname userpart2" : "lastname as userpart1, firstname as userpart2").",
$hpsql="SELECT ".(api_is_western_name_order() ? "firstname as userpart1, lastname userpart2" : "lastname as userpart1, firstname as userpart2").", email, tth.exe_name, tth.exe_result , tth.exe_weighting, tth.exe_date email,
tth.exe_name,
tth.exe_result,
tth.exe_weighting,
tth.exe_date
FROM $TBL_TRACK_HOTPOTATOES tth, $TBL_USER tu FROM $TBL_TRACK_HOTPOTATOES tth, $TBL_USER tu
WHERE tu.user_id=tth.exe_user_id AND WHERE tu.user_id=tth.exe_user_id AND
tth.exe_cours_id = '" . Database :: escape_string($cid) . "' AND tth.exe_cours_id = '" . Database :: escape_string($cid) . "' AND
@ -133,9 +138,18 @@ class ExerciseResult
} else { } else {
$user_id_and = ' AND te.exe_user_id = ' . api_get_user_id() . ' '; $user_id_and = ' AND te.exe_user_id = ' . api_get_user_id() . ' ';
// get only this user's results // get only this user's results
$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, " . $sql="SELECT ".(api_is_western_name_order() ? "firstname as userpart1, lastname userpart2" : "lastname as userpart1, firstname as userpart2").",
"te.exe_weighting as exweight, te.exe_date as exdate, te.exe_id as exid, email as exemail, " . ce.title as extitle,
"te.start_date as exstart, steps_counter as exstep, exe_user_id as excruid, te.exe_duration as exduration, ce.results_disabled as exdisabled 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 duration,
ce.results_disabled as exdisabled
FROM $TBL_EXERCISES AS ce INNER JOIN $TBL_TRACK_EXERCISES AS te ON (te.exe_exo_id = ce.id) INNER JOIN $TBL_USER AS user ON (user.user_id = exe_user_id) FROM $TBL_EXERCISES AS ce INNER JOIN $TBL_TRACK_EXERCISES AS te ON (te.exe_exo_id = ce.id) INNER JOIN $TBL_USER AS user ON (user.user_id = exe_user_id)
WHERE ce.c_id = $course_id AND WHERE ce.c_id = $course_id AND
te.status != 'incomplete' AND te.status != 'incomplete' AND
@ -204,7 +218,9 @@ class ExerciseResult
$return[$i]['email'] = $results[$i]['exemail']; $return[$i]['email'] = $results[$i]['exemail'];
} }
$return[$i]['title'] = $results[$i]['extitle']; $return[$i]['title'] = $results[$i]['extitle'];
$return[$i]['time'] = api_convert_and_format_date($results[$i]['exdate']); $return[$i]['start_date'] = api_get_local_time($results[$i]['exstart']);
$return[$i]['end_date'] = api_get_local_time($results[$i]['exdate']);
$return[$i]['duration'] = $results[$i]['duration'];
$return[$i]['result'] = $results[$i]['exresult']; $return[$i]['result'] = $results[$i]['exresult'];
$return[$i]['max'] = $results[$i]['exweight']; $return[$i]['max'] = $results[$i]['exweight'];
$return[$i]['status'] = $revised ? get_lang('Validated') : get_lang('NotValidated'); $return[$i]['status'] = $revised ? get_lang('Validated') : get_lang('NotValidated');
@ -225,7 +241,10 @@ class ExerciseResult
$return[$i]['last_name'] = $hpresults[$i]['userpart2']; $return[$i]['last_name'] = $hpresults[$i]['userpart2'];
} }
$return[$i]['title'] = $title; $return[$i]['title'] = $title;
$return[$i]['time'] = api_convert_and_format_date($hpresults[$i]['exdate']); $return[$i]['start_date'] = api_get_local_time($results[$i]['exstart']);
$return[$i]['end_date'] = api_get_local_time($results[$i]['exdate']);
$return[$i]['duration'] = $results[$i]['duration'];
$return[$i]['result'] = $hpresults[$i]['exe_result']; $return[$i]['result'] = $hpresults[$i]['exe_result'];
$return[$i]['max'] = $hpresults[$i]['exe_weighting']; $return[$i]['max'] = $hpresults[$i]['exe_weighting'];
} }
@ -249,6 +268,7 @@ class ExerciseResult
} }
$data = ''; $data = '';
if (api_is_western_name_order()) { if (api_is_western_name_order()) {
if(!empty($this->results[0]['first_name'])) { if(!empty($this->results[0]['first_name'])) {
$data .= get_lang('FirstName').';'; $data .= get_lang('FirstName').';';
@ -277,6 +297,8 @@ class ExerciseResult
$data .= get_lang('Title').';'; $data .= get_lang('Title').';';
$data .= get_lang('StartDate').';'; $data .= get_lang('StartDate').';';
$data .= get_lang('EndDate').';';
$data .= get_lang('Duration'). ' ('.get_lang('MinMinutes').') ;';
$data .= get_lang('Score').';'; $data .= get_lang('Score').';';
$data .= get_lang('Total').';'; $data .= get_lang('Total').';';
$data .= get_lang('Status').';'; $data .= get_lang('Status').';';
@ -284,21 +306,15 @@ class ExerciseResult
//results //results
foreach($this->results as $row) { foreach($this->results as $row) {
if (api_is_western_name_order()) { if (api_is_western_name_order()) {
if(!empty($row['first_name'])) { $data .= str_replace("\r\n",' ',api_html_entity_decode(strip_tags($row['first_name']), ENT_QUOTES, $charset)).';';
$data .= str_replace("\r\n",' ',api_html_entity_decode(strip_tags($row['first_name']), ENT_QUOTES, $charset)).';'; $data .= str_replace("\r\n",' ',api_html_entity_decode(strip_tags($row['last_name']), ENT_QUOTES, $charset)).';';
}
if(!empty($row['last_name'])) {
$data .= str_replace("\r\n",' ',api_html_entity_decode(strip_tags($row['last_name']), ENT_QUOTES, $charset)).';';
}
} else { } else {
if(!empty($row['last_name'])) { $data .= str_replace("\r\n",' ',api_html_entity_decode(strip_tags($row['last_name']), ENT_QUOTES, $charset)).';';
$data .= str_replace("\r\n",' ',api_html_entity_decode(strip_tags($row['last_name']), ENT_QUOTES, $charset)).';'; $data .= str_replace("\r\n",' ',api_html_entity_decode(strip_tags($row['first_name']), ENT_QUOTES, $charset)).';';
}
if(!empty($row['first_name'])) {
$data .= str_replace("\r\n",' ',api_html_entity_decode(strip_tags($row['first_name']), ENT_QUOTES, $charset)).';';
}
} }
$data .= str_replace("\r\n",' ',api_html_entity_decode(strip_tags($row['email']), ENT_QUOTES, $charset)).';'; $data .= str_replace("\r\n",' ',api_html_entity_decode(strip_tags($row['email']), ENT_QUOTES, $charset)).';';
if ($export_user_fields) { if ($export_user_fields) {
@ -308,8 +324,11 @@ class ExerciseResult
$data .= '"'.str_replace('"','""',api_html_entity_decode(strip_tags($value), ENT_QUOTES, $charset)).'";'; $data .= '"'.str_replace('"','""',api_html_entity_decode(strip_tags($value), ENT_QUOTES, $charset)).'";';
} }
} }
$data .= str_replace("\r\n",' ',api_html_entity_decode(strip_tags($row['title']), ENT_QUOTES, $charset)).';'; $data .= str_replace("\r\n",' ',api_html_entity_decode(strip_tags($row['title']), ENT_QUOTES, $charset)).';';
$data .= str_replace("\r\n",' ',$row['time']).';'; $data .= str_replace("\r\n",' ',$row['start_date']).';';
$data .= str_replace("\r\n",' ',$row['end_date']).';';
$data .= str_replace("\r\n",' ',$row['duration']).';';
$data .= str_replace("\r\n",' ',$row['result']).';'; $data .= str_replace("\r\n",' ',$row['result']).';';
$data .= str_replace("\r\n",' ',$row['max']).';'; $data .= str_replace("\r\n",' ',$row['max']).';';
$data .= str_replace("\r\n",' ',$row['status']).';'; $data .= str_replace("\r\n",' ',$row['status']).';';
@ -345,11 +364,9 @@ class ExerciseResult
global $charset; global $charset;
$this->_getExercisesReporting($document_path, $user_id, $export_filter, $exercise_id, $hotpotato_name); $this->_getExercisesReporting($document_path, $user_id, $export_filter, $exercise_id, $hotpotato_name);
$filename = 'exercise_results_'.date('YmdGis').'.xls'; $filename = 'exercise_results_'.date('YmdGis').'.xls';
if(!empty($user_id)) { if (!empty($user_id)) {
$filename = 'exercise_results_user_'.$user_id.'_'.date('YmdGis').'.xls'; $filename = 'exercise_results_user_'.$user_id.'_'.date('YmdGis').'.xls';
} }
require_once api_get_path(LIBRARY_PATH).'pear/Spreadsheet_Excel_Writer/Writer.php';
$workbook = new Spreadsheet_Excel_Writer(); $workbook = new Spreadsheet_Excel_Writer();
$workbook->setTempDir(api_get_path(SYS_ARCHIVE_PATH)); $workbook->setTempDir(api_get_path(SYS_ARCHIVE_PATH));
$workbook->setVersion(8); // BIFF8 $workbook->setVersion(8); // BIFF8
@ -369,6 +386,8 @@ class ExerciseResult
} }
} }
if ($with_column_user) { if ($with_column_user) {
$worksheet->write($line,$column,get_lang('Email')); $worksheet->write($line,$column,get_lang('Email'));
@ -392,32 +411,45 @@ class ExerciseResult
$extra_user_fields = UserManager::get_extra_fields(0,1000,5,'ASC',false, 1); $extra_user_fields = UserManager::get_extra_fields(0,1000,5,'ASC',false, 1);
//show the fields names for user fields //show the fields names for user fields
foreach($extra_user_fields as $field) { foreach ($extra_user_fields as $field) {
$worksheet->write($line,$column,api_html_entity_decode(strip_tags($field[3]), ENT_QUOTES, $charset)); $worksheet->write($line,$column,api_html_entity_decode(strip_tags($field[3]), ENT_QUOTES, $charset));
$column++; $column++;
} }
} }
$worksheet->write($line,$column,get_lang('Title')); $worksheet->write($line,$column, get_lang('Title'));
$column++; $column++;
$worksheet->write($line,$column,get_lang('StartDate')); $worksheet->write($line,$column, get_lang('StartDate'));
$column++;
$worksheet->write($line,$column, get_lang('EndDate'));
$column++;
$worksheet->write($line,$column, get_lang('Duration').' ('.get_lang('MinMinutes').')');
$column++; $column++;
$worksheet->write($line,$column,get_lang('Score')); $worksheet->write($line,$column, get_lang('Score'));
$column++; $column++;
$worksheet->write($line,$column,get_lang('Total')); $worksheet->write($line,$column, get_lang('Total'));
$column++; $column++;
$worksheet->write($line,$column,get_lang('Status')); $worksheet->write($line,$column, get_lang('Status'));
$line++; $line++;
foreach($this->results as $row) { foreach ($this->results as $row) {
$column = 0; $column = 0;
if(!empty($row['last_name']) && !empty($row['first_name'])) {
$worksheet->write($line,$column,api_html_entity_decode(strip_tags($row['email']), ENT_QUOTES, $charset)); if ($with_column_user) {
$column++; $worksheet->write($line,$column,api_html_entity_decode(strip_tags($row['email']), ENT_QUOTES, $charset));
$worksheet->write($line,$column,api_html_entity_decode(strip_tags($row['last_name']), ENT_QUOTES, $charset)); $column++;
$column++;
$worksheet->write($line,$column,api_html_entity_decode(strip_tags($row['first_name']), ENT_QUOTES, $charset)); if (api_is_western_name_order()) {
$column++; $worksheet->write($line,$column,api_html_entity_decode(strip_tags($row['first_name']), ENT_QUOTES, $charset));
$column++;
$worksheet->write($line,$column,api_html_entity_decode(strip_tags($row['last_name']), ENT_QUOTES, $charset));
$column++;
} else {
$worksheet->write($line,$column,api_html_entity_decode(strip_tags($row['last_name']), ENT_QUOTES, $charset));
$column++;
$worksheet->write($line,$column,api_html_entity_decode(strip_tags($row['first_name']), ENT_QUOTES, $charset));
$column++;
}
} }
if ($export_user_fields) { if ($export_user_fields) {
@ -428,9 +460,14 @@ class ExerciseResult
$column++; $column++;
} }
} }
$worksheet->write($line,$column,api_html_entity_decode(strip_tags($row['title']), ENT_QUOTES, $charset)); $worksheet->write($line,$column,api_html_entity_decode(strip_tags($row['title']), ENT_QUOTES, $charset));
$column++; $column++;
$worksheet->write($line,$column,$row['time']); $worksheet->write($line,$column,$row['start_date']);
$column++;
$worksheet->write($line,$column,$row['end_date']);
$column++;
$worksheet->write($line,$column,$row['duration']);
$column++; $column++;
$worksheet->write($line,$column,$row['result']); $worksheet->write($line,$column,$row['result']);
$column++; $column++;

@ -212,10 +212,22 @@ if ($origin != 'learnpath') {
// Updates the empty exercise // Updates the empty exercise
$quiz_duration = (!empty($_SESSION['quizStartTime']) ? time() - $_SESSION['quizStartTime'] : 0); $quiz_duration = 0;
$end_date = api_get_utc_datetime();
if (isset($_SESSION['quizStartTime']) && !empty($_SESSION['quizStartTime'])) {
if (isset($_SESSION['quizStartTime'][$objExercise->selectId()])) {
$start_date = $_SESSION['quizStartTime'][$objExercise->selectId()];
$end_date_datetime = new DateTime($end_date);
$start_date_date_time = new DateTime($start_date);
$interval = $end_date_datetime->diff($start_date_date_time);
$hours = $interval->format('%h');
$minutes = $interval->format('%i');
$quiz_duration = $hours * 60 + $minutes;
}
}
if (api_is_allowed_to_session_edit()) { if (api_is_allowed_to_session_edit()) {
update_event_exercice($exercise_stat_info['exe_id'], $objExercise->selectId(), $total_score, $total_weight, api_get_session_id(), $safe_lp_id, $safe_lp_item_id, $safe_lp_item_view_id, $quiz_duration, $question_list, ''); update_event_exercice($exercise_stat_info['exe_id'], $objExercise->selectId(), $total_score, $total_weight, api_get_session_id(), $safe_lp_id, $safe_lp_item_id, $safe_lp_item_view_id, $quiz_duration, $question_list, '', array(), $end_date);
} }
//If is not valid //If is not valid

@ -369,8 +369,8 @@ if (!isset($_SESSION['questionList'])) {
if ($debug) error_log('8. Question list loaded '.print_r($questionList, 1)); if ($debug) error_log('8. Question list loaded '.print_r($questionList, 1));
$quizStartTime = time(); $quizStartTime = array( $exerciseId => api_get_utc_datetime());
Session::write('quizStartTime',$quizStartTime); Session::write('quizStartTime', $quizStartTime);
//Real question count //Real question count
$question_count = 0; $question_count = 0;

Loading…
Cancel
Save