Skip to content
Permalink
Browse files

Add certificate link + download certificate in a zip see BT#15017

when using the customcertificate plugin
  • Loading branch information...
jmontoyaa committed Nov 8, 2018
1 parent 73c50d1 commit f50ecb71057d7266da330089684ee4a6469729ed
@@ -391,6 +391,7 @@ public static function notificationTags()
'((author_last_name))',
'((score))',
'((portal_name))',
'((certificate_link))',
];
return $tags;
@@ -417,6 +418,8 @@ public static function sendNotification(
}
$currentUserInfo = api_get_user_info();
$url = api_get_path(WEB_PATH).'certificates/index.php?id='.$certificateInfo['id'].'&user_id='.$certificateInfo['user_id'];
$link = Display::url($url, $url);
$replace = [
$courseInfo['title'],
@@ -426,7 +429,9 @@ public static function sendNotification(
$currentUserInfo['lastname'],
$certificateInfo['score_certificate'],
api_get_setting('Institution'),
$link
];
$message = str_replace(self::notificationTags(), $replace, $message);
MessageManager::send_message(
@@ -259,7 +259,6 @@ public static function redirectCheck($certificate, $certId, $userId)
if (api_get_plugin_setting('customcertificate', 'enable_plugin_customcertificate') === 'true') {
$infoCertificate = self::getCertificateData($certId, $userId);
var_dump($infoCertificate);
if (!empty($infoCertificate)) {
if ($certificate->user_id == api_get_user_id() && !empty($certificate->certificate_data)) {
$certificateId = $certificate->certificate_data['id'];
@@ -108,22 +108,22 @@
'c_id' => $formValues['c_id'],
'session_id' => $formValues['session_id'],
'content_course' => $formValues['content_course'],
'contents_type' => intval($formValues['contents_type']),
'contents_type' => (int) $formValues['contents_type'],
'contents' => $contents,
'date_change' => intval($formValues['date_change']),
'date_start' => date("Y-m-d", strtotime($date_start)),
'date_end' => date("Y-m-d", strtotime($date_end)),
'place' => $formValues['place'],
'type_date_expediction' => intval($formValues['type_date_expediction']),
'type_date_expediction' => (int) $formValues['type_date_expediction'],
'day' => $formValues['day'],
'month' => $formValues['month'],
'year' => $formValues['year'],
'signature_text1' => $formValues['signature_text1'],
'signature_text2' => $formValues['signature_text2'],
'signature_text3' => $formValues['signature_text3'],
'signature_text4' => $formValues['signature_text4'],
'margin_left' => intval($formValues['margin_left']),
'margin_right' => intval($formValues['margin_right']),
'margin_left' => (int) $formValues['margin_left'],
'margin_right' => (int) $formValues['margin_right'],
'certificate_default' => 0,
];
@@ -5,7 +5,7 @@
$default = isset($_GET['default']) ? (int) $_GET['default'] : null;
if ($default == 1) {
if ($default === 1) {
$cidReset = true;
}
@@ -41,6 +41,8 @@
if (!empty($courseInfo)) {
$courseId = $courseInfo['real_id'];
}
} else {
$courseInfo = api_get_course_info($courseCode);
}
if (empty($sessionId)) {
@@ -116,17 +118,21 @@
$workSpace = intval(297 - $infoCertificate['margin_left'] - $infoCertificate['margin_right']);
$widthCell = intval($workSpace / 6);
$htmlText = '<html>';
$htmlText .= '
$htmlList = [];
$currentLocalTime = api_get_local_time();
foreach ($userList as $userInfo) {
$htmlText = '<html>';
$htmlText .= '
<link rel="stylesheet"
type="text/css"
href="'.api_get_path(WEB_PLUGIN_PATH).'customcertificate/resources/css/certificate.css">';
$htmlText .= '
$htmlText .= '
<link rel="stylesheet"
type="text/css"
href="'.api_get_path(WEB_CSS_PATH).'document.css">';
$htmlText .= '<body>';
foreach ($userList as $userInfo) {
$htmlText .= '<body>';
$studentId = $userInfo['user_id'];
if (empty($infoCertificate['background'])) {
@@ -248,8 +254,10 @@ class = "caraA"
);
}
} else {
$dateInfo = api_get_local_time($sessionInfo['access_end_date']);
$dateExpediction .= $plugin->get_lang('to').api_format_date($dateInfo, DATE_FORMAT_LONG);
if (!empty($sessionInfo)) {
$dateInfo = api_get_local_time($sessionInfo['access_end_date']);
$dateExpediction .= $plugin->get_lang('to').api_format_date($dateInfo, DATE_FORMAT_LONG);
}
}
}
@@ -465,24 +473,50 @@ class = "caraA"
}
$htmlText .= '</div>';
}
$htmlText .= '</body></html>';
$fileName = 'certificate_'.$courseInfo['code'].'_'.$userInfo['complete_name'].'_'.$currentLocalTime;
$htmlList[$fileName] = $htmlText;
}
$fileList = [];
$archivePath = api_get_path(SYS_ARCHIVE_PATH).'certificates/';
if (!is_dir($archivePath)) {
mkdir($archivePath, api_get_permissions_for_new_directories());
}
foreach ($htmlList as $fileName => $content) {
$fileName = api_replace_dangerous_char($fileName);
$params = [
'filename' => $fileName,
'pdf_title' => 'Certificate',
'pdf_description' => '',
'format' => 'A4-L',
'orientation' => 'L',
'left' => 15,
'top' => 15,
'bottom' => 0,
];
$pdf = new PDF($params['format'], $params['orientation'], $params);
if (count($htmlList) == 1) {
$pdf->content_to_pdf($content, '', $fileName, null, 'D', false, null, false, false, false);
exit;
} else {
$filePath = $archivePath.$fileName.'.pdf';
$pdf->content_to_pdf($content, '', $fileName, null, 'F', true, $filePath, false, false, false);
$fileList[] = $filePath;
}
}
if (!empty($fileList)) {
$zipFile = $archivePath.'certificates_'.api_get_unique_id().'.zip';
$zipFolder = new PclZip($zipFile);
foreach ($fileList as $file) {
$zipFolder->add($file, PCLZIP_OPT_REMOVE_ALL_PATH);
}
$name = 'certificates_'.$courseInfo['code'].'_'.$currentLocalTime.'.zip';
DocumentManager::file_send_for_download($zipFile, true, $name);
exit;
}
$htmlText .= '</body></html>';
$fileName = 'certificate_'.date('Ymd_His');
$params = [
'filename' => $fileName,
'pdf_title' => 'Certificate',
'pdf_description' => '',
'format' => 'A4-L',
'orientation' => 'L',
'left' => 15,
'top' => 15,
'bottom' => 0,
];
$pdf = new PDF($params['format'], $params['orientation'], $params);
$pdf->content_to_pdf($htmlText, '', $fileName, null, 'D', false, null, false, false, false);
exit;
function getIndexFiltered($index)
{
@@ -491,12 +525,16 @@ function getIndexFiltered($index)
$lines = explode(chr(13).chr(10), $txt);
$text1 = '';
for ($x = 0; $x < 47; $x++) {
$text1 .= $lines[$x].chr(13).chr(10);
if (isset($lines[$x])) {
$text1 .= $lines[$x].chr(13).chr(10);
}
}
$text2 = '';
for ($x = 47; $x < 94; $x++) {
$text2 .= $lines[$x].chr(13).chr(10);
if (isset($lines[$x])) {
$text2 .= $lines[$x].chr(13).chr(10);
}
}
$showLeft = str_replace(chr(13).chr(10), "<br/>", $text1);

0 comments on commit f50ecb7

Please sign in to comment.
You can’t perform that action at this time.