diff --git a/edit_form.php b/edit_form.php
index 98dcae3..bcdb416 100644
--- a/edit_form.php
+++ b/edit_form.php
@@ -221,6 +221,11 @@ class mod_customcert_edit_form extends moodleform {
$mform->addRule('height_' . $pageid, null, 'required', null, 'client');
$mform->addHelpButton('height_' . $pageid, 'height', 'customcert');
+ $group = array();
+ $group[] = $mform->createElement('select', 'element_' . $pageid, '', $elementsavailable);
+ $group[] = $mform->createElement('submit', 'addelement_' . $pageid, get_string('addelement', 'customcert'));
+ $mform->addElement('group', 'elementgroup', '', $group, '', false);
+
// Check if there are elements to add.
if ($elements = $DB->get_records('customcert_elements', array('pageid' => $pageid), 'id ASC')) {
// Loop through and add the ones present.
@@ -229,6 +234,9 @@ class mod_customcert_edit_form extends moodleform {
// It's possible this element was added to the database then the folder was deleted, if
// this is the case we do not want to render these elements as an error will occur.
if (file_exists($classfile)) {
+ // Add the page number to the element so we can use within the element.
+ $element->pagenum = $pagenum;
+ // Get the classname.
$classname = "customcert_element_{$element->element}";
$e = new $classname($element);
$e->render_form_elements($mform);
@@ -240,11 +248,6 @@ class mod_customcert_edit_form extends moodleform {
}
}
- $group = array();
- $group[] = $mform->createElement('select', 'element_' . $pageid, '', $elementsavailable);
- $group[] = $mform->createElement('submit', 'addelement_' . $pageid, get_string('addelement', 'customcert'));
- $mform->addElement('group', 'elementgroup', '', $group, '', false);
-
// Add option to delete this page if it is not the first page.
if ($pagenum > 1) {
$mform->addElement('html', html_writer::start_tag('div', array('class' => 'deletecertpage')));
diff --git a/elements/element.class.php b/elements/element.class.php
index 4c5129a..b1f4847 100644
--- a/elements/element.class.php
+++ b/elements/element.class.php
@@ -70,39 +70,61 @@ class customcert_element_base {
/**
* This function renders the form elements when adding a customcert element.
- * Can be overridden if more functionality is needed.
+ * Must be overriden.
*
* @param stdClass $mform the edit_form instance.
* @return array the form elements
*/
public function render_form_elements($mform) {
- // Keep track of the number of times these elements have been
- // added, so we only add the help icon once.
- static $numtimesadded = 0;
+ // Must be overriden.
+ return false;
+ }
+ /**
+ * This function renders the common form elements when adding a customcert element.
+ *
+ * @param stdClass $mform the edit_form instance.
+ * @return array the form elements
+ */
+ public function render_common_form_elements($mform) {
// The identifier.
$id = $this->element->id;
+ // Commonly used string.
+ $strrequired = get_string('required');
+
// The common group of elements.
- $group = array();
- $group[] = $mform->createElement('select', 'font_' . $id, '', customcert_get_fonts());
- $group[] = $mform->createElement('select', 'size_' . $id, '', customcert_get_font_sizes());
- $group[] = $mform->createELement('text', 'colour_' . $id, '', array('size' => 10, 'maxlength' => 6));
- $group[] = $mform->createElement('text', 'posx_' . $id, '', array('size' => 10));
- $group[] = $mform->createElement('text', 'posy_' . $id, '', array('size' => 10));
+ $mform->addElement('select', 'font_' . $id, get_string('font', 'customcert'), customcert_get_fonts());
+ $mform->addElement('select', 'size_' . $id, get_string('fontsize', 'customcert'), customcert_get_font_sizes());
+ $mform->addELement('text', 'colour_' . $id, get_string('fontcolour', 'customcert'), array('size' => 10, 'maxlength' => 6));
+ $mform->addElement('text', 'posx_' . $id, get_string('posx', 'customcert'), array('size' => 10));
+ $mform->addElement('text', 'posy_' . $id, get_string('posy', 'customcert'), array('size' => 10));
- // Add this group.
- $mform->addElement('group', 'elementfieldgroup_' . $id, get_string('pluginname', 'customcertelement_' . $this->element->element),
- $group, array(' ' . get_string('fontsize', 'customcert') . ' ', ' ' . get_string('colour', 'customcert') . ' ',
- ' ' . get_string('posx', 'customcert') . ' ', ' ' . get_string('posy', 'customcert') . ' '), false);
+ // Set the types of these elements.
+ $mform->setType('font_' . $id, PARAM_TEXT);
+ $mform->setType('size_' . $id, PARAM_INT);
+ $mform->setType('colour_' . $id, PARAM_RAW); // Need to validate this is a hexadecimal value.
+ $mform->setType('posx_' . $id, PARAM_INT);
+ $mform->setType('posy_' . $id, PARAM_INT);
- $this->set_form_element_types($mform);
+ // Add some rules.
+ $mform->addRule('colour_' . $id, $strrequired, 'required', null, 'client');
+ $mform->addRule('posx_' . $id, $strrequired, 'required', null, 'client');
+ $mform->addRule('posy_' . $id, $strrequired, 'required', null, 'client');
- if ($numtimesadded == 0) {
- $mform->addHelpButton('elementfieldgroup_' . $id, 'commonformelements', 'customcert');
- }
+ // Set the values of these elements.
+ $mform->setDefault('font_' . $id, $this->element->font);
+ $mform->setDefault('size_' . $id, $this->element->size);
+ $mform->setDefault('colour_' . $id, $this->element->colour);
+ $mform->setDefault('posx_' . $id, $this->element->posx);
+ $mform->setDefault('posy_' . $id, $this->element->posy);
- $numtimesadded++;
+ // Add help buttons.
+ $mform->addHelpButton('font_' . $id, 'font', 'customcert');
+ $mform->addHelpButton('size_' . $id, 'fontsize', 'customcert');
+ $mform->addHelpButton('colour_' . $id, 'fontcolour', 'customcert');
+ $mform->addHelpButton('posx_' . $id, 'posx', 'customcert');
+ $mform->addHelpButton('posy_' . $id, 'posy', 'customcert');
}
/**
@@ -226,38 +248,4 @@ class customcert_element_base {
return $DB->delete_records('customcert_elements', array('id' => $this->element->id));
}
-
-
- /**
- * Helper function that sets the types, defaults and rules for the common elements.
- *
- * @param stdClass $mform the edit_form instance.
- * @return array the form elements
- */
- public function set_form_element_types($mform) {
-
- // The identifier.
- $id = $this->element->id;
-
- // Set the types of these elements.
- $mform->setType('font_' . $id, PARAM_TEXT);
- $mform->setType('size_' . $id, PARAM_INT);
- $mform->setType('colour_' . $id, PARAM_RAW); // Need to validate this is a hexadecimal value.
- $mform->setType('posx_' . $id, PARAM_INT);
- $mform->setType('posy_' . $id, PARAM_INT);
-
- // Add some rules.
- $grouprule = array();
- $grouprule['colour_' . $id][] = array(null, 'required', null, 'client');
- $grouprule['posx_' . $id][] = array(null, 'required', null, 'client');
- $grouprule['posy_' . $id][] = array(null, 'required', null, 'client');
- $mform->addGroupRule('elementfieldgroup_' . $id, $grouprule);
-
- // Set the values of these elements.
- $mform->setDefault('font_' . $id, $this->element->font);
- $mform->setDefault('size_' . $id, $this->element->size);
- $mform->setDefault('colour_' . $id, $this->element->colour);
- $mform->setDefault('posx_' . $id, $this->element->posx);
- $mform->setDefault('posy_' . $id, $this->element->posy);
- }
}
\ No newline at end of file
diff --git a/elements/grade/lang/en/customcertelement_grade.php b/elements/grade/lang/en/customcertelement_grade.php
index 24fa438..e099cdc 100644
--- a/elements/grade/lang/en/customcertelement_grade.php
+++ b/elements/grade/lang/en/customcertelement_grade.php
@@ -23,15 +23,10 @@
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
-$string['gradeformelements'] = 'Grade form elements';
-$string['gradeformelements_help'] = 'These are the most common attributes shared between multiple customcert elements.
-Grade: The grade item you wish to display the grade of.
-Grade Format: The format you wish to use when displaying the grade.
-Font Size: This is the size of the font in points.
-Colour: This is the colour of the font.
-Position x: This is the position in pixels from the top left corner you wish the element to display in the x direction.
-Position Y: This is the position in pixels from the top left corner you wish the element to display in the y direction.
';
+$string['gradeitem'] = 'Grade item';
+$string['gradeitem_help'] = 'The grade item you wish to display the grade of.';
$string['gradeformat'] = 'Grade format';
+$string['gradeformat_help'] = 'The format you wish to use when displaying the grade.';
$string['gradeitem'] = 'Grade item';
$string['gradepercent'] = 'Percentage Grade';
$string['gradepoints'] = 'Points Grade';
diff --git a/elements/grade/lib.php b/elements/grade/lib.php
index c900cfe..7fae181 100644
--- a/elements/grade/lib.php
+++ b/elements/grade/lib.php
@@ -47,43 +47,35 @@ class customcert_element_grade extends customcert_element_base {
* @return array the form elements
*/
public function render_form_elements($mform) {
- // Keep track of the number of times these elements have been
- // added, so we only add the help icon once.
- static $numtimesadded = 0;
-
// The identifier.
$id = $this->element->id;
- $gradeinfo = json_decode($this->element->data);
- $gradeitem = $gradeinfo->gradeitem;
- $gradeformat = $gradeinfo->gradeformat;
+ $gradeitem = '';
+ $gradeformat = '';
- // The common group of elements.
- $group = array();
- $group[] = $mform->createElement('select', 'gradeitem_' . $id, '', $this->get_grade_items());
- $group[] = $mform->createElement('select', 'gradeformat_' . $id, '', $this->get_grade_format_options());
- $group[] = $mform->createElement('select', 'font_' . $id, '', customcert_get_fonts());
- $group[] = $mform->createElement('select', 'size_' . $id, '', customcert_get_font_sizes());
- $group[] = $mform->createELement('text', 'colour_' . $id, '', array('size' => 10, 'maxlength' => 6));
- $group[] = $mform->createElement('text', 'posx_' . $id, '', array('size' => 10));
- $group[] = $mform->createElement('text', 'posy_' . $id, '', array('size' => 10));
+ // Check if there is any data for this element.
+ if (!empty($this->element->data)) {
+ $gradeinfo = json_decode($this->element->data);
+ $gradeitem = $gradeinfo->gradeitem;
+ $gradeformat = $gradeinfo->gradeformat;
+ }
- // Add this group.
- $mform->addElement('group', 'elementfieldgroup_' . $id, get_string('pluginname', 'customcertelement_grade'), $group,
- array(' ' . get_string('gradeformat', 'customcertelement_grade') . ' ', ' ' . get_string('font', 'customcert') . ' ',
- ' ' . get_string('fontsize', 'customcert') . ' ', ' ' . get_string('colour', 'customcert') . ' ',
- ' ' . get_string('posx', 'customcert') . ' ', ' ' . get_string('posy', 'customcert') . ' '), false);
+ // Add element header.
+ $mform->addElement('header', 'headerelement_' . $id, get_string('page', 'customcert', $this->element->pagenum) . " - " .
+ get_string('pluginname', 'customcertelement_grade'));
- $this->set_form_element_types($mform);
+ // The elements unique to this field.
+ $mform->addElement('select', 'gradeitem_' . $id, get_string('gradeitem', 'customcertelement_grade'), $this->get_grade_items());
+ $mform->addElement('select', 'gradeformat_' . $id, get_string('gradeformat', 'customcertelement_grade'), $this->get_grade_format_options());
+
+ parent::render_common_form_elements($mform);
$mform->setDefault('gradeitem_' . $id, $gradeitem);
$mform->setDefault('gradeformat_' . $id, $gradeformat);
- if ($numtimesadded == 0) {
- $mform->addHelpButton('elementfieldgroup_' . $id, 'gradeformelements', 'customcertelement_grade');
- }
-
- $numtimesadded++;
+ // Add help buttons.
+ $mform->addHelpButton('gradeitem_' . $id, 'gradeitem', 'customcertelement_grade');
+ $mform->addHelpButton('gradeformat_' . $id, 'gradeformat', 'customcertelement_grade');
}
/**
diff --git a/elements/studentname/lib.php b/elements/studentname/lib.php
index 0128b1a..e180502 100644
--- a/elements/studentname/lib.php
+++ b/elements/studentname/lib.php
@@ -38,6 +38,23 @@ class customcert_element_studentname extends customcert_element_base {
parent::__construct($element);
}
+ /**
+ * This function renders the form elements when adding a customcert element.
+ *
+ * @param stdClass $mform the edit_form instance.
+ * @return array the form elements
+ */
+ public function render_form_elements($mform) {
+ // The identifier.
+ $id = $this->element->id;
+
+ // Add element header.
+ $mform->addElement('header', 'headerelement_' . $id, get_string('page', 'customcert', $this->element->pagenum) . " - "
+ . get_string('pluginname', 'customcertelement_studentname'));
+
+ parent::render_common_form_elements($mform);
+ }
+
/**
* Handles displaying the element on the pdf.
*
diff --git a/lang/en/customcert.php b/lang/en/customcert.php
index 4911a0b..76c8b53 100644
--- a/lang/en/customcert.php
+++ b/lang/en/customcert.php
@@ -26,13 +26,6 @@
$string['addcertpage'] = 'Add another certificate page';
$string['addelement'] = 'Add element';
-$string['colour'] = 'Colour';
-$string['commonformelements'] = 'Common form elements';
-$string['commonformelements_help'] = 'These are the most common attributes shared between multiple customcert elements.
-Font Size: This is the size of the font in points.
-Colour: This is the colour of the font.
-Position x: This is the position in pixels from the top left corner you wish the element to display in the x direction.
-Position Y: This is the position in pixels from the top left corner you wish the element to display in the y direction.
';
$string['coursetimereq'] = 'Required minutes in course';
$string['coursetimereq_help'] = 'Enter here the minimum amount of time, in minutes, that a student must be logged into the course before they will be able to receive the certificate.';
$string['customcert:addinstance'] = 'Add a new custom certificate instance';
@@ -45,7 +38,11 @@ $string['deleteelementconfirm'] = 'Are you sure you want to delete this element?
$string['deletepageconfirm'] = 'Are you sure you want to delete this certificate page?';
$string['editcustomcert'] = 'Edit custom certificate';
$string['font'] = 'Font';
+$string['font_help'] = 'The font used when generating this element.';
+$string['fontcolour'] = 'Colour';
+$string['fontcolour_help'] = 'The colour of the font.';
$string['fontsize'] = 'Size';
+$string['fontsize_help'] = 'The size of the font in points.';
$string['height'] = 'Height';
$string['heightnotvalid'] = 'The height has to be a valid number.';
$string['height_help'] = 'This is the height of the certificate PDF in mm. For reference an A4 piece of paper is 297mm high and a letter is 279mm high.';
@@ -65,7 +62,9 @@ $string['pluginadministration'] = 'Custom Certificate administration';
$string['pluginname'] = 'Custom Certificate';
$string['portrait'] = 'Portrait';
$string['posx'] = 'Position X';
+$string['posx_help'] = 'This is the position in pixels from the top left corner you wish the element to display in the x direction.';
$string['posy'] = 'Postion Y';
+$string['posy_help'] = 'This is the position in pixels from the top left corner you wish the element to display in the y direction.';
$string['uploadimage'] = 'Upload image';
$string['width'] = 'Width';
$string['widthnotvalid'] = 'The width has to be a valid number.';