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.
This commit is contained in:
Mark Nelson 2013-07-25 18:41:16 +08:00
parent 23d611de1b
commit 8b92d1c307
5 changed files with 13 additions and 19 deletions

View file

@ -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.

View file

@ -37,7 +37,6 @@
<FIELDS>
<FIELD NAME="id" TYPE="int" LENGTH="10" NOTNULL="true" SEQUENCE="true" ENUM="false"/>
<FIELD NAME="customcertid" TYPE="int" LENGTH="10" NOTNULL="true" DEFAULT="0" SEQUENCE="false" ENUM="false"/>
<FIELD NAME="orientation" TYPE="char" LENGTH="10" NOTNULL="true" SEQUENCE="false" ENUM="false"/>
<FIELD NAME="width" TYPE="int" LENGTH="10" NOTNULL="true" DEFAULT="0" SEQUENCE="false" ENUM="false"/>
<FIELD NAME="height" TYPE="int" LENGTH="10" NOTNULL="true" DEFAULT="0" SEQUENCE="false" ENUM="false"/>
<FIELD NAME="pagenumber" TYPE="int" LENGTH="10" NOTNULL="false" SEQUENCE="false" ENUM="false"/>
@ -85,7 +84,6 @@
<FIELDS>
<FIELD NAME="id" TYPE="int" LENGTH="10" NOTNULL="true" SEQUENCE="true" ENUM="false"/>
<FIELD NAME="templateid" TYPE="int" LENGTH="10" NOTNULL="true" DEFAULT="0" SEQUENCE="false" ENUM="false"/>
<FIELD NAME="orientation" TYPE="char" LENGTH="10" NOTNULL="true" SEQUENCE="false" ENUM="false"/>
<FIELD NAME="width" TYPE="int" LENGTH="10" NOTNULL="true" DEFAULT="0" SEQUENCE="false" ENUM="false"/>
<FIELD NAME="height" TYPE="int" LENGTH="10" NOTNULL="true" DEFAULT="0" SEQUENCE="false" ENUM="false"/>
<FIELD NAME="pagenumber" TYPE="int" LENGTH="10" NOTNULL="false" SEQUENCE="false" ENUM="false"/>

View file

@ -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');

View file

@ -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';

17
lib.php
View file

@ -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.