Fixed issue when creating an image element

The images were not loading in the filemanager.
This meant that when the element was saved the
images would be deleted for that course, affecting
existing image elements as well.
This commit is contained in:
Mark Nelson 2015-12-10 15:26:49 +08:00
parent 136292f331
commit 9413d65ee0
9 changed files with 32 additions and 19 deletions

View file

@ -62,10 +62,7 @@ class mod_customcert_edit_element_form extends moodleform {
* Fill in the current page data for this customcert.
*/
public function definition_after_data() {
// 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);
}
$this->element->definition_after_data($this->_form);
}
/**

View file

@ -95,7 +95,9 @@ class customcert_element_border extends customcert_element_base {
* @param mod_customcert_edit_element_form $mform the edit_form instance
*/
public function definition_after_data($mform) {
$this->element->width = $this->element->data;
if (!empty($this->element->data)) {
$this->element->width = $this->element->data;
}
parent::definition_after_data($mform);
}

View file

@ -160,9 +160,11 @@ class customcert_element_date extends customcert_element_base {
*/
public function definition_after_data($mform) {
// Set the item and format for this element.
$dateinfo = json_decode($this->element->data);
$this->element->dateitem = $dateinfo->dateitem;
$this->element->dateformat = $dateinfo->dateformat;
if (!empty($this->element->data)) {
$dateinfo = json_decode($this->element->data);
$this->element->dateitem = $dateinfo->dateitem;
$this->element->dateformat = $dateinfo->dateformat;
}
parent::definition_after_data($mform);
}

View file

@ -141,9 +141,11 @@ class customcert_element_grade extends customcert_element_base {
*/
public function definition_after_data($mform) {
// Set the item and format for this element.
$gradeinfo = json_decode($this->element->data);
$this->element->gradeitem = $gradeinfo->gradeitem;
$this->element->gradeformat = $gradeinfo->gradeformat;
if (!empty($this->element->data)) {
$gradeinfo = json_decode($this->element->data);
$this->element->gradeitem = $gradeinfo->gradeitem;
$this->element->gradeformat = $gradeinfo->gradeformat;
}
parent::definition_after_data($mform);
}

View file

@ -106,7 +106,9 @@ class customcert_element_gradeitemname extends customcert_element_base {
* @param mod_customcert_edit_element_form $mform the edit_form instance
*/
public function definition_after_data($mform) {
$this->element->gradeitem = $this->element->data;
if (!empty($this->element->data)) {
$this->element->gradeitem = $this->element->data;
}
parent::definition_after_data($mform);
}
}

View file

@ -216,10 +216,12 @@ class customcert_element_image extends customcert_element_base {
global $COURSE;
// Set the image, width and height for this element.
$imageinfo = json_decode($this->element->data);
$this->element->image = $imageinfo->pathnamehash;
$this->element->width = $imageinfo->width;
$this->element->height = $imageinfo->height;
if (!empty($this->element->data)) {
$imageinfo = json_decode($this->element->data);
$this->element->image = $imageinfo->pathnamehash;
$this->element->width = $imageinfo->width;
$this->element->height = $imageinfo->height;
}
// Editing existing instance - copy existing files into draft area.
$draftitemid = file_get_submitted_draft_itemid('customcertimage');

View file

@ -109,7 +109,9 @@ class customcert_element_teachername extends customcert_element_base {
* @param mod_customcert_edit_element_form $mform the edit_form instance
*/
public function definition_after_data($mform) {
$this->element->teacher = $this->element->data;
if (!empty($this->element->data)) {
$this->element->teacher = $this->element->data;
}
parent::definition_after_data($mform);
}
}

View file

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

View file

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