Gradebook: Export certificate list using CLI - refs BT#18279

pull/3757/head
Angel Fernando Quiroz Campos 5 years ago
parent 1ed046f462
commit e637f503e1
  1. 13
      main/gradebook/certificate_report.php
  2. 58
      main/gradebook/gradebook_display_certificate.php
  3. 60
      main/gradebook/lib/GradebookUtils.php
  4. 49
      main/inc/ajax/gradebook.ajax.php
  5. 6
      main/template/default/gradebook/certificate_report.tpl

@ -129,14 +129,11 @@ if ($searchSessionAndCourse || $searchCourseOnly) {
}
if (!is_null($gradebook)) {
$exportAllLink = api_get_path(WEB_CODE_PATH)."gradebook/gradebook_display_certificate.php?";
$exportAllLink .= http_build_query([
"action" => "export_all_certificates",
"cidReq" => $selectedCourseInfo['code'],
"id_session" => 0,
"gidReq" => 0,
"cat_id" => $gradebook->get_id(),
]);
$exportAllLink = GradebookUtils::returnJsExportAllCertificates(
'#btn-export-all',
$gradebook->get_id(),
$selectedCourseInfo['code']
);
$sessionName = api_get_session_name($selectedSession);
$courseName = api_get_course_info($selectedCourseInfo['code'])['title'];

@ -125,31 +125,6 @@ switch ($action) {
);
$content = $form->returnForm();
break;
case 'export_all_certificates':
if ($allowCustomCertificate) {
$params = 'course_code='.api_get_course_id().
'&session_id='.api_get_session_id().
'&'.api_get_cidreq().
'&cat_id='.$categoryId;
$url = api_get_path(WEB_PLUGIN_PATH).
'customcertificate/src/print_certificate.php?export_all_in_one=1&'.$params;
} else {
if (api_is_student_boss()) {
$userGroup = new UserGroup();
$userList = $userGroup->getGroupUsersByUser(api_get_user_id());
} else {
$userList = [];
if (!empty($filterOfficialCodeGet)) {
$userList = UserManager::getUsersByOfficialCode($filterOfficialCodeGet);
}
}
Category::exportAllCertificates($categoryId, $userList);
}
header('Location: '.$url);
exit;
break;
case 'export_all_certificates_zip':
if ($allowCustomCertificate) {
$params = 'course_code='.api_get_course_id().
@ -280,10 +255,27 @@ $actions .= Display::url(
$hideCertificateExport = api_get_setting('hide_certificate_export_link');
if (count($certificate_list) > 0 && $hideCertificateExport !== 'true') {
$actions .= Display::url(
Display::return_icon('pdf.png', get_lang('ExportAllCertificatesToPDF'), [], ICON_SIZE_MEDIUM),
$url.'&action=export_all_certificates'
);
if ($allowCustomCertificate) {
$actions = Display::url(
Display::return_icon('pdf.png', get_lang('ExportAllCertificatesToPDF'), [], ICON_SIZE_MEDIUM),
api_get_path(WEB_PLUGIN_PATH)
.'customcertificate/src/print_certificate.php?'.api_get_cidreq().'&'
.http_build_query(
[
'export_all_in_one' => 1,
'course_code' => api_get_course_id(),
'session_id' => api_get_session_id(),
'cat_id' => $categoryId,
]
)
);
} else {
$actions .= Display::url(
Display::return_icon('pdf.png', get_lang('ExportAllCertificatesToPDF'), [], ICON_SIZE_MEDIUM),
'#',
['id' => 'btn-export-all']
);
}
if ($allowCustomCertificate) {
$actions .= Display::url(
@ -350,5 +342,13 @@ if (count($certificate_list) == 0) {
}
echo '</tbody>';
echo '</table>';
echo GradebookUtils::returnJsExportAllCertificates(
'#btn-export-all',
$categoryId,
api_get_course_id(),
api_get_session_id(),
$filterOfficialCodeGet
);
}
Display::display_footer();

@ -1704,4 +1704,64 @@ class GradebookUtils
Database::update($table, $params, ['id = ?' => $commentInfo['id']]);
}
}
public static function returnJsExportAllCertificates(
$buttonSelector,
$categoryId,
$courseCode,
$sessionId = 0,
$filterOfficialCodeGet = null
) {
$params = [
'a' => 'export_all_certificates',
'cat_id' => $categoryId,
'cidReq' => $courseCode,
'id_session' => $sessionId,
'filter' => $filterOfficialCodeGet,
];
$urlExportAll = 'gradebook.ajax.php?'.http_build_query($params);
$params['a'] = 'verify_export_all_certificates';
$urlVerifyExportAll = 'gradebook.ajax.php?'.http_build_query($params);
$imgSrcLoading = api_get_path(WEB_LIBRARY_JS_PATH).'loading.gif';
$imgSrcPdf = Display::return_icon('pdf.png', '', [], ICON_SIZE_MEDIUM, false, true);
return "<script>
$(function () {
var \$btnExport = $('$buttonSelector'),
interval = 0;
function verifyExportSuccess (response) {
if (response.length > 0) {
\$btnExport.find('img').prop('src', '$imgSrcPdf');
window.clearInterval(interval);
window.removeEventListener('beforeunload', onbeforeunloadListener);
window.location.href = response;
}
}
function exportAllSuccess () {
interval = window.setInterval(
function () {
$.ajax(_p.web_ajax + '$urlVerifyExportAll').then(verifyExportSuccess);
},
15000
);
}
function onbeforeunloadListener (e) {
e.preventDefault();
e.returnValue = '';
}
\$btnExport.on('click', function (e) {
e.preventDefault();
\$btnExport.find('img').prop({src: '$imgSrcLoading', width: 40, height: 40});
window.addEventListener('beforeunload', onbeforeunloadListener);
$.ajax(_p.web_ajax + '$urlExportAll').then(exportAllSuccess);
});
});
</script>";
}
}

@ -55,6 +55,55 @@ switch ($action) {
$form->display();
}
break;*/
case 'export_all_certificates':
$categoryId = (int) $_GET['cat_id'];
$filterOfficialCodeGet = isset($_GET['filter']) ? Security::remove_XSS($_GET['filter']) : null;
if (api_is_student_boss()) {
$userGroup = new UserGroup();
$userList = $userGroup->getGroupUsersByUser(api_get_user_id());
} else {
$userList = [];
if (!empty($filterOfficialCodeGet)) {
$userList = UserManager::getUsersByOfficialCode($filterOfficialCodeGet);
}
}
$courseCode = api_get_course_id();
$sessionId = api_get_session_id();
$commandScript = api_get_path(SYS_CODE_PATH).'gradebook/cli/export_all_certificates.php';
shell_exec("php $commandScript $courseCode $sessionId $categoryId > /dev/null &");
break;
case 'verify_export_all_certificates':
$categoryId = (int) $_GET['cat_id'];
$courseCode = isset($_GET['cidReq']) ? Security::remove_XSS($_GET['cidReq']) : api_get_course_id();
$sessionId = isset($_GET['id_session']) ? (int) $_GET['id_session'] : api_get_session_id();
$filterOfficialCodeGet = isset($_GET['filter']) ? Security::remove_XSS($_GET['filter']) : null;
if (api_is_student_boss()) {
$userGroup = new UserGroup();
$userList = $userGroup->getGroupUsersByUser(api_get_user_id());
} else {
$userList = [];
if (!empty($filterOfficialCodeGet)) {
$userList = UserManager::getUsersByOfficialCode($filterOfficialCodeGet);
}
}
$date = api_get_utc_datetime(null, false, true);
$pdfName = 'certs_'.$courseCode.'_'.$sessionId.'_'.$categoryId.'_'.$date->format('Y-m-d');
$sysFinalFile = api_get_path(SYS_ARCHIVE_PATH)."$pdfName.pdf";
$webFinalFile = api_get_path(WEB_ARCHIVE_PATH)."$pdfName.pdf";
if (file_exists($sysFinalFile)) {
echo $webFinalFile;
}
break;
default:
echo '';
break;

@ -38,10 +38,12 @@ $(document).on('ready', function () {
<h2 class="page-header">{{ "GradebookListOfStudentsCertificates" | get_lang }}</h2>
{% if not export_all_link is null %}
<div class="actions">
<a href="{{ export_all_link }}" class="btn btn-info">
<em class="fa fa-check"></em> {{ 'ExportAllCertificatesToPDF' | get_lang }}
<a href="#" id="btn-export-all">
{{ 'pdf.png'|img(32, 'ExportAllCertificatesToPDF'|get_lang) }}
</a>
</div>
{{ export_all_link }}
{% endif %}
<table class="table table-striped">

Loading…
Cancel
Save