From 1680c3042f47ccdd6a684f2528e951211940a343 Mon Sep 17 00:00:00 2001 From: jmontoyaa Date: Thu, 23 Feb 2017 13:16:57 +0100 Subject: [PATCH] Fix exercise export see BT#12312 --- main/exercise/exercise_report.php | 8 ---- main/exercise/exercise_result.class.php | 39 ++++++++++++++----- main/exercise/hotpotatoes_exercise_report.php | 2 +- main/inc/lib/exercise.lib.php | 4 +- 4 files changed, 32 insertions(+), 21 deletions(-) diff --git a/main/exercise/exercise_report.php b/main/exercise/exercise_report.php index 56166e470a8..1edf8940eea 100755 --- a/main/exercise/exercise_report.php +++ b/main/exercise/exercise_report.php @@ -213,14 +213,6 @@ if (isset($_POST['send_notification'])) { //@todo move this somewhere else $subject = get_lang('ExamSheetVCC'); - /*$message = ExerciseLib::getEmailNotification( - api_get_user_id(), - $course_info, - $test, - $lp_id, - $url - );*/ - $message = isset($_POST['notification_content']) ? $_POST['notification_content'] : ''; MessageManager::send_message_simple( diff --git a/main/exercise/exercise_result.class.php b/main/exercise/exercise_result.class.php index 31401a0f8e2..5fa2c0de314 100755 --- a/main/exercise/exercise_result.class.php +++ b/main/exercise/exercise_result.class.php @@ -296,7 +296,13 @@ public function exportCompleteReportCSV( $hotpotato_name = null ) { 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 + ); $now = api_get_local_time(); $filename = 'exercise_results_'.$now.'.csv'; if (!empty($user_id)) { @@ -304,7 +310,6 @@ public function exportCompleteReportCSV( } $filename = api_replace_dangerous_char($filename); - $data = ''; if (api_is_western_name_order()) { if (!empty($this->results[0]['first_name'])) { @@ -391,11 +396,12 @@ public function exportCompleteReportCSV( } } } + $duration = !empty($row['duration']) ? round($row['duration'] / 60) : 0; $data .= str_replace("\r\n",' ', api_html_entity_decode(strip_tags($row['title']), ENT_QUOTES, $charset)).';'; $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", ' ', $duration).';'; $data .= str_replace("\r\n", ' ', $row['result']).';'; $data .= str_replace("\r\n", ' ', $row['max']).';'; $data .= str_replace("\r\n", ' ', $row['status']).';'; @@ -427,7 +433,14 @@ public function exportCompleteReportCSV( /** * Exports the complete report as an XLS file - * @return boolean False on error + * + * @param string $document_path + * @param null $user_id + * @param bool $export_user_fields + * @param int $export_filter + * @param int $exercise_id + * @param null $hotpotato_name + * @return bool */ public function exportCompleteReportXLS( $document_path = '', @@ -438,17 +451,24 @@ public function exportCompleteReportXLS( $hotpotato_name = null ) { global $charset; - $this->getExercisesReporting($document_path, $user_id, $export_filter, $exercise_id, $hotpotato_name); - $filename = 'exercise_results_'.api_get_local_time().'.xlsx'; + $this->getExercisesReporting( + $document_path, + $user_id, + $export_filter, + $exercise_id, + $hotpotato_name + ); + $now = api_get_local_time(); + $filename = 'exercise_results_'.$now.'.xlsx'; if (!empty($user_id)) { - $filename = 'exercise_results_user_'.$user_id.'_'.api_get_local_time().'.xlsx'; + $filename = 'exercise_results_user_'.$user_id.'_'.$now.'.xlsx'; } $spreadsheet = new PHPExcel(); $spreadsheet->setActiveSheetIndex(0); $worksheet = $spreadsheet->getActiveSheet(); - $line = 0; + $line = 1; // Skip first line $column = 0; //skip the first column (row titles) // check if exists column 'user' @@ -648,7 +668,8 @@ public function exportCompleteReportXLS( $column++; $worksheet->setCellValueByColumnAndRow($column, $line, $row['end_date']); $column++; - $worksheet->setCellValueByColumnAndRow($column, $line, $row['duration']); + $duration = !empty($row['duration']) ? round($row['duration'] / 60) : 0; + $worksheet->setCellValueByColumnAndRow($column, $line, $duration); $column++; $worksheet->setCellValueByColumnAndRow($column, $line, $row['result']); $column++; diff --git a/main/exercise/hotpotatoes_exercise_report.php b/main/exercise/hotpotatoes_exercise_report.php index 3fa51cbe6cc..f3aa6505247 100755 --- a/main/exercise/hotpotatoes_exercise_report.php +++ b/main/exercise/hotpotatoes_exercise_report.php @@ -318,7 +318,7 @@ function exportExcel() { }); -
+ diff --git a/main/inc/lib/exercise.lib.php b/main/inc/lib/exercise.lib.php index 9c775491790..6f000abfc60 100644 --- a/main/inc/lib/exercise.lib.php +++ b/main/inc/lib/exercise.lib.php @@ -1995,9 +1995,7 @@ public static function get_exam_results_data( } } else { - $attempt_url = api_get_path( - WEB_CODE_PATH - ) . 'exercise/result.php?' . api_get_cidreq() . '&id=' . $results[$i]['exe_id'] . '&id_session=' . $sessionId; + $attempt_url = api_get_path(WEB_CODE_PATH) . 'exercise/result.php?' . api_get_cidreq() . '&id=' . $results[$i]['exe_id'] . '&id_session=' . $sessionId; $attempt_link = Display::url( get_lang('Show'), $attempt_url,