From a3c2a6f0ffccd296cb616320ccc93dc709985843 Mon Sep 17 00:00:00 2001 From: Matheus Garcia Date: Tue, 28 May 2019 18:22:24 -0300 Subject: [PATCH] =?UTF-8?q?Flexibiliza=C3=A7=C3=A3o=20para=20certificados?= =?UTF-8?q?=20com=20assinaturas=20diferentes=20conforme=20data=20de=20conc?= =?UTF-8?q?lus=C3=A3o?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- locallib.php | 23 +++++++++++++++++++---- type/ILB_Sem_tutoria_2014/certificate.php | 5 +++-- 2 files changed, 22 insertions(+), 6 deletions(-) diff --git a/locallib.php b/locallib.php index 97e0f1b..e9bf1d4 100644 --- a/locallib.php +++ b/locallib.php @@ -1158,8 +1158,8 @@ function certificate_draw_frame_letter($pdf, $certificate) { * @param int $w the width * @param int $h the height */ -function certificate_print_image($pdf, $certificate, $type, $x, $y, $w, $h) { - global $CFG; +function certificate_print_image($pdf, $certificate, $type, $x, $y, $w, $h, $cert_date = null) { + global $CFG, $DB; switch($type) { case CERT_IMAGE_BORDER : @@ -1172,10 +1172,25 @@ function certificate_print_image($pdf, $certificate, $type, $x, $y, $w, $h) { $path = "$CFG->dirroot/mod/certificate/pix/$type/$certificate->printseal"; $uploadpath = "$CFG->dataroot/mod/certificate/pix/$type/$certificate->printseal"; break; + case CERT_IMAGE_SIGNATURE : $attr = 'printsignature'; - $path = "$CFG->dirroot/mod/certificate/pix/$type/$certificate->printsignature"; - $uploadpath = "$CFG->dataroot/mod/certificate/pix/$type/$certificate->printsignature"; + + if($certificate->printsignature == 'automatica.jpeg' && ($cert_date != null)) { + $record = $DB->get_record_sql( + 'SELECT nome_arquivo ' . + 'FROM {ilb_assinaturas} ' . + 'WHERE ? BETWEEN dat_ini_validade AND coalesce(dat_fim_validade, extract(epoch from current_timestamp))', + [$cert_date] + ); + + $arq_assinatura = $record->nome_arquivo; + }else { + $arq_assinatura = $certificate->printsignature; + } + $path = "$CFG->dirroot/mod/certificate/pix/$type/$arq_assinatura"; + $uploadpath = "$CFG->dataroot/mod/certificate/pix/$type/$arq_assinatura"; + break; case CERT_IMAGE_WATERMARK : $attr = 'printwmark'; diff --git a/type/ILB_Sem_tutoria_2014/certificate.php b/type/ILB_Sem_tutoria_2014/certificate.php index 1388105..332ed45 100644 --- a/type/ILB_Sem_tutoria_2014/certificate.php +++ b/type/ILB_Sem_tutoria_2014/certificate.php @@ -38,10 +38,11 @@ require_once("$CFG->dirroot/enrol/locallib.php"); $cc = new completion_completion(array('userid'=>$USER->id, 'course'=>$course->id)); $enrol_manager = new course_enrolment_manager($PAGE, $course); -$user_enrol = end($enrol_manager->get_user_enrolments($USER->id)); +$user_enrol = $enrol_manager->get_user_enrolments($USER->id); $start_date = $user_enrol->timestart; $end_date = $cc->timecompleted; +$cert_date = $end_date; $fmt = '%d/%m/%Y'; // Default format if ($certificate->datefmt == 1) { @@ -143,7 +144,7 @@ $pdf->SetAlpha(0.2); certificate_print_image($pdf, $certificate, CERT_IMAGE_WATERMARK, $wmarkx, $wmarky, $wmarkw, $wmarkh); $pdf->SetAlpha(1); certificate_print_image($pdf, $certificate, CERT_IMAGE_SEAL, $sealx, $sealy, '', ''); -certificate_print_image($pdf, $certificate, CERT_IMAGE_SIGNATURE, $sigx, $sigy, '', ''); +certificate_print_image($pdf, $certificate, CERT_IMAGE_SIGNATURE, $sigx, $sigy, '', '', $cert_date); // Add text $pdf->SetTextColor(0, 0, 0);