From 17459319e48b5899e24881f2514c2dd9bc19a9fa Mon Sep 17 00:00:00 2001 From: ricardoh34 Date: Fri, 3 Sep 2021 10:51:41 +0200 Subject: [PATCH 1/8] Update template.php Include name of student and name of the course in the PDF certificate so as to ease organization of the certificates downloaded, solving issue #455 --- classes/template.php | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/classes/template.php b/classes/template.php index ded81638..ac7750be 100644 --- a/classes/template.php +++ b/classes/template.php @@ -299,8 +299,15 @@ public function generate_pdf(bool $preview = false, int $userid = null, bool $re if (empty($filename)) { $filename = get_string('certificate', 'customcert'); } - - $filename = clean_filename($filename . '.pdf'); + + $sql = "SELECT course,fullname + FROM {customcert} c, + {course} cr + WHERE c.id = :templateid + AND c.course = cr.id"; + $course = $DB->get_record_sql($sql, array('templateid' => $this->id)); + $filename = clean_filename($filename .'_'. fullname($USER) .'_'. $course->fullname . '.pdf'); + // Loop through the pages and display their content. foreach ($pages as $page) { // Add the page to the PDF. From ef0d6584e107ec222db9d843ffec6df469aa99e7 Mon Sep 17 00:00:00 2001 From: ricardoh34 Date: Fri, 17 Sep 2021 19:32:09 +0200 Subject: [PATCH 2/8] Update template.php MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Changed tabs and try to distinguish fullname and full_name. If still persists the error maybe we can´t use fullname($USER)? I have added also defined('moodle_internal') || die(); if that´s the problem. --- classes/template.php | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/classes/template.php b/classes/template.php index ac7750be..38157abc 100644 --- a/classes/template.php +++ b/classes/template.php @@ -255,15 +255,16 @@ public function delete_element($elementid) { */ public function generate_pdf(bool $preview = false, int $userid = null, bool $return = false) { global $CFG, $DB, $USER; + defined('MOODLE_INTERNAL') || die(); - if (empty($userid)) { + if (empty($userid)) { $user = $USER; } else { $user = \core_user::get_user($userid); } require_once($CFG->libdir . '/pdflib.php'); - + // Get the pages for the template, there should always be at least one page for each template. if ($pages = $DB->get_records('customcert_pages', array('templateid' => $this->id), 'sequence ASC')) { // Create the pdf object. @@ -300,13 +301,13 @@ public function generate_pdf(bool $preview = false, int $userid = null, bool $re $filename = get_string('certificate', 'customcert'); } - $sql = "SELECT course,fullname - FROM {customcert} c, - {course} cr - WHERE c.id = :templateid - AND c.course = cr.id"; - $course = $DB->get_record_sql($sql, array('templateid' => $this->id)); - $filename = clean_filename($filename .'_'. fullname($USER) .'_'. $course->fullname . '.pdf'); + $sql = "SELECT course,full_name + FROM {customcert} c, + {course} cr + WHERE c.id = :templateid + AND c.course = cr.id"; + $course = $DB->get_record_sql($sql, array('templateid' => $this->id)); + $filename = clean_filename($filename .'_'. fullname($USER) .'_'. $course->full_name . '.pdf'); // Loop through the pages and display their content. foreach ($pages as $page) { From 0f16d6a700acd616816fa3dc21c2c3a48bf154ec Mon Sep 17 00:00:00 2001 From: ricardoh34 Date: Thu, 30 Sep 2021 22:10:58 +0200 Subject: [PATCH 3/8] Add student name to PDF certificate file Add student name to PDF certificate file --- classes/template.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/classes/template.php b/classes/template.php index 38157abc..9f772eec 100644 --- a/classes/template.php +++ b/classes/template.php @@ -301,7 +301,7 @@ public function generate_pdf(bool $preview = false, int $userid = null, bool $re $filename = get_string('certificate', 'customcert'); } - $sql = "SELECT course,full_name + $sql = "SELECT course,fullname as full_name FROM {customcert} c, {course} cr WHERE c.id = :templateid From 81341f61b30a8fb07b834131b706f21ca0a026f0 Mon Sep 17 00:00:00 2001 From: ricardoh34 Date: Fri, 22 Oct 2021 22:30:16 +0200 Subject: [PATCH 4/8] Corrected mistakes from @mdjnelson comments @mdjnelson ammendments and corrections. I have changed full_name to fullname again. I expect everything works now. --- classes/template.php | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/classes/template.php b/classes/template.php index 9f772eec..c30364e8 100644 --- a/classes/template.php +++ b/classes/template.php @@ -255,8 +255,7 @@ public function delete_element($elementid) { */ public function generate_pdf(bool $preview = false, int $userid = null, bool $return = false) { global $CFG, $DB, $USER; - defined('MOODLE_INTERNAL') || die(); - + if (empty($userid)) { $user = $USER; } else { @@ -264,8 +263,7 @@ public function generate_pdf(bool $preview = false, int $userid = null, bool $re } require_once($CFG->libdir . '/pdflib.php'); - - // Get the pages for the template, there should always be at least one page for each template. + // Get the pages for the template, there should always be at least one page for each template. if ($pages = $DB->get_records('customcert_pages', array('templateid' => $this->id), 'sequence ASC')) { // Create the pdf object. $pdf = new \pdf(); @@ -301,13 +299,12 @@ public function generate_pdf(bool $preview = false, int $userid = null, bool $re $filename = get_string('certificate', 'customcert'); } - $sql = "SELECT course,fullname as full_name - FROM {customcert} c, - {course} cr - WHERE c.id = :templateid - AND c.course = cr.id"; + $sql = "SELECT course,fullname + FROM {customcert} c, {course} cr + WHERE c.id = :templateid + AND c.course = cr.id"; $course = $DB->get_record_sql($sql, array('templateid' => $this->id)); - $filename = clean_filename($filename .'_'. fullname($USER) .'_'. $course->full_name . '.pdf'); + $filename = clean_filename($filename .'_'. fullname($USER) .'_'. $course->fullname . '.pdf'); // Loop through the pages and display their content. foreach ($pages as $page) { From ebf4a1c09a81520e29829ef8fe958c9e55fa2432 Mon Sep 17 00:00:00 2001 From: ricardoh34 Date: Sun, 28 Nov 2021 12:19:27 +0100 Subject: [PATCH 5/8] Added new space in line 266 Added original space in line 266. --- classes/template.php | 1 + 1 file changed, 1 insertion(+) diff --git a/classes/template.php b/classes/template.php index c30364e8..2b27ef0b 100644 --- a/classes/template.php +++ b/classes/template.php @@ -263,6 +263,7 @@ public function generate_pdf(bool $preview = false, int $userid = null, bool $re } require_once($CFG->libdir . '/pdflib.php'); + // Get the pages for the template, there should always be at least one page for each template. if ($pages = $DB->get_records('customcert_pages', array('templateid' => $this->id), 'sequence ASC')) { // Create the pdf object. From d1ac2cbcbfd0971e84016de649ec02d07621f2da Mon Sep 17 00:00:00 2001 From: ricardoh34 Date: Wed, 21 Aug 2024 09:08:05 +0200 Subject: [PATCH 6/8] Erase tabs --- classes/template.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/classes/template.php b/classes/template.php index 2b27ef0b..e8ce803a 100644 --- a/classes/template.php +++ b/classes/template.php @@ -303,9 +303,9 @@ public function generate_pdf(bool $preview = false, int $userid = null, bool $re $sql = "SELECT course,fullname FROM {customcert} c, {course} cr WHERE c.id = :templateid - AND c.course = cr.id"; - $course = $DB->get_record_sql($sql, array('templateid' => $this->id)); - $filename = clean_filename($filename .'_'. fullname($USER) .'_'. $course->fullname . '.pdf'); + AND c.course = cr.id"; + $course = $DB->get_record_sql($sql, array('templateid' => $this->id)); + $filename = clean_filename($filename .'_'. fullname($USER) .'_'. $course->fullname . '.pdf'); // Loop through the pages and display their content. foreach ($pages as $page) { From 8abcab07e98d85bfaefe21037b7b86cc99f9588c Mon Sep 17 00:00:00 2001 From: ricardoh34 Date: Fri, 3 Sep 2021 10:51:41 +0200 Subject: [PATCH 7/8] Update template.php MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Include name of student and name of the course in the PDF certificate so as to ease organization of the certificates downloaded, solving issue #455 Erase tabs Added new space in line 266 Added original space in line 266. Corrected mistakes from @mdjnelson comments @mdjnelson ammendments and corrections. I have changed full_name to fullname again. I expect everything works now. Add student name to PDF certificate file Add student name to PDF certificate file Update template.php Changed tabs and try to distinguish fullname and full_name. If still persists the error maybe we can´t use fullname($USER)? I have added also defined('moodle_internal') || die(); if that´s the problem. --- classes/template.php | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/classes/template.php b/classes/template.php index ded81638..e8ce803a 100644 --- a/classes/template.php +++ b/classes/template.php @@ -255,16 +255,16 @@ public function delete_element($elementid) { */ public function generate_pdf(bool $preview = false, int $userid = null, bool $return = false) { global $CFG, $DB, $USER; - - if (empty($userid)) { + + if (empty($userid)) { $user = $USER; } else { $user = \core_user::get_user($userid); } require_once($CFG->libdir . '/pdflib.php'); - - // Get the pages for the template, there should always be at least one page for each template. + + // Get the pages for the template, there should always be at least one page for each template. if ($pages = $DB->get_records('customcert_pages', array('templateid' => $this->id), 'sequence ASC')) { // Create the pdf object. $pdf = new \pdf(); @@ -299,8 +299,14 @@ public function generate_pdf(bool $preview = false, int $userid = null, bool $re if (empty($filename)) { $filename = get_string('certificate', 'customcert'); } - - $filename = clean_filename($filename . '.pdf'); + + $sql = "SELECT course,fullname + FROM {customcert} c, {course} cr + WHERE c.id = :templateid + AND c.course = cr.id"; + $course = $DB->get_record_sql($sql, array('templateid' => $this->id)); + $filename = clean_filename($filename .'_'. fullname($USER) .'_'. $course->fullname . '.pdf'); + // Loop through the pages and display their content. foreach ($pages as $page) { // Add the page to the PDF. From 828689dec8ca83fc41fade263a5af166ad92b44e Mon Sep 17 00:00:00 2001 From: ricardoh34 Date: Mon, 26 Aug 2024 20:05:06 +0200 Subject: [PATCH 8/8] Update template.php --- classes/template.php | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/classes/template.php b/classes/template.php index e8ce803a..26f5d86b 100644 --- a/classes/template.php +++ b/classes/template.php @@ -255,16 +255,16 @@ public function delete_element($elementid) { */ public function generate_pdf(bool $preview = false, int $userid = null, bool $return = false) { global $CFG, $DB, $USER; - - if (empty($userid)) { + + if (empty($userid)) { $user = $USER; } else { $user = \core_user::get_user($userid); } require_once($CFG->libdir . '/pdflib.php'); - - // Get the pages for the template, there should always be at least one page for each template. + + // Get the pages for the template, there should always be at least one page for each template. if ($pages = $DB->get_records('customcert_pages', array('templateid' => $this->id), 'sequence ASC')) { // Create the pdf object. $pdf = new \pdf(); @@ -303,9 +303,9 @@ public function generate_pdf(bool $preview = false, int $userid = null, bool $re $sql = "SELECT course,fullname FROM {customcert} c, {course} cr WHERE c.id = :templateid - AND c.course = cr.id"; - $course = $DB->get_record_sql($sql, array('templateid' => $this->id)); - $filename = clean_filename($filename .'_'. fullname($USER) .'_'. $course->fullname . '.pdf'); + AND c.course = cr.id"; + $course = $DB->get_record_sql($sql, array('templateid' => $this->id)); + $filename = clean_filename($filename .'_'. fullname($USER) .'_'. $course->fullname . '.pdf'); // Loop through the pages and display their content. foreach ($pages as $page) {