diff --git a/backup/moodle2/backup_customcert_stepslib.php b/backup/moodle2/backup_customcert_stepslib.php
index 78964fa..6705284 100644
--- a/backup/moodle2/backup_customcert_stepslib.php
+++ b/backup/moodle2/backup_customcert_stepslib.php
@@ -54,8 +54,9 @@ class backup_customcert_activity_structure_step extends backup_activity_structur
// The elements.
$element = new backup_nested_element('element', array('id'), array(
- 'pageid', 'name', 'element', 'data', 'font', 'size', 'colour', 'width',
- 'posx', 'posy', 'sequence', 'timecreated', 'timemodified'));
+ 'pageid', 'name', 'element', 'data', 'font', 'size',
+ 'colour', 'width', 'refpoint', 'align', 'posx',
+ 'posy', 'sequence', 'timecreated', 'timemodified'));
// Build the tree.
$customcert->add_child($issues);
diff --git a/db/install.xml b/db/install.xml
index ad17256..700032f 100644
--- a/db/install.xml
+++ b/db/install.xml
@@ -62,6 +62,8 @@
+
+
@@ -111,6 +113,8 @@
+
+
diff --git a/db/upgrade.php b/db/upgrade.php
index a488429..8cc8b5c 100644
--- a/db/upgrade.php
+++ b/db/upgrade.php
@@ -28,7 +28,7 @@ function xmldb_customcert_upgrade($oldversion=0) {
global $CFG, $DB;
$dbman = $DB->get_manager();
- if ($oldversion < 2015072700) {
+ if ($oldversion < 2015073000) {
// Add the margin fields to customcert_pages table
$table = new xmldb_table('customcert_pages');
$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);
}
- // 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');
+ // Add the width fields to customcert_elements table
$field = new xmldb_field('width', XMLDB_TYPE_INTEGER, 10, null, null, null, 0, 'posy');
if (!$dbman->field_exists($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');
+ // Add the width fields to customcert_template_elements table
$field = new xmldb_field('width', XMLDB_TYPE_INTEGER, 10, null, null, null, 0, 'posy');
if (!$dbman->field_exists($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.
- upgrade_mod_savepoint(true, 2015072700, 'customcert');
+ upgrade_mod_savepoint(true, 2015073000, 'customcert');
}
return true;
diff --git a/element/element.class.php b/element/element.class.php
index dd71b62..2aeea96 100644
--- a/element/element.class.php
+++ b/element/element.class.php
@@ -114,6 +114,8 @@ abstract class customcert_element_base {
$element->posx = (isset($data->posx)) ? $data->posx : null;
$element->posy = (isset($data->posy)) ? $data->posy : 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();
// Check if we are updating, or inserting a new element.
@@ -184,7 +186,36 @@ abstract class customcert_element_base {
$this->set_font($pdf);
$fontcolour = TCPDF_COLORS::convertHTMLColorToDec($this->element->colour, $fontcolour);
$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->setDefault('width', '');
$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');
}
/**
diff --git a/lang/en/customcert.php b/lang/en/customcert.php
index d681fb6..c2bde64 100644
--- a/lang/en/customcert.php
+++ b/lang/en/customcert.php
@@ -24,6 +24,12 @@
$string['addcertpage'] = 'Add another certificate page';
$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['code'] = 'Code';
$string['copy'] = 'Copy';
@@ -88,10 +94,12 @@ $string['pluginname'] = 'Custom Certificate';
$string['print'] = 'Print';
$string['portrait'] = 'Portrait';
$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_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['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['report'] = 'Report';
$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['templatename'] = 'Template name';
$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['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
diff --git a/locallib.php b/locallib.php
index 1ed0686..73b2d83 100644
--- a/locallib.php
+++ b/locallib.php
@@ -50,6 +50,21 @@ define('CUSTOMCERT_PER_PAGE', 20);
*/
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
*
diff --git a/version.php b/version.php
index bf15d40..a0209c8 100644
--- a/version.php
+++ b/version.php
@@ -24,7 +24,7 @@
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->cron = 0; // Period for cron to check this module (secs).
$plugin->component = 'mod_customcert';