Exercise: Improve export results to pdfs in zip - refs BT#20691

Author: @christianbeeznest
pull/4697/head
christianbeeznest 3 years ago committed by GitHub
parent 818ea5a120
commit 4933d1a0b6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 21
      main/inc/lib/exercise.lib.php
  2. 24
      main/inc/lib/pdf.lib.php

@ -7169,9 +7169,16 @@ EOT;
curl_setopt($ch, CURLOPT_FAILONERROR, false); curl_setopt($ch, CURLOPT_FAILONERROR, false);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, false); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, false);
curl_setopt($ch, CURLOPT_HEADER, true); curl_setopt($ch, CURLOPT_HEADER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$result = curl_exec($ch); $result = curl_exec($ch);
if (false === $result) {
error_log('saveFileExerciseResultPdf error: '.curl_error($ch));
}
curl_close($ch); curl_close($ch);
} }
@ -7188,6 +7195,7 @@ EOT;
'' ''
); );
$exportOk = false;
if (!empty($exeResults)) { if (!empty($exeResults)) {
$exportName = 'S'.$sessionId.'-C'.$courseId.'-T'.$exerciseId; $exportName = 'S'.$sessionId.'-C'.$courseId.'-T'.$exerciseId;
$baseDir = api_get_path(SYS_ARCHIVE_PATH); $baseDir = api_get_path(SYS_ARCHIVE_PATH);
@ -7209,7 +7217,8 @@ EOT;
// 3. If export folder is not empty will be zipped. // 3. If export folder is not empty will be zipped.
$isFolderPathEmpty = (file_exists($exportFolderPath) && 2 == count(scandir($exportFolderPath))); $isFolderPathEmpty = (file_exists($exportFolderPath) && 2 == count(scandir($exportFolderPath)));
if (!$isFolderPathEmpty) { if (is_dir($exportFolderPath) && !$isFolderPathEmpty) {
$exportOk = true;
$exportFilePath = $baseDir.$exportName.'.zip'; $exportFilePath = $baseDir.$exportName.'.zip';
$zip = new \PclZip($exportFilePath); $zip = new \PclZip($exportFilePath);
$zip->create($exportFolderPath, PCLZIP_OPT_REMOVE_PATH, $exportFolderPath); $zip->create($exportFolderPath, PCLZIP_OPT_REMOVE_PATH, $exportFolderPath);
@ -7220,6 +7229,16 @@ EOT;
} }
} }
if (!$exportOk) {
Display::addFlash(
Display::return_message(
get_lang('ExportExerciseNoResult'),
'warning',
false
)
);
}
return false; return false;
} }
} }

@ -560,15 +560,23 @@ class PDF
if ($saveInFile) { if ($saveInFile) {
$fileToSave = !empty($fileToSave) ? $fileToSave : api_get_path(SYS_ARCHIVE_PATH).uniqid(); $fileToSave = !empty($fileToSave) ? $fileToSave : api_get_path(SYS_ARCHIVE_PATH).uniqid();
@$this->pdf->Output( try {
$fileToSave, @$this->pdf->Output(
$outputMode $fileToSave,
); // F to save the pdf in a file $outputMode
); // F to save the pdf in a file
} catch (MpdfException $e) {
error_log($e);
}
} else { } else {
@$this->pdf->Output( try {
$output_file, @$this->pdf->Output(
$outputMode $output_file,
); // F to save the pdf in a file $outputMode
); // F to save the pdf in a file
} catch (MpdfException $e) {
error_log($e);
}
} }
if ($outputMode != 'F') { if ($outputMode != 'F') {

Loading…
Cancel
Save