Removed usage of magic getter and abuse of $this->element
This commit is contained in:
parent
430ae35d71
commit
13f892a229
15 changed files with 293 additions and 94 deletions
|
@ -172,11 +172,11 @@ class element extends \mod_customcert\element {
|
|||
*/
|
||||
public function render($pdf, $preview, $user) {
|
||||
// If there is no element data, we have nothing to display.
|
||||
if (empty($this->element->data)) {
|
||||
if (empty($this->get_data())) {
|
||||
return;
|
||||
}
|
||||
|
||||
$imageinfo = json_decode($this->element->data);
|
||||
$imageinfo = json_decode($this->get_data());
|
||||
|
||||
if ($file = $this->get_file()) {
|
||||
$location = make_request_directory() . '/target';
|
||||
|
@ -184,9 +184,9 @@ class element extends \mod_customcert\element {
|
|||
|
||||
$mimetype = $file->get_mimetype();
|
||||
if ($mimetype == 'image/svg+xml') {
|
||||
$pdf->ImageSVG($location, $this->element->posx, $this->element->posy, $imageinfo->width, $imageinfo->height);
|
||||
$pdf->ImageSVG($location, $this->get_posx(), $this->get_posy(), $imageinfo->width, $imageinfo->height);
|
||||
} else {
|
||||
$pdf->Image($location, $this->element->posx, $this->element->posy, $imageinfo->width, $imageinfo->height);
|
||||
$pdf->Image($location, $this->get_posx(), $this->get_posy(), $imageinfo->width, $imageinfo->height);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -201,11 +201,11 @@ class element extends \mod_customcert\element {
|
|||
*/
|
||||
public function render_html() {
|
||||
// If there is no element data, we have nothing to display.
|
||||
if (empty($this->element->data)) {
|
||||
if (empty($this->get_data())) {
|
||||
return '';
|
||||
}
|
||||
|
||||
$imageinfo = json_decode($this->element->data);
|
||||
$imageinfo = json_decode($this->get_data());
|
||||
|
||||
// Get the image.
|
||||
$fs = get_file_storage();
|
||||
|
@ -246,12 +246,17 @@ class element extends \mod_customcert\element {
|
|||
global $COURSE, $SITE;
|
||||
|
||||
// Set the image, width and height for this element.
|
||||
if (!empty($this->element->data)) {
|
||||
$imageinfo = json_decode($this->element->data);
|
||||
if (!empty($this->get_data())) {
|
||||
$imageinfo = json_decode($this->get_data());
|
||||
if ($file = $this->get_file()) {
|
||||
$this->element->fileid = $file->get_id();
|
||||
$this->element->width = $imageinfo->width;
|
||||
$this->element->height = $imageinfo->height;
|
||||
$element = $mform->getElement('fileid');
|
||||
$element->setValue($this->get_data());
|
||||
|
||||
$element = $mform->getElement('width');
|
||||
$element->setValue($imageinfo->width);
|
||||
|
||||
$element = $mform->getElement('height');
|
||||
$element->setValue($imageinfo->height);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -282,7 +287,7 @@ class element extends \mod_customcert\element {
|
|||
global $DB;
|
||||
|
||||
// Get the current data we have stored for this element.
|
||||
$elementinfo = json_decode($this->element->data);
|
||||
$elementinfo = json_decode($this->get_data());
|
||||
|
||||
// Update the context.
|
||||
$elementinfo->contextid = \context_course::instance($restore->get_courseid())->id;
|
||||
|
@ -291,7 +296,7 @@ class element extends \mod_customcert\element {
|
|||
$elementinfo = json_encode($elementinfo);
|
||||
|
||||
// Perform the update.
|
||||
$DB->set_field('customcert_elements', 'data', $elementinfo, array('id' => $this->element->id));
|
||||
$DB->set_field('customcert_elements', 'data', $elementinfo, array('id' => $this->get_id()));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -300,7 +305,7 @@ class element extends \mod_customcert\element {
|
|||
* @return \stored_file|bool stored_file instance if exists, false if not
|
||||
*/
|
||||
public function get_file() {
|
||||
$imageinfo = json_decode($this->element->data);
|
||||
$imageinfo = json_decode($this->get_data());
|
||||
|
||||
$fs = get_file_storage();
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue