Only call definition_after_data when we are editing an element so that we know data exists

This commit is contained in:
Mark Nelson 2013-07-23 17:01:27 +08:00
parent ffcd9cc879
commit 73cf11b043
7 changed files with 17 additions and 41 deletions

View file

@ -62,7 +62,7 @@ $PAGE->set_heading($course->fullname);
$PAGE->set_title(get_string('editcustomcert', 'customcert', format_string($customcert->name))); $PAGE->set_title(get_string('editcustomcert', 'customcert', format_string($customcert->name)));
$PAGE->set_url($pageurl); $PAGE->set_url($pageurl);
$mform = new mod_customcert_edit_element_form($pageurl, array('element' => $element, 'cmid' => $cmid)); $mform = new mod_customcert_edit_element_form($pageurl, array('element' => $element, 'cmid' => $cmid, 'action' => $action));
// Check if they cancelled. // Check if they cancelled.
if ($mform->is_cancelled()) { if ($mform->is_cancelled()) {

View file

@ -61,7 +61,10 @@ class mod_customcert_edit_element_form extends moodleform {
* Fill in the current page data for this customcert. * Fill in the current page data for this customcert.
*/ */
public function definition_after_data() { public function definition_after_data() {
$this->element->definition_after_data($this->_form); // We only want to call definition_after_data if we are editing an element.
if ($this->_customdata['action'] == 'edit') {
$this->element->definition_after_data($this->_form);
}
} }
/** /**

View file

@ -154,17 +154,9 @@ class customcert_element_date extends customcert_element_base {
*/ */
public function definition_after_data($mform) { public function definition_after_data($mform) {
// Set the item and format for this element. // Set the item and format for this element.
$dateitem = ''; $dateinfo = json_decode($this->element->data);
$dateformat = ''; $this->element->dateitem = $dateinfo->dateitem;
$this->element->dateformat = $dateinfo->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); parent::definition_after_data($mform);
} }

View file

@ -106,17 +106,9 @@ class customcert_element_grade extends customcert_element_base {
*/ */
public function definition_after_data($mform) { public function definition_after_data($mform) {
// Set the item and format for this element. // Set the item and format for this element.
$gradeitem = ''; $gradeinfo = json_decode($this->element->data);
$gradeformat = ''; $this->element->gradeitem = $gradeinfo->gradeitem;
$this->element->gradeformat = $gradeinfo->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); parent::definition_after_data($mform);
} }

View file

@ -125,21 +125,10 @@ class customcert_element_image extends customcert_element_base {
*/ */
public function definition_after_data($mform) { public function definition_after_data($mform) {
// Set the image, width and height for this element. // Set the image, width and height for this element.
$image = ''; $imageinfo = json_decode($this->element->data);
$width = '0'; $this->element->image = $imageinfo->pathnamehash;
$height = '0'; $this->element->width = $imageinfo->width;
$this->element->height = $imageinfo->height;
// 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); parent::definition_after_data($mform);
} }

View file

@ -67,7 +67,7 @@ class customcert_element_text extends customcert_element_base {
* @param mod_customcert_edit_element_form $mform the edit_form instance * @param mod_customcert_edit_element_form $mform the edit_form instance
*/ */
public function definition_after_data($mform) { public function definition_after_data($mform) {
$this->element->text = (!empty($this->element->data)) ? $this->element->data : ''; $this->element->text = $this->element->data;
parent::definition_after_data($mform); parent::definition_after_data($mform);
} }
} }

View file

@ -87,7 +87,7 @@ class customcert_element_userfield extends customcert_element_base {
* @param mod_customcert_edit_element_form $mform the edit_form instance * @param mod_customcert_edit_element_form $mform the edit_form instance
*/ */
public function definition_after_data($mform) { public function definition_after_data($mform) {
$this->element->userfield = (!empty($this->element->data)) ? $this->element->data : ''; $this->element->userfield = $this->element->data;
parent::definition_after_data($mform); parent::definition_after_data($mform);
} }
} }