Implemented support for element alignment

Also specifying the reference point location (the
location of the element that's put at posx and
posy) for each element.
This commit is contained in:
Shamim Rezaie 2015-07-30 14:51:50 +10:00 committed by Mark Nelson
parent 7634568df1
commit 039e8bca37
7 changed files with 115 additions and 10 deletions

View file

@ -54,8 +54,9 @@ class backup_customcert_activity_structure_step extends backup_activity_structur
// The elements. // The elements.
$element = new backup_nested_element('element', array('id'), array( $element = new backup_nested_element('element', array('id'), array(
'pageid', 'name', 'element', 'data', 'font', 'size', 'colour', 'width', 'pageid', 'name', 'element', 'data', 'font', 'size',
'posx', 'posy', 'sequence', 'timecreated', 'timemodified')); 'colour', 'width', 'refpoint', 'align', 'posx',
'posy', 'sequence', 'timecreated', 'timemodified'));
// Build the tree. // Build the tree.
$customcert->add_child($issues); $customcert->add_child($issues);

View file

@ -62,6 +62,8 @@
<FIELD NAME="posx" TYPE="int" LENGTH="10" NOTNULL="false" SEQUENCE="false"/> <FIELD NAME="posx" TYPE="int" LENGTH="10" NOTNULL="false" SEQUENCE="false"/>
<FIELD NAME="posy" TYPE="int" LENGTH="10" NOTNULL="false" SEQUENCE="false"/> <FIELD NAME="posy" TYPE="int" LENGTH="10" NOTNULL="false" SEQUENCE="false"/>
<FIELD NAME="width" TYPE="int" LENGTH="10" NOTNULL="false" SEQUENCE="false"/> <FIELD NAME="width" TYPE="int" LENGTH="10" NOTNULL="false" SEQUENCE="false"/>
<FIELD NAME="refpoint" TYPE="int" LENGTH="4" NOTNULL="false" SEQUENCE="false"/>
<FIELD NAME="align" TYPE="char" LENGTH="1" NOTNULL="false" SEQUENCE="false"/>
<FIELD NAME="sequence" TYPE="int" LENGTH="10" NOTNULL="false" SEQUENCE="false"/> <FIELD NAME="sequence" TYPE="int" LENGTH="10" NOTNULL="false" SEQUENCE="false"/>
<FIELD NAME="timecreated" TYPE="int" LENGTH="10" NOTNULL="true" DEFAULT="0" SEQUENCE="false"/> <FIELD NAME="timecreated" TYPE="int" LENGTH="10" NOTNULL="true" DEFAULT="0" SEQUENCE="false"/>
<FIELD NAME="timemodified" TYPE="int" LENGTH="10" NOTNULL="true" DEFAULT="0" SEQUENCE="false"/> <FIELD NAME="timemodified" TYPE="int" LENGTH="10" NOTNULL="true" DEFAULT="0" SEQUENCE="false"/>
@ -111,6 +113,8 @@
<FIELD NAME="posx" TYPE="int" LENGTH="10" NOTNULL="false" SEQUENCE="false"/> <FIELD NAME="posx" TYPE="int" LENGTH="10" NOTNULL="false" SEQUENCE="false"/>
<FIELD NAME="posy" TYPE="int" LENGTH="10" NOTNULL="false" SEQUENCE="false"/> <FIELD NAME="posy" TYPE="int" LENGTH="10" NOTNULL="false" SEQUENCE="false"/>
<FIELD NAME="width" TYPE="int" LENGTH="10" NOTNULL="false" SEQUENCE="false"/> <FIELD NAME="width" TYPE="int" LENGTH="10" NOTNULL="false" SEQUENCE="false"/>
<FIELD NAME="refpoint" TYPE="int" LENGTH="4" NOTNULL="false" SEQUENCE="false"/>
<FIELD NAME="align" TYPE="char" LENGTH="1" NOTNULL="false" SEQUENCE="false"/>
<FIELD NAME="sequence" TYPE="int" LENGTH="10" NOTNULL="false" SEQUENCE="false"/> <FIELD NAME="sequence" TYPE="int" LENGTH="10" NOTNULL="false" SEQUENCE="false"/>
<FIELD NAME="timecreated" TYPE="int" LENGTH="10" NOTNULL="true" DEFAULT="0" SEQUENCE="false"/> <FIELD NAME="timecreated" TYPE="int" LENGTH="10" NOTNULL="true" DEFAULT="0" SEQUENCE="false"/>
<FIELD NAME="timemodified" TYPE="int" LENGTH="10" NOTNULL="true" DEFAULT="0" SEQUENCE="false"/> <FIELD NAME="timemodified" TYPE="int" LENGTH="10" NOTNULL="true" DEFAULT="0" SEQUENCE="false"/>

