From 8b92d1c3070362db5d321df4f551d5840d5edbc5 Mon Sep 17 00:00:00 2001 From: Mark Nelson Date: Thu, 25 Jul 2013 18:41:16 +0800 Subject: [PATCH] Removed the orientation field as it is redundant considering the width and height are already specified Note: I did not create a db/upgrade.php script to remove the database column as this module should not be currently used by anyone. --- backup/moodle2/backup_customcert_stepslib.php | 2 +- db/install.xml | 2 -- edit_form.php | 9 --------- lang/en/customcert.php | 2 -- lib.php | 17 ++++++++++++----- 5 files changed, 13 insertions(+), 19 deletions(-) diff --git a/backup/moodle2/backup_customcert_stepslib.php b/backup/moodle2/backup_customcert_stepslib.php index 5812a7e..25c2500 100644 --- a/backup/moodle2/backup_customcert_stepslib.php +++ b/backup/moodle2/backup_customcert_stepslib.php @@ -49,7 +49,7 @@ class backup_customcert_activity_structure_step extends backup_activity_structur // The pages. $pages = new backup_nested_element('pages'); $page = new backup_nested_element('page', array('id'), array( - 'customcertid', 'orientation', 'width', 'height', 'pagenumber', + 'customcertid', 'width', 'height', 'pagenumber', 'timecreated', 'timemodified')); // The elements. diff --git a/db/install.xml b/db/install.xml index 50b0d56..517292e 100644 --- a/db/install.xml +++ b/db/install.xml @@ -37,7 +37,6 @@ - @@ -85,7 +84,6 @@ - diff --git a/edit_form.php b/edit_form.php index ee780a8..e1cedbe 100644 --- a/edit_form.php +++ b/edit_form.php @@ -111,9 +111,6 @@ class mod_customcert_edit_form extends moodleform { if ($pages = $DB->get_records('customcert_pages', array('customcertid' => $this->id))) { // Loop through the pages. foreach ($pages as $p) { - // Set the orientation. - $element = $mform->getElement('orientation_' . $p->id); - $element->setValue($p->orientation); // Set the width. $element = $mform->getElement('pagewidth_' . $p->id); $element->setValue($p->width); @@ -183,12 +180,6 @@ class mod_customcert_edit_form extends moodleform { $mform->addElement('html', $OUTPUT->action_icon($url, new pix_icon('t/down', get_string('movedown')))); } - $orientationoptions = array('L' => get_string('landscape', 'customcert'), - 'P' => get_string('portrait', 'customcert')); - $mform->addElement('select', 'orientation_' . $page->id, get_string('orientation', 'customcert'), $orientationoptions); - $mform->setDefault('orientation_' . $page->id, 'P'); - $mform->addHelpButton('orientation_' . $page->id, 'orientation', 'customcert'); - $mform->addElement('text', 'pagewidth_' . $page->id, get_string('width', 'customcert')); $mform->setType('pagewidth_' . $page->id, PARAM_INT); $mform->setDefault('pagewidth_' . $page->id, '210'); diff --git a/lang/en/customcert.php b/lang/en/customcert.php index 3ed3a88..f7e636a 100644 --- a/lang/en/customcert.php +++ b/lang/en/customcert.php @@ -74,8 +74,6 @@ $string['modulenameplural'] = 'Custom Certificates'; $string['name'] = 'Name'; $string['noimage'] = 'No image'; $string['options'] = 'Options'; -$string['orientation'] = 'Orientation'; -$string['orientation_help'] = 'Choose whether you want your certificate orientation to be portrait or landscape.'; $string['page'] = 'Page {$a}'; $string['pluginadministration'] = 'Custom Certificate administration'; $string['pluginname'] = 'Custom Certificate'; diff --git a/lib.php b/lib.php index dd34c8b..e215c87 100644 --- a/lib.php +++ b/lib.php @@ -489,13 +489,11 @@ function customcert_save_page_data($data) { // Loop through existing pages. foreach ($pages as $page) { // Get the name of the fields we want from the form. - $orientation = 'orientation_' . $page->id; $width = 'pagewidth_' . $page->id; $height = 'pageheight_' . $page->id; // Create the page data to update the DB with. $p = new stdClass(); $p->id = $page->id; - $p->orientation = $data->$orientation; $p->width = $data->$width; $p->height = $data->$height; $p->timemodified = $time; @@ -550,7 +548,6 @@ function customcert_add_page($data) { // New page creation. $page = new stdClass(); $page->customcertid = $data->id; - $page->orientation = 'P'; $page->width = '210'; $page->height = '297'; $page->pagenumber = $pagenumber; @@ -813,7 +810,12 @@ function customcert_generate_grid_pdf($pageid) { $pdf->SetAutoPageBreak(true, 0); // Add the page to the PDF. - $pdf->AddPage($page->orientation, array($page->width, $page->height)); + if ($page->width > $page->height) { + $orientation = 'L'; + } else { + $orientation = 'P'; + } + $pdf->AddPage($orientation, array($page->width, $page->height)); // The cell width. $cellwidth = 10; @@ -889,7 +891,12 @@ function customcert_generate_pdf($customcert, $preview = false) { // Loop through the pages and display their content. foreach ($pages as $page) { // Add the page to the PDF. - $pdf->AddPage($page->orientation, array($page->width, $page->height)); + if ($page->width > $page->height) { + $orientation = 'L'; + } else { + $orientation = 'P'; + } + $pdf->AddPage($orientation, array($page->width, $page->height)); // Get the elements for the page. if ($elements = $DB->get_records('customcert_elements', array('pageid' => $page->id), 'sequence ASC')) { // Loop through and display.