#158 Fixed fatal error in PHP < 5.5

This commit is contained in:
Mark Nelson 2018-01-22 19:47:44 +08:00
parent 8fe6c32d9a
commit 4a4fa18c28
11 changed files with 74 additions and 50 deletions

View file

@ -67,11 +67,12 @@ class element extends \customcertelement_image\element {
*/ */
public function render($pdf, $preview, $user) { public function render($pdf, $preview, $user) {
// If there is no element data, we have nothing to display. // If there is no element data, we have nothing to display.
if (empty($this->get_data())) { $data = $this->get_data();
if (empty($data)) {
return; return;
} }
$imageinfo = json_decode($this->get_data()); $imageinfo = json_decode($data);
// If there is no file, we have nothing to display. // If there is no file, we have nothing to display.
if (empty($imageinfo->filename)) { if (empty($imageinfo->filename)) {
@ -104,11 +105,12 @@ class element extends \customcertelement_image\element {
global $DB; global $DB;
// If there is no element data, we have nothing to display. // If there is no element data, we have nothing to display.
if (empty($this->get_data())) { $data = $this->get_data();
if (empty($data)) {
return ''; return '';
} }
$imageinfo = json_decode($this->get_data()); $imageinfo = json_decode($data);
// If there is no file, we have nothing to display. // If there is no file, we have nothing to display.
if (empty($imageinfo->filename)) { if (empty($imageinfo->filename)) {

View file

@ -106,9 +106,10 @@ class element extends \mod_customcert\element {
* @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) {
if (!empty($this->get_data())) { $data = $this->get_data();
if (!empty($data)) {
$element = $mform->getElement('width'); $element = $mform->getElement('width');
$element->setValue($this->get_data()); $element->setValue($data);
} }
parent::definition_after_data($mform); parent::definition_after_data($mform);
} }

View file

@ -117,14 +117,15 @@ class element extends \mod_customcert\element {
global $DB; global $DB;
// If there is no element data, we have nothing to display. // If there is no element data, we have nothing to display.
if (empty($this->get_data())) { $data = $this->get_data();
if (empty($data)) {
return; return;
} }
$courseid = \mod_customcert\element_helper::get_courseid($this->id); $courseid = \mod_customcert\element_helper::get_courseid($this->id);
// Decode the information stored in the database. // Decode the information stored in the database.
$dateinfo = json_decode($this->get_data()); $dateinfo = json_decode($data);
$dateitem = $dateinfo->dateitem; $dateitem = $dateinfo->dateitem;
$dateformat = $dateinfo->dateformat; $dateformat = $dateinfo->dateformat;
@ -179,8 +180,9 @@ class element extends \mod_customcert\element {
); );
} }
if ($grade && !empty($grade->get_dategraded())) { $dategraded = $grade->get_dategraded();
$date = $grade->get_dategraded(); if ($grade && !empty($dategraded)) {
$date = $dategraded;
} }
} }
} }
@ -201,12 +203,13 @@ class element extends \mod_customcert\element {
*/ */
public function render_html() { public function render_html() {
// If there is no element data, we have nothing to display. // If there is no element data, we have nothing to display.
if (empty($this->get_data())) { $data = $this->get_data();
return; if (empty($data)) {
return '';
} }
// Decode the information stored in the database. // Decode the information stored in the database.
$dateinfo = json_decode($this->get_data()); $dateinfo = json_decode($data);
$dateformat = $dateinfo->dateformat; $dateformat = $dateinfo->dateformat;
return \mod_customcert\element_helper::render_html_content($this, $this->get_date_format_string(time(), $dateformat)); return \mod_customcert\element_helper::render_html_content($this, $this->get_date_format_string(time(), $dateformat));
@ -219,8 +222,9 @@ class element extends \mod_customcert\element {
*/ */
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.
if (!empty($this->get_data())) { $data = $this->get_data();
$dateinfo = json_decode($this->get_data()); if (!empty($data)) {
$dateinfo = json_decode($data);
$element = $mform->getElement('dateitem'); $element = $mform->getElement('dateitem');
$element->setValue($dateinfo->dateitem); $element->setValue($dateinfo->dateitem);

View file

@ -195,11 +195,12 @@ class element extends \customcertelement_image\element {
*/ */
public function render($pdf, $preview, $user) { public function render($pdf, $preview, $user) {
// If there is no element data, we have nothing to display. // If there is no element data, we have nothing to display.
if (empty($this->get_data())) { $data = $this->get_data();
if (empty($data)) {
return; return;
} }
$imageinfo = json_decode($this->get_data()); $imageinfo = json_decode($data);
// If there is no file, we have nothing to display. // If there is no file, we have nothing to display.
if (empty($imageinfo->filename)) { if (empty($imageinfo->filename)) {
@ -252,8 +253,9 @@ class element extends \customcertelement_image\element {
$context = \context_course::instance($COURSE->id); $context = \context_course::instance($COURSE->id);
} }
if (!empty($this->get_data())) { $data = $this->get_data();
$imageinfo = json_decode($this->get_data()); if (!empty($data)) {
$imageinfo = json_decode($data);
$element = $mform->getElement('signaturename'); $element = $mform->getElement('signaturename');
$element->setValue($imageinfo->signaturename); $element->setValue($imageinfo->signaturename);

View file

@ -93,14 +93,15 @@ class element extends \mod_customcert\element {
*/ */
public function render($pdf, $preview, $user) { public function render($pdf, $preview, $user) {
// If there is no element data, we have nothing to display. // If there is no element data, we have nothing to display.
if (empty($this->get_data())) { $data = $this->get_data();
if (empty($data)) {
return; return;
} }
$courseid = \mod_customcert\element_helper::get_courseid($this->id); $courseid = \mod_customcert\element_helper::get_courseid($this->id);
// Decode the information stored in the database. // Decode the information stored in the database.
$gradeinfo = json_decode($this->get_data()); $gradeinfo = json_decode($data);
$gradeitem = $gradeinfo->gradeitem; $gradeitem = $gradeinfo->gradeitem;
$gradeformat = $gradeinfo->gradeformat; $gradeformat = $gradeinfo->gradeformat;
@ -156,12 +157,13 @@ class element extends \mod_customcert\element {
global $COURSE; global $COURSE;
// If there is no element data, we have nothing to display. // If there is no element data, we have nothing to display.
if (empty($this->get_data())) { $data = $this->get_data();
return; if (empty($data)) {
return '';
} }
// Decode the information stored in the database. // Decode the information stored in the database.
$gradeinfo = json_decode($this->get_data()); $gradeinfo = json_decode($data);
$courseitem = \grade_item::fetch_course_item($COURSE->id); $courseitem = \grade_item::fetch_course_item($COURSE->id);
@ -183,8 +185,9 @@ class element extends \mod_customcert\element {
*/ */
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.
if (!empty($this->get_data())) { $data = $this->get_data();
$gradeinfo = json_decode($this->get_data()); if (!empty($data)) {
$gradeinfo = json_decode($data);
$element = $mform->getElement('gradeitem'); $element = $mform->getElement('gradeitem');
$element->setValue($gradeinfo->gradeitem); $element->setValue($gradeinfo->gradeitem);

View file

@ -76,9 +76,10 @@ class element extends \mod_customcert\element {
global $DB; global $DB;
// Check that the grade item is not empty. // Check that the grade item is not empty.
if (!empty($this->get_data())) { $data = $this->get_data();
if (!empty($data)) {
// Get the course module information. // Get the course module information.
$cm = $DB->get_record('course_modules', array('id' => $this->get_data()), '*', MUST_EXIST); $cm = $DB->get_record('course_modules', array('id' => $data), '*', MUST_EXIST);
$module = $DB->get_record('modules', array('id' => $cm->module), '*', MUST_EXIST); $module = $DB->get_record('modules', array('id' => $cm->module), '*', MUST_EXIST);
// Get the name of the item. // Get the name of the item.
@ -100,9 +101,10 @@ class element extends \mod_customcert\element {
global $DB; global $DB;
// Check that the grade item is not empty. // Check that the grade item is not empty.
if (!empty($this->get_data())) { $data = $this->get_data();
if (!empty($data)) {
// Get the course module information. // Get the course module information.
$cm = $DB->get_record('course_modules', array('id' => $this->get_data()), '*', MUST_EXIST); $cm = $DB->get_record('course_modules', array('id' => $data), '*', MUST_EXIST);
$module = $DB->get_record('modules', array('id' => $cm->module), '*', MUST_EXIST); $module = $DB->get_record('modules', array('id' => $cm->module), '*', MUST_EXIST);
// Get the name of the item. // Get the name of the item.
@ -120,9 +122,10 @@ class element extends \mod_customcert\element {
* @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) {
if (!empty($this->get_data())) { $data = $this->get_data();
if (!empty($data)) {
$element = $mform->getElement('gradeitem'); $element = $mform->getElement('gradeitem');
$element->setValue($this->get_data()); $element->setValue($data);
} }
parent::definition_after_data($mform); parent::definition_after_data($mform);
} }

View file

@ -174,11 +174,12 @@ class element extends \mod_customcert\element {
*/ */
public function render($pdf, $preview, $user) { public function render($pdf, $preview, $user) {
// If there is no element data, we have nothing to display. // If there is no element data, we have nothing to display.
if (empty($this->get_data())) { $data = $this->get_data();
if (empty($data)) {
return; return;
} }
$imageinfo = json_decode($this->get_data()); $imageinfo = json_decode($data);
// If there is no file, we have nothing to display. // If there is no file, we have nothing to display.
if (empty($imageinfo->filename)) { if (empty($imageinfo->filename)) {
@ -208,11 +209,12 @@ class element extends \mod_customcert\element {
*/ */
public function render_html() { public function render_html() {
// If there is no element data, we have nothing to display. // If there is no element data, we have nothing to display.
if (empty($this->get_data())) { $data = $this->get_data();
if (empty($data)) {
return ''; return '';
} }
$imageinfo = json_decode($this->get_data()); $imageinfo = json_decode($data);
// If there is no file, we have nothing to display. // If there is no file, we have nothing to display.
if (empty($imageinfo->filename)) { if (empty($imageinfo->filename)) {
@ -258,8 +260,9 @@ class element extends \mod_customcert\element {
global $COURSE, $SITE; global $COURSE, $SITE;
// Set the image, width and height for this element. // Set the image, width and height for this element.
if (!empty($this->get_data())) { $data = $this->get_data();
$imageinfo = json_decode($this->get_data()); if (!empty($data)) {
$imageinfo = json_decode($data);
if (!empty($imageinfo->filename)) { if (!empty($imageinfo->filename)) {
if ($file = $this->get_file()) { if ($file = $this->get_file()) {
$element = $mform->getElement('fileid'); $element = $mform->getElement('fileid');

View file

@ -121,9 +121,10 @@ class element extends \mod_customcert\element {
* @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) {
if (!empty($this->get_data())) { $data = $this->get_data();
if (!empty($data)) {
$element = $mform->getElement('teacher'); $element = $mform->getElement('teacher');
$element->setValue($this->get_data()); $element->setValue($data);
} }
parent::definition_after_data($mform); parent::definition_after_data($mform);
} }

View file

@ -88,9 +88,10 @@ class element extends \mod_customcert\element {
* @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) {
if (!empty($this->get_data())) { $data = $this->get_data();
if (!empty($data)) {
$element = $mform->getElement('text'); $element = $mform->getElement('text');
$element->setValue($this->get_data()); $element->setValue($data);
} }
parent::definition_after_data($mform); parent::definition_after_data($mform);
} }

View file

@ -164,9 +164,10 @@ class element extends \mod_customcert\element {
* @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) {
if (!empty($this->get_data())) { $data = $this->get_data();
if (!empty($data)) {
$element = $mform->getElement('userfield'); $element = $mform->getElement('userfield');
$element->setValue($this->get_data()); $element->setValue($data);
} }
parent::definition_after_data($mform); parent::definition_after_data($mform);
} }

View file

@ -113,11 +113,12 @@ class element extends \mod_customcert\element {
global $CFG; global $CFG;
// If there is no element data, we have nothing to display. // If there is no element data, we have nothing to display.
if (empty($this->get_data())) { $data = $this->get_data();
if (empty($data)) {
return; return;
} }
$imageinfo = json_decode($this->get_data()); $imageinfo = json_decode($data);
$context = \context_user::instance($user->id); $context = \context_user::instance($user->id);
@ -157,11 +158,12 @@ class element extends \mod_customcert\element {
global $PAGE, $USER; global $PAGE, $USER;
// If there is no element data, we have nothing to display. // If there is no element data, we have nothing to display.
if (empty($this->get_data())) { $data = $this->get_data();
if (empty($data)) {
return ''; return '';
} }
$imageinfo = json_decode($this->get_data()); $imageinfo = json_decode($data);
// Get the image. // Get the image.
$userpicture = new \user_picture($USER); $userpicture = new \user_picture($USER);
@ -194,8 +196,9 @@ class element extends \mod_customcert\element {
*/ */
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.
if (!empty($this->get_data())) { $data = $this->get_data();
$imageinfo = json_decode($this->get_data()); if (!empty($data)) {
$imageinfo = json_decode($data);
$element = $mform->getElement('width'); $element = $mform->getElement('width');
$element->setValue($imageinfo->width); $element->setValue($imageinfo->width);