View file

@ -28,7 +28,7 @@ function xmldb_customcert_upgrade($oldversion=0) {
global $CFG, $DB; global $CFG, $DB;
$dbman = $DB->get_manager(); $dbman = $DB->get_manager();
if ($oldversion < 2015072700) { if ($oldversion < 2015073000) {
// Add the margin fields to customcert_pages table // Add the margin fields to customcert_pages table
$table = new xmldb_table('customcert_pages'); $table = new xmldb_table('customcert_pages');
$field = new xmldb_field('margin', XMLDB_TYPE_INTEGER, 10, null, null, null, 0, 'height'); $field = new xmldb_field('margin', XMLDB_TYPE_INTEGER, 10, null, null, null, 0, 'height');
@ -43,22 +43,44 @@ function xmldb_customcert_upgrade($oldversion=0) {
$dbman->add_field($table, $field); $dbman->add_field($table, $field);
} }
// Add the width fields to customcert_elements table // Retrieve the customcert_elements table to add some elements to it
$table = new xmldb_table('customcert_elements'); $table = new xmldb_table('customcert_elements');
// Add the width fields to customcert_elements table
$field = new xmldb_field('width', XMLDB_TYPE_INTEGER, 10, null, null, null, 0, 'posy'); $field = new xmldb_field('width', XMLDB_TYPE_INTEGER, 10, null, null, null, 0, 'posy');
if (!$dbman->field_exists($table, $field)) { if (!$dbman->field_exists($table, $field)) {
$dbman->add_field($table, $field); $dbman->add_field($table, $field);
} }
// Add the refpoint fields to customcert_elements table.
$field = new xmldb_field('refpoint', XMLDB_TYPE_INTEGER, 4, null, null, null, 0, 'width');
if (!$dbman->field_exists($table, $field)) {
$dbman->add_field($table, $field);
}
// Add the align fields to customcert_elements table.
$field = new xmldb_field('align', XMLDB_TYPE_CHAR, 1, null, null, null, 0, 'refpoint');
if (!$dbman->field_exists($table, $field)) {
$dbman->add_field($table, $field);
}
// Add the width fields to customcert_template_elements table // Retrieve the customcert_template_elements table to add some elements to it
$table = new xmldb_table('customcert_template_elements'); $table = new xmldb_table('customcert_template_elements');
// Add the width fields to customcert_template_elements table
$field = new xmldb_field('width', XMLDB_TYPE_INTEGER, 10, null, null, null, 0, 'posy'); $field = new xmldb_field('width', XMLDB_TYPE_INTEGER, 10, null, null, null, 0, 'posy');
if (!$dbman->field_exists($table, $field)) { if (!$dbman->field_exists($table, $field)) {
$dbman->add_field($table, $field); $dbman->add_field($table, $field);
} }
// Add the refpoint fields to customcert_template_elements table.
$field = new xmldb_field('refpoint', XMLDB_TYPE_INTEGER, 4, null, null, null, 0, 'width');
if (!$dbman->field_exists($table, $field)) {
$dbman->add_field($table, $field);
}
// Add the align fields to customcert_template_elements table.
$field = new xmldb_field('align', XMLDB_TYPE_CHAR, 1, null, null, null, 0, 'refpoint');
if (!$dbman->field_exists($table, $field)) {
$dbman->add_field($table, $field);
}
// Customcert savepoint reached. // Customcert savepoint reached.
upgrade_mod_savepoint(true, 2015072700, 'customcert'); upgrade_mod_savepoint(true, 2015073000, 'customcert');
} }
return true; return true;

View file

