diff --git a/classes/template.php b/classes/template.php index ded8163..595fc70 100644 --- a/classes/template.php +++ b/classes/template.php @@ -50,6 +50,8 @@ class template { */ protected $contextid; + protected $html; + /** * The constructor. * @@ -59,6 +61,7 @@ class template { $this->id = $template->id; $this->name = $template->name; $this->contextid = $template->contextid; + $this->html = $template->html; } /** @@ -310,17 +313,22 @@ class template { $orientation = 'P'; } $pdf->AddPage($orientation, array($page->width, $page->height)); - $pdf->SetMargins($page->leftmargin, 0, $page->rightmargin); - // Get the elements for the page. - if ($elements = $DB->get_records('customcert_elements', array('pageid' => $page->id), 'sequence ASC')) { - // Loop through and display. - foreach ($elements as $element) { - // Get an instance of the element class. - if ($e = \mod_customcert\element_factory::get_element_instance($element)) { - $e->render($pdf, $preview, $user); - } - } - } + + if ($this->html) { + $pdf->WriteHTML($this->html); + } else { + $pdf->SetMargins($page->leftmargin, 0, $page->rightmargin); + // Get the elements for the page. + if ($elements = $DB->get_records('customcert_elements', array('pageid' => $page->id), 'sequence ASC')) { + // Loop through and display. + foreach ($elements as $element) { + // Get an instance of the element class. + if ($e = \mod_customcert\element_factory::get_element_instance($element)) { + $e->render($pdf, $preview, $user); + } + } + } + } } if ($return) { @@ -339,6 +347,9 @@ class template { public function copy_to_template($copytotemplateid) { global $DB; + $copytotemplate = $DB->get_records('customcert_templates', array('id' => $copytotemplateid)); + $copytotemplate->html = $this->html; + // Get the pages for the template, there should always be at least one page for each template. if ($templatepages = $DB->get_records('customcert_pages', array('templateid' => $this->id))) { // Loop through the pages. @@ -431,6 +442,10 @@ class template { return $this->name; } + public function get_html() { + return $this->html; + } + /** * Returns the context id. * diff --git a/db/install.xml b/db/install.xml index f6368b3..233fb9e 100644 --- a/db/install.xml +++ b/db/install.xml @@ -1,5 +1,5 @@ - @@ -10,7 +10,7 @@ - + @@ -34,6 +34,7 @@ + @@ -77,7 +78,7 @@ - + diff --git a/db/upgrade.php b/db/upgrade.php index 701e819..dc1ff3c 100644 --- a/db/upgrade.php +++ b/db/upgrade.php @@ -184,7 +184,19 @@ function xmldb_customcert_upgrade($oldversion) { $dbman->add_field($table, $field); - upgrade_mod_savepoint(true, 2021051702, 'customcert'); // Replace with the actual version number. + upgrade_mod_savepoint(true, 2021051702, 'customcert'); + } + + if ($oldversion < 2021110501) { + $table = new xmldb_table('customcert_templates'); + $field = new xmldb_field('html', XMLDB_TYPE_TEXT, null, null, null, null, null, 'timemodified'); + + // Conditionally launch add field html. + if (!$dbman->field_exists($table, $field)) { + $dbman->add_field($table, $field); + } + + upgrade_mod_savepoint(true, 2021110501, 'customcert'); } return true; diff --git a/version.php b/version.php index 12b71b5..72bb0ac 100644 --- a/version.php +++ b/version.php @@ -24,10 +24,10 @@ defined('MOODLE_INTERNAL') || die('Direct access to this script is forbidden.'); -$plugin->version = 2021051702; // The current module version (Date: YYYYMMDDXX). +$plugin->version = 2021110501; // The current module version (Date: YYYYMMDDXX). $plugin->requires = 2021051700; // Requires this Moodle version (3.11). $plugin->cron = 0; // Period for cron to check this module (secs). $plugin->component = 'mod_customcert'; $plugin->maturity = MATURITY_STABLE; -$plugin->release = "3.11.1"; // User-friendly version number. +$plugin->release = "3.11.1-seachefs"; // User-friendly version number.