Skip to content

Commit

Permalink
Fix exercise export see BT#12312
Browse files Browse the repository at this point in the history
  • Loading branch information
jmontoyaa committed Feb 23, 2017
1 parent ae77dbf commit 1680c30
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 21 deletions.
8 changes: 0 additions & 8 deletions main/exercise/exercise_report.php
Expand Up @@ -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(
Expand Down
39 changes: 30 additions & 9 deletions main/exercise/exercise_result.class.php
Expand Up @@ -296,15 +296,20 @@ 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)) {
$filename = 'exercise_results_user_'.$user_id.'_'.$now.'.csv';
}

$filename = api_replace_dangerous_char($filename);

$data = '';
if (api_is_western_name_order()) {
if (!empty($this->results[0]['first_name'])) {
Expand Down Expand Up @@ -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']).';';
Expand Down Expand Up @@ -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 = '',
Expand All @@ -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'
Expand Down Expand Up @@ -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++;
Expand Down
2 changes: 1 addition & 1 deletion main/exercise/hotpotatoes_exercise_report.php
Expand Up @@ -318,7 +318,7 @@ function exportExcel() {
<?php } ?>
});
</script>
<form id="export_report_form" method="post" action="hotpotatoes_exercise_report.php">
<form id="export_report_form" method="post" action="hotpotatoes_exercise_report.php?<?php echo api_get_cidreq(); ?>">
<input type="hidden" name="csvBuffer" id="csvBuffer" value="" />
<input type="hidden" name="export_report" id="export_report" value="1" />
<input type="hidden" name="path" id="path" value="<?php echo $hotpotatoes_path ?>" />
Expand Down
4 changes: 1 addition & 3 deletions main/inc/lib/exercise.lib.php
Expand Up @@ -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,
Expand Down

0 comments on commit 1680c30

Please sign in to comment.