Gradebook: Add CLI to export all certificates in course - refs BT#18279

pull/3757/head
Angel Fernando Quiroz Campos 5 years ago
parent 0cc8382f10
commit 1ed046f462
  1. 32
      main/gradebook/cli/export_all_certificates.php
  2. 25
      main/gradebook/lib/be/category.class.php
  3. 15
      main/inc/lib/pdf.lib.php

@ -0,0 +1,32 @@
<?php
/* For licensing terms, see /license.txt */
/**
* Command to export certificates for a gradebook categori in course (or course session).
*
* <code>php main/gradebook/cli/export_all_certificated.php COURSE_CODE SESSION_ID CATEGORY_ID [USER_IDS]</code>
*/
require_once __DIR__.'/../../inc/global.inc.php';
if (PHP_SAPI !== 'cli') {
die(get_lang('NotAllowed'));
}
$courseCode = $argv[1];
$sessionId = $argv[2];
$categoryId = $argv[3];
$userList = isset($argv[4]) ? explode(',', $argv[4]) : [];
$date = api_get_utc_datetime(null, false, true);
$pdfName = 'certs_'.$courseCode.'_'.$sessionId.'_'.$categoryId.'_'.$date->format('Y-m-d');
$finalFile = api_get_path(SYS_ARCHIVE_PATH)."$pdfName.pdf";
if (file_exists($finalFile)) {
unlink(api_get_path(SYS_ARCHIVE_PATH)."$pdfName.pdf");
}
Category::exportAllCertificates($categoryId, $userList, $courseCode, true, $pdfName);

@ -2267,9 +2267,19 @@ class Category implements GradebookItem
/**
* @param int $catId
* @param array $userList
*/
public static function exportAllCertificates($catId, $userList = [])
{
* @param string|null $courseCode
* @param bool $generateToFile
* @param string $pdfName
*
* @throws \MpdfException
*/
public static function exportAllCertificates(
$catId,
$userList = [],
$courseCode = null,
$generateToFile = false,
$pdfName = ''
) {
$orientation = api_get_configuration_value('certificate_pdf_orientation');
$params['orientation'] = 'landscape';
@ -2310,10 +2320,13 @@ class Category implements GradebookItem
// stuff) and return as one multiple-pages PDF
$pdf->html_to_pdf(
$certificate_path_list,
get_lang('Certificates'),
null,
empty($pdfName) ? get_lang('Certificates') : $pdfName,
$courseCode,
false,
false
false,
true,
'',
$generateToFile
);
}
}

@ -186,12 +186,15 @@ class PDF
* 1 => array('title'=>'Bye','path'=>'file2.html')
* );
* @param string $pdf_name pdf name
* @param string $course_code (if you are using html that are located
* @param null $course_code (if you are using html that are located
* in the document tool you must provide this)
* @param bool $print_title add title
* @param bool $complete_style show header and footer if true
* @param bool $addStyle
* @param string $mainTitle
* @param bool $generateToFile Optional. When it is TRUE, then the output file is move to app/cache
*
* @throws \MpdfException
*
* @return false|null
*/
@ -202,7 +205,8 @@ class PDF
$print_title = false,
$complete_style = true,
$addStyle = true,
$mainTitle = ''
$mainTitle = '',
$generateToFile = false
) {
if (empty($html_file_array)) {
return false;
@ -365,7 +369,12 @@ class PDF
$output_file = $pdf_name.'.pdf';
}
// F to save the pdf in a file
@$this->pdf->Output($output_file, 'D');
@$this->pdf->Output($output_file, $generateToFile ? 'F' : 'D');
if ($generateToFile) {
rename(getcwd()."/$output_file", api_get_path(SYS_ARCHIVE_PATH).$output_file);
}
exit;
}

Loading…
Cancel
Save