@ -114,6 +114,8 @@ abstract class customcert_element_base {
$element->posx = (isset($data->posx)) ? $data->posx : null; $element->posx = (isset($data->posx)) ? $data->posx : null;
$element->posy = (isset($data->posy)) ? $data->posy : null; $element->posy = (isset($data->posy)) ? $data->posy : null;
$element->width = (isset($data->width)) ? $data->width : null; $element->width = (isset($data->width)) ? $data->width : null;
$element->refpoint = (isset($data->refpoint)) ? $data->refpoint : null;
$element->align = (isset($data->align)) ? $data->align : null;
$element->timemodified = time(); $element->timemodified = time();
// Check if we are updating, or inserting a new element. // Check if we are updating, or inserting a new element.
@ -184,7 +186,36 @@ abstract class customcert_element_base {
$this->set_font($pdf); $this->set_font($pdf);
$fontcolour = TCPDF_COLORS::convertHTMLColorToDec($this->element->colour, $fontcolour); $fontcolour = TCPDF_COLORS::convertHTMLColorToDec($this->element->colour, $fontcolour);
$pdf->SetTextColor($fontcolour['R'], $fontcolour['G'], $fontcolour['B']); $pdf->SetTextColor($fontcolour['R'], $fontcolour['G'], $fontcolour['B']);
$pdf->writeHTMLCell($this->element->width, 0, $this->element->posx, $this->element->posy, $content);
$x = $this->element->posx;
$y = $this->element->posy;
$w = $this->element->width;
$align = $this->element->align;
$refpoint = $this->element->refpoint;
$actualwidth = $pdf->GetStringWidth($content);
if ($w and $w < $actualwidth) {
$actualwidth = $w;
}
switch ($refpoint) {
case CUSTOMCERT_REF_POINT_TOPRIGHT:
$x = $this->element->posx - $actualwidth;
if ($x < 0) {
$x = 0;
$w = $this->element->posx;
}
break;
case CUSTOMCERT_REF_POINT_TOPCENTER:
$x = $this->element->posx - $actualwidth / 2;
if ($x < 0) {
$x = 0;
$w = $this->element->posx * 2;
}
break;
}
$pdf->writeHTMLCell($w, 0, $x, $y, $content, 0, 0, true, true, $align);
} }
/** /**
@ -272,6 +303,27 @@ abstract class customcert_element_base {
$mform->setType('width', PARAM_INT); $mform->setType('width', PARAM_INT);
$mform->setDefault('width', ''); $mform->setDefault('width', '');
$mform->addHelpButton('width', 'elementwidth', 'customcert'); $mform->addHelpButton('width', 'elementwidth', 'customcert');
$refpointoptions = array();
$refpointoptions[CUSTOMCERT_REF_POINT_TOPLEFT] = get_string('topleft', 'customcert');
$refpointoptions[CUSTOMCERT_REF_POINT_TOPCENTER] = get_string('topcenter', 'customcert');
$refpointoptions[CUSTOMCERT_REF_POINT_TOPRIGHT] = get_string('topright', 'customcert');
$mform->addElement('select', 'refpoint', get_string('refpoint', 'customcert'), $refpointoptions);
$mform->setType('refpoint', PARAM_INT);
$mform->setDefault('refpoint', '');
$mform->addHelpButton('refpoint', 'refpoint', 'customcert');
$alignoptions = array();
$alignoptions[''] = get_string('alignnone', 'customcert');
$alignoptions['L'] = get_string('alignleft', 'customcert');
$alignoptions['C'] = get_string('aligncenter', 'customcert');
$alignoptions['R'] = get_string('alignright', 'customcert');
$mform->addElement('select', 'align', get_string('align', 'customcert'), $alignoptions);
$mform->setType('align', PARAM_ALPHA);
$mform->setDefault('align', '');
$mform->addHelpButton('align', 'align', 'customcert');
} }
/** /**

View file

@ -24,6 +24,12 @@
$string['addcertpage'] = 'Add another certificate page'; $string['addcertpage'] = 'Add another certificate page';
$string['addelement'] = 'Add element'; $string['addelement'] = 'Add element';
$string['align'] = 'Alignment';
$string['align_help'] = 'Alignment Help';
$string['aligncenter'] = 'Center';
$string['alignleft'] = 'Left align';
$string['alignnone'] = 'No alignment';
$string['alignright'] = 'Right align';
$string['awardedto'] = 'Awarded to'; $string['awardedto'] = 'Awarded to';
$string['code'] = 'Code'; $string['code'] = 'Code';
$string['copy'] = 'Copy'; $string['copy'] = 'Copy';
@ -88,10 +94,12 @@ $string['pluginname'] = 'Custom Certificate';
$string['print'] = 'Print'; $string['print'] = 'Print';
$string['portrait'] = 'Portrait'; $string['portrait'] = 'Portrait';
$string['posx'] = 'Position X'; $string['posx'] = 'Position X';
$string['posx_help'] = 'This is the position in mm from the top left corner you wish the element to display in the x direction.'; $string['posx_help'] = 'This is the position in mm from the top left corner you wish the element\'s reference point to locate in the x direction.';
$string['posy'] = 'Postion Y'; $string['posy'] = 'Postion Y';
$string['posy_help'] = 'This is the position in mm from the top left corner you wish the element to display in the y direction.'; $string['posy_help'] = 'This is the position in mm from the top left corner you wish the element\'s reference point to locate in the y direction.';
$string['receiveddate'] = 'Received date'; $string['receiveddate'] = 'Received date';
$string['refpoint'] = 'Reference point location';
$string['refpoint_help'] = 'This specifies which location of the element to be located at position X and position Y.';
$string['replacetemplate'] = 'Replace'; $string['replacetemplate'] = 'Replace';
$string['report'] = 'Report'; $string['report'] = 'Report';
$string['save'] = 'Save'; $string['save'] = 'Save';
@ -102,6 +110,9 @@ $string['setprotection_help'] = 'Choose the actions you wish to prevent users fr
$string['summaryofissue'] = 'Summary of issue'; $string['summaryofissue'] = 'Summary of issue';
$string['templatename'] = 'Template name'; $string['templatename'] = 'Template name';
$string['templatenameexists'] = 'That template name is currently in use, please choose another.'; $string['templatenameexists'] = 'That template name is currently in use, please choose another.';
$string['topcenter'] = 'Center';
$string['topleft'] = 'Top left';
$string['topright'] = 'Top right';
$string['type'] = 'Type'; $string['type'] = 'Type';
$string['uploadimage'] = 'Upload image'; $string['uploadimage'] = 'Upload image';
$string['uploadimagedesc'] = 'This link will take you to a new screen where you will be able to upload images. Images uploaded using $string['uploadimagedesc'] = 'This link will take you to a new screen where you will be able to upload images. Images uploaded using

View file

@ -50,6 +50,21 @@ define('CUSTOMCERT_PER_PAGE', 20);
*/ */
define('CUSTOMCERT_MAX_PER_PAGE', 300); define('CUSTOMCERT_MAX_PER_PAGE', 300);
/**
* @var int the top-left of element
*/
define('CUSTOMCERT_REF_POINT_TOPLEFT', 0);
/**
* @var int the top-center of element
*/
define('CUSTOMCERT_REF_POINT_TOPCENTER', 1);
/**
* @var int the top-left of element
*/
define('CUSTOMCERT_REF_POINT_TOPRIGHT', 2);
/** /**
* Handles setting the protection field for the customcert * Handles setting the protection field for the customcert
* *

View file

@ -24,7 +24,7 @@
defined('MOODLE_INTERNAL') || die('Direct access to this script is forbidden.'); defined('MOODLE_INTERNAL') || die('Direct access to this script is forbidden.');
$plugin->version = 2015072700; // The current module version (Date: YYYYMMDDXX). $plugin->version = 2015073000; // The current module version (Date: YYYYMMDDXX).
$plugin->requires = 2014051200; // Requires this Moodle version (2.7). $plugin->requires = 2014051200; // Requires this Moodle version (2.7).
$plugin->cron = 0; // Period for cron to check this module (secs). $plugin->cron = 0; // Period for cron to check this module (secs).
$plugin->component = 'mod_customcert'; $plugin->component = 'mod_customcert';