Set the element values in the definition_after_data function rather than the constructor

This commit is contained in:
Mark Nelson 2013-06-25 13:40:56 +10:00
parent 1f145d6a3c
commit dee0b54c02
10 changed files with 96 additions and 97 deletions

View file

@ -39,28 +39,6 @@ define('CUSTOMCERT_DATE_COMPLETION', '2');
*/
class customcert_element_date extends customcert_element_base {
/**
* Constructor.
*
* @param stdClass $element the element data
*/
function __construct($element) {
parent::__construct($element);
// Set the item and format for this element.
$dateitem = '';
$dateformat = '';
if (!empty($this->element->data)) {
$dateinfo = json_decode($this->element->data);
$dateitem = $dateinfo->dateitem;
$dateformat = $dateinfo->dateformat;
}
$this->element->dateitem = $dateitem;
$this->element->dateformat = $dateformat;
}
/**
* This function renders the form elements when adding a customcert element.
*
@ -167,6 +145,28 @@ class customcert_element_date extends customcert_element_base {
}
}
/**
* Sets the data on the form when editing an element.
*
* @param mod_customcert_edit_element_form $mform the edit_form instance
*/
public function definition_after_data($mform) {
// Set the item and format for this element.
$dateitem = '';
$dateformat = '';
if (!empty($this->element->data)) {
$dateinfo = json_decode($this->element->data);
$dateitem = $dateinfo->dateitem;
$dateformat = $dateinfo->dateformat;
}
$this->element->dateitem = $dateitem;
$this->element->dateformat = $dateformat;
parent::definition_after_data($mform);
}
/**
* Helper function to return all the date formats.
*

View file

@ -25,6 +25,6 @@
defined('MOODLE_INTERNAL') || die('Direct access to this script is forbidden.');
$plugin->version = 2013061200;
$plugin->version = 2013062500;
$plugin->requires = 2013040500; // Requires this Moodle version.
$plugin->component = 'customcertelement_date';

View file

@ -36,28 +36,6 @@ define('CUSTOMCERT_GRADE_COURSE', '0');
*/
class customcert_element_grade extends customcert_element_base {
/**
* Constructor.
*
* @param stdClass $element the element data
*/
function __construct($element) {
parent::__construct($element);
// Set the item and format for this element.
$gradeitem = '';
$gradeformat = '';
if (!empty($this->element->data)) {
$gradeinfo = json_decode($this->element->data);
$gradeitem = $gradeinfo->gradeitem;
$gradeformat = $gradeinfo->gradeformat;
}
$this->element->gradeitem = $gradeitem;
$this->element->gradeformat = $gradeformat;
}
/**
* This function renders the form elements when adding a customcert element.
*
@ -122,6 +100,28 @@ class customcert_element_grade extends customcert_element_base {
parent::render_content($pdf, $grade);
}
/**
* Sets the data on the form when editing an element.
*
* @param mod_customcert_edit_element_form $mform the edit_form instance
*/
public function definition_after_data($mform) {
// Set the item and format for this element.
$gradeitem = '';
$gradeformat = '';
if (!empty($this->element->data)) {
$gradeinfo = json_decode($this->element->data);
$gradeitem = $gradeinfo->gradeitem;
$gradeformat = $gradeinfo->gradeformat;
}
$this->element->gradeitem = $gradeitem;
$this->element->gradeformat = $gradeformat;
parent::definition_after_data($mform);
}
/**
* Helper function to return all the grades items for this course.
*

View file

@ -25,6 +25,6 @@
defined('MOODLE_INTERNAL') || die('Direct access to this script is forbidden.');
$plugin->version = 2013061200;
$plugin->version = 2013062500;
$plugin->requires = 2013040500; // Requires this Moodle version.
$plugin->component = 'customcertelement_grade';

View file

@ -28,32 +28,6 @@ require_once($CFG->dirroot . '/mod/customcert/element/element.class.php');
*/
class customcert_element_image extends customcert_element_base {
/**
* Constructor.
*
* @param stdClass $element the element data
*/
function __construct($element) {
parent::__construct($element);
// Set the image, width and height for this element.
$image = '';
$width = '0';
$height = '0';
// Check if there is any data for this element.
if (!empty($this->element->data)) {
$imageinfo = json_decode($this->element->data);
$image = $imageinfo->pathnamehash;
$width = $imageinfo->width;
$height = $imageinfo->height;
}
$this->element->image = $image;
$this->element->width = $width;
$this->element->height = $height;
}
/**
* This function renders the form elements when adding a customcert element.
*
@ -144,6 +118,32 @@ class customcert_element_image extends customcert_element_base {
}
}
/**
* Sets the data on the form when editing an element.
*
* @param mod_customcert_edit_element_form $mform the edit_form instance
*/
public function definition_after_data($mform) {
// Set the image, width and height for this element.
$image = '';
$width = '0';
$height = '0';
// Check if there is any data for this element.
if (!empty($this->element->data)) {
$imageinfo = json_decode($this->element->data);
$image = $imageinfo->pathnamehash;
$width = $imageinfo->width;
$height = $imageinfo->height;
}
$this->element->image = $image;
$this->element->width = $width;
$this->element->height = $height;
parent::definition_after_data($mform);
}
/**
* Return the list of possible images to use.
*

View file

@ -25,6 +25,6 @@
defined('MOODLE_INTERNAL') || die('Direct access to this script is forbidden.');
$plugin->version = 2013061200;
$plugin->version = 2013062500;
$plugin->requires = 2013040500; // Requires this Moodle version.
$plugin->component = 'customcertelement_image';

View file

@ -28,17 +28,6 @@ require_once($CFG->dirroot . '/mod/customcert/element/element.class.php');
*/
class customcert_element_text extends customcert_element_base {
/**
* Constructor.
*
* @param stdClass $element the element data
*/
function __construct($element) {
parent::__construct($element);
$this->element->text = (!empty($element->data)) ? $element->data : '';
}
/**
* This function renders the form elements when adding a customcert element.
*
@ -71,4 +60,14 @@ class customcert_element_text extends customcert_element_base {
public function render($pdf) {
parent::render_content($pdf, $this->element->data);
}
/**
* Sets the data on the form when editing an element.
*
* @param mod_customcert_edit_element_form $mform the edit_form instance
*/
public function definition_after_data($mform) {
$this->element->text = (!empty($this->element->data)) ? $this->element->data : '';
parent::definition_after_data($mform);
}
}

View file

@ -25,6 +25,6 @@
defined('MOODLE_INTERNAL') || die('Direct access to this script is forbidden.');
$plugin->version = 2013061200;
$plugin->version = 2013062500;
$plugin->requires = 2013040500; // Requires this Moodle version.
$plugin->component = 'customcertelement_text';

View file

@ -18,6 +18,7 @@
defined('MOODLE_INTERNAL') || die('Direct access to this script is forbidden.');
require_once($CFG->dirroot . '/mod/customcert/element/element.class.php');
require_once($CFG->libdir . '/conditionlib.php');
/**
* The customcert element userfield's core interaction API.
@ -28,17 +29,6 @@ require_once($CFG->dirroot . '/mod/customcert/element/element.class.php');
*/
class customcert_element_userfield extends customcert_element_base {
/**
* Constructor.
*
* @param stdClass $element the element data
*/
function __construct($element) {
parent::__construct($element);
$this->element->userfield = (!empty($element->data)) ? $element->data : '';
}
/**
* This function renders the form elements when adding a customcert element.
*
@ -90,4 +80,14 @@ class customcert_element_userfield extends customcert_element_base {
parent::render_content($pdf, $value);
}
/**
* Sets the data on the form when editing an element.
*
* @param mod_customcert_edit_element_form $mform the edit_form instance
*/
public function definition_after_data($mform) {
$this->element->userfield = (!empty($this->element->data)) ? $this->element->data : '';
parent::definition_after_data($mform);
}
}

View file

@ -25,6 +25,6 @@
defined('MOODLE_INTERNAL') || die('Direct access to this script is forbidden.');
$plugin->version = 2013061400;
$plugin->version = 2013062500;
$plugin->requires = 2013040500; // Requires this Moodle version.
$plugin->component = 'customcertelement_userfield';