Removed usage of magic getter and abuse of $this->element
This commit is contained in:
parent
fedfe95080
commit
5c1f1aa812
15 changed files with 293 additions and 94 deletions
|
@ -38,14 +38,69 @@ defined('MOODLE_INTERNAL') || die();
|
||||||
abstract class element {
|
abstract class element {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var \stdClass $element The data for the element we are adding.
|
* @var \stdClass $element The data for the element we are adding - do not use, kept for legacy reasons.
|
||||||
*/
|
*/
|
||||||
public $element;
|
protected $element;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var int The id.
|
||||||
|
*/
|
||||||
|
protected $id;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var int The page id.
|
||||||
|
*/
|
||||||
|
protected $pageid;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var string The name.
|
||||||
|
*/
|
||||||
|
protected $name;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var mixed The data.
|
||||||
|
*/
|
||||||
|
protected $data;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var string The font name.
|
||||||
|
*/
|
||||||
|
protected $font;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var int The font size.
|
||||||
|
*/
|
||||||
|
protected $fontsize;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var string The font colour.
|
||||||
|
*/
|
||||||
|
protected $colour;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var int The position x.
|
||||||
|
*/
|
||||||
|
protected $posx;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var int The position y.
|
||||||
|
*/
|
||||||
|
protected $posy;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var int The width.
|
||||||
|
*/
|
||||||
|
protected $width;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var int The refpoint.
|
||||||
|
*/
|
||||||
|
protected $refpoint;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var bool $showposxy Show position XY form elements?
|
* @var bool $showposxy Show position XY form elements?
|
||||||
*/
|
*/
|
||||||
public $showposxy;
|
protected $showposxy;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor.
|
* Constructor.
|
||||||
|
@ -55,10 +110,121 @@ abstract class element {
|
||||||
public function __construct($element) {
|
public function __construct($element) {
|
||||||
$showposxy = get_config('customcert', 'showposxy');
|
$showposxy = get_config('customcert', 'showposxy');
|
||||||
|
|
||||||
|
// Keeping this for legacy reasons so we do not break third-party elements.
|
||||||
$this->element = clone($element);
|
$this->element = clone($element);
|
||||||
|
|
||||||
|
$this->id = $element->id;
|
||||||
|
$this->name = $element->name;
|
||||||
|
$this->data = $element->data;
|
||||||
|
$this->font = $element->font;
|
||||||
|
$this->fontsize = $element->fontsize;
|
||||||
|
$this->colour = $element->colour;
|
||||||
|
$this->posx = $element->posx;
|
||||||
|
$this->posy = $element->posy;
|
||||||
|
$this->width = $element->width;
|
||||||
|
$this->refpoint = $element->refpoint;
|
||||||
$this->showposxy = isset($showposxy) && $showposxy;
|
$this->showposxy = isset($showposxy) && $showposxy;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the id.
|
||||||
|
*
|
||||||
|
* @return int
|
||||||
|
*/
|
||||||
|
public function get_id() {
|
||||||
|
return $this->id;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the page id.
|
||||||
|
*
|
||||||
|
* @return int
|
||||||
|
*/
|
||||||
|
public function get_pageid() {
|
||||||
|
return $this->pageid;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the name.
|
||||||
|
*
|
||||||
|
* @return int
|
||||||
|
*/
|
||||||
|
public function get_name() {
|
||||||
|
return $this->name;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the data.
|
||||||
|
*
|
||||||
|
* @return mixed
|
||||||
|
*/
|
||||||
|
public function get_data() {
|
||||||
|
return $this->data;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the font name.
|
||||||
|
*
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public function get_font() {
|
||||||
|
return $this->font;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the font size.
|
||||||
|
*
|
||||||
|
* @return int
|
||||||
|
*/
|
||||||
|
public function get_fontsize() {
|
||||||
|
return $this->fontsize;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the font colour.
|
||||||
|
*
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public function get_colour() {
|
||||||
|
return $this->colour;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the position x.
|
||||||
|
*
|
||||||
|
* @return int
|
||||||
|
*/
|
||||||
|
public function get_posx() {
|
||||||
|
return $this->posx;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the position y.
|
||||||
|
*
|
||||||
|
* @return int
|
||||||
|
*/
|
||||||
|
public function get_posy() {
|
||||||
|
return $this->posy;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the width.
|
||||||
|
*
|
||||||
|
* @return int
|
||||||
|
*/
|
||||||
|
public function get_width() {
|
||||||
|
return $this->width;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the refpoint.
|
||||||
|
*
|
||||||
|
* @return int
|
||||||
|
*/
|
||||||
|
public function get_refpoint() {
|
||||||
|
return $this->refpoint;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This function renders the form elements when adding a customcert element.
|
* This function renders the form elements when adding a customcert element.
|
||||||
* Can be overridden if more functionality is needed.
|
* Can be overridden if more functionality is needed.
|
||||||
|
@ -84,7 +250,17 @@ abstract class element {
|
||||||
public function definition_after_data($mform) {
|
public function definition_after_data($mform) {
|
||||||
// Loop through the properties of the element and set the values
|
// Loop through the properties of the element and set the values
|
||||||
// of the corresponding form element, if it exists.
|
// of the corresponding form element, if it exists.
|
||||||
foreach ($this->element as $property => $value) {
|
$properties = [
|
||||||
|
'name' => $this->name,
|
||||||
|
'font' => $this->font,
|
||||||
|
'fontsize' => $this->fontsize,
|
||||||
|
'colour' => $this->colour,
|
||||||
|
'posx' => $this->posx,
|
||||||
|
'posy' => $this->posy,
|
||||||
|
'width' => $this->width,
|
||||||
|
'refpoint' => $this->refpoint
|
||||||
|
];
|
||||||
|
foreach ($properties as $property => $value) {
|
||||||
if (!is_null($value) && $mform->elementExists($property)) {
|
if (!is_null($value) && $mform->elementExists($property)) {
|
||||||
$element = $mform->getElement($property);
|
$element = $mform->getElement($property);
|
||||||
$element->setValue($value);
|
$element->setValue($value);
|
||||||
|
@ -140,8 +316,8 @@ abstract class element {
|
||||||
$element->timemodified = time();
|
$element->timemodified = time();
|
||||||
|
|
||||||
// Check if we are updating, or inserting a new element.
|
// Check if we are updating, or inserting a new element.
|
||||||
if (!empty($this->element->id)) { // Must be updating a record in the database.
|
if (!empty($this->id)) { // Must be updating a record in the database.
|
||||||
$element->id = $this->element->id;
|
$element->id = $this->id;
|
||||||
return $DB->update_record('customcert_elements', $element);
|
return $DB->update_record('customcert_elements', $element);
|
||||||
} else { // Must be adding a new one.
|
} else { // Must be adding a new one.
|
||||||
$element->element = $data->element;
|
$element->element = $data->element;
|
||||||
|
@ -208,7 +384,7 @@ abstract class element {
|
||||||
public function delete() {
|
public function delete() {
|
||||||
global $DB;
|
global $DB;
|
||||||
|
|
||||||
return $DB->delete_records('customcert_elements', array('id' => $this->element->id));
|
return $DB->delete_records('customcert_elements', array('id' => $this->id));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -230,6 +406,7 @@ abstract class element {
|
||||||
* @param string $name
|
* @param string $name
|
||||||
*/
|
*/
|
||||||
public function __get($name) {
|
public function __get($name) {
|
||||||
|
debugging('Please call the appropriate get_* function instead of relying on magic getters', DEBUG_DEVELOPER);
|
||||||
if (property_exists($this->element, $name)) {
|
if (property_exists($this->element, $name)) {
|
||||||
return $this->element->$name;
|
return $this->element->$name;
|
||||||
}
|
}
|
||||||
|
|
|
@ -61,14 +61,14 @@ class element_helper {
|
||||||
*/
|
*/
|
||||||
public static function render_content($pdf, $element, $content) {
|
public static function render_content($pdf, $element, $content) {
|
||||||
list($font, $attr) = self::get_font($element);
|
list($font, $attr) = self::get_font($element);
|
||||||
$pdf->setFont($font, $attr, $element->fontsize);
|
$pdf->setFont($font, $attr, $element->get_fontsize());
|
||||||
$fontcolour = \TCPDF_COLORS::convertHTMLColorToDec($element->colour, $fontcolour);
|
$fontcolour = \TCPDF_COLORS::convertHTMLColorToDec($element->get_colour(), $fontcolour);
|
||||||
$pdf->SetTextColor($fontcolour['R'], $fontcolour['G'], $fontcolour['B']);
|
$pdf->SetTextColor($fontcolour['R'], $fontcolour['G'], $fontcolour['B']);
|
||||||
|
|
||||||
$x = $element->posx;
|
$x = $element->get_posx();
|
||||||
$y = $element->posy;
|
$y = $element->get_posy();
|
||||||
$w = $element->width;
|
$w = $element->get_width();
|
||||||
$refpoint = $element->refpoint;
|
$refpoint = $element->get_refpoint();
|
||||||
$actualwidth = $pdf->GetStringWidth($content);
|
$actualwidth = $pdf->GetStringWidth($content);
|
||||||
|
|
||||||
if ($w and $w < $actualwidth) {
|
if ($w and $w < $actualwidth) {
|
||||||
|
@ -77,19 +77,19 @@ class element_helper {
|
||||||
|
|
||||||
switch ($refpoint) {
|
switch ($refpoint) {
|
||||||
case self::CUSTOMCERT_REF_POINT_TOPRIGHT:
|
case self::CUSTOMCERT_REF_POINT_TOPRIGHT:
|
||||||
$x = $element->posx - $actualwidth;
|
$x = $element->get_posx() - $actualwidth;
|
||||||
if ($x < 0) {
|
if ($x < 0) {
|
||||||
$x = 0;
|
$x = 0;
|
||||||
$w = $element->posx;
|
$w = $element->get_posx();
|
||||||
} else {
|
} else {
|
||||||
$w = $actualwidth;
|
$w = $actualwidth;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case self::CUSTOMCERT_REF_POINT_TOPCENTER:
|
case self::CUSTOMCERT_REF_POINT_TOPCENTER:
|
||||||
$x = $element->posx - $actualwidth / 2;
|
$x = $element->get_posx() - $actualwidth / 2;
|
||||||
if ($x < 0) {
|
if ($x < 0) {
|
||||||
$x = 0;
|
$x = 0;
|
||||||
$w = $element->posx * 2;
|
$w = $element->get_posx() * 2;
|
||||||
} else {
|
} else {
|
||||||
$w = $actualwidth;
|
$w = $actualwidth;
|
||||||
}
|
}
|
||||||
|
@ -120,9 +120,9 @@ class element_helper {
|
||||||
$fontstyle .= '; font-style: italic';
|
$fontstyle .= '; font-style: italic';
|
||||||
}
|
}
|
||||||
|
|
||||||
$style = $fontstyle . '; color: ' . $element->colour . '; font-size: ' . $element->fontsize . 'pt;';
|
$style = $fontstyle . '; color: ' . $element->get_colour() . '; font-size: ' . $element->get_fontsize() . 'pt;';
|
||||||
if ($element->width) {
|
if ($element->get_width()) {
|
||||||
$style .= ' width: ' . $element->width . 'mm';
|
$style .= ' width: ' . $element->get_width() . 'mm';
|
||||||
}
|
}
|
||||||
return \html_writer::div($content, '', array('style' => $style));
|
return \html_writer::div($content, '', array('style' => $style));
|
||||||
}
|
}
|
||||||
|
@ -253,7 +253,7 @@ class element_helper {
|
||||||
*/
|
*/
|
||||||
public static function get_font($element) {
|
public static function get_font($element) {
|
||||||
// Variable for the font.
|
// Variable for the font.
|
||||||
$font = $element->font;
|
$font = $element->get_font();
|
||||||
// Get the last two characters of the font name.
|
// Get the last two characters of the font name.
|
||||||
$fontlength = strlen($font);
|
$fontlength = strlen($font);
|
||||||
$lastchar = $font[$fontlength - 1];
|
$lastchar = $font[$fontlength - 1];
|
||||||
|
|
|
@ -67,7 +67,7 @@ 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->element->data)) {
|
if (empty($this->get_data())) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -97,7 +97,7 @@ 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->element->data)) {
|
if (empty($this->get_data())) {
|
||||||
return '';
|
return '';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -105,7 +105,7 @@ class element extends \customcertelement_image\element {
|
||||||
$url = \moodle_url::make_pluginfile_url($file->get_contextid(), 'mod_customcert', 'image', $file->get_itemid(),
|
$url = \moodle_url::make_pluginfile_url($file->get_contextid(), 'mod_customcert', 'image', $file->get_itemid(),
|
||||||
$file->get_filepath(), $file->get_filename());
|
$file->get_filepath(), $file->get_filename());
|
||||||
// Get the page we are rendering this on.
|
// Get the page we are rendering this on.
|
||||||
$page = $DB->get_record('customcert_pages', array('id' => $this->element->pageid), '*', MUST_EXIST);
|
$page = $DB->get_record('customcert_pages', array('id' => $this->get_pageid()), '*', MUST_EXIST);
|
||||||
|
|
||||||
// Set the image to the size of the page.
|
// Set the image to the size of the page.
|
||||||
$style = 'width: ' . $page->width . 'mm; height: ' . $page->height . 'mm';
|
$style = 'width: ' . $page->width . 'mm; height: ' . $page->height . 'mm';
|
||||||
|
|
|
@ -58,8 +58,8 @@ class element extends \mod_customcert\element {
|
||||||
* @param \stdClass $user the user we are rendering this for
|
* @param \stdClass $user the user we are rendering this for
|
||||||
*/
|
*/
|
||||||
public function render($pdf, $preview, $user) {
|
public function render($pdf, $preview, $user) {
|
||||||
$colour = \TCPDF_COLORS::convertHTMLColorToDec($this->element->colour, $colour);
|
$colour = \TCPDF_COLORS::convertHTMLColorToDec($this->get_colour(), $colour);
|
||||||
$pdf->SetLineStyle(array('width' => $this->element->data, 'color' => $colour));
|
$pdf->SetLineStyle(array('width' => $this->get_data(), 'color' => $colour));
|
||||||
$pdf->Line(0, 0, $pdf->getPageWidth(), 0);
|
$pdf->Line(0, 0, $pdf->getPageWidth(), 0);
|
||||||
$pdf->Line($pdf->getPageWidth(), 0, $pdf->getPageWidth(), $pdf->getPageHeight());
|
$pdf->Line($pdf->getPageWidth(), 0, $pdf->getPageWidth(), $pdf->getPageHeight());
|
||||||
$pdf->Line(0, $pdf->getPageHeight(), $pdf->getPageWidth(), $pdf->getPageHeight());
|
$pdf->Line(0, $pdf->getPageHeight(), $pdf->getPageWidth(), $pdf->getPageHeight());
|
||||||
|
@ -106,8 +106,9 @@ 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->element->data)) {
|
if (!empty($this->get_data())) {
|
||||||
$this->element->width = $this->element->data;
|
$element = $mform->getElement('width');
|
||||||
|
$element->setValue($this->get_data());
|
||||||
}
|
}
|
||||||
parent::definition_after_data($mform);
|
parent::definition_after_data($mform);
|
||||||
}
|
}
|
||||||
|
|
|
@ -43,7 +43,7 @@ class element extends \mod_customcert\element {
|
||||||
* @param \stdClass $user the user we are rendering this for
|
* @param \stdClass $user the user we are rendering this for
|
||||||
*/
|
*/
|
||||||
public function render($pdf, $preview, $user) {
|
public function render($pdf, $preview, $user) {
|
||||||
\mod_customcert\element_helper::render_content($pdf, $this, self::get_category_name($this->id));
|
\mod_customcert\element_helper::render_content($pdf, $this, self::get_category_name($this->get_id()));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -49,7 +49,7 @@ class element extends \mod_customcert\element {
|
||||||
$code = \mod_customcert\certificate::generate_code();
|
$code = \mod_customcert\certificate::generate_code();
|
||||||
} else {
|
} else {
|
||||||
// Get the page.
|
// Get the page.
|
||||||
$page = $DB->get_record('customcert_pages', array('id' => $this->element->pageid), '*', MUST_EXIST);
|
$page = $DB->get_record('customcert_pages', array('id' => $this->get_pageid()), '*', MUST_EXIST);
|
||||||
// Get the customcert this page belongs to.
|
// Get the customcert this page belongs to.
|
||||||
$customcert = $DB->get_record('customcert', array('templateid' => $page->templateid), '*', MUST_EXIST);
|
$customcert = $DB->get_record('customcert', array('templateid' => $page->templateid), '*', MUST_EXIST);
|
||||||
// Now we can get the issue for this user.
|
// Now we can get the issue for this user.
|
||||||
|
|
|
@ -43,7 +43,7 @@ class element extends \mod_customcert\element {
|
||||||
* @param \stdClass $user the user we are rendering this for
|
* @param \stdClass $user the user we are rendering this for
|
||||||
*/
|
*/
|
||||||
public function render($pdf, $preview, $user) {
|
public function render($pdf, $preview, $user) {
|
||||||
$courseid = \mod_customcert\element_helper::get_courseid($this->id);
|
$courseid = \mod_customcert\element_helper::get_courseid($this->get_id());
|
||||||
$course = get_course($courseid);
|
$course = get_course($courseid);
|
||||||
|
|
||||||
\mod_customcert\element_helper::render_content($pdf, $this, $course->fullname);
|
\mod_customcert\element_helper::render_content($pdf, $this, $course->fullname);
|
||||||
|
|
|
@ -109,14 +109,14 @@ 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->element->data)) {
|
if (empty($this->get_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->element->data);
|
$dateinfo = json_decode($this->get_data());
|
||||||
$dateitem = $dateinfo->dateitem;
|
$dateitem = $dateinfo->dateitem;
|
||||||
$dateformat = $dateinfo->dateformat;
|
$dateformat = $dateinfo->dateformat;
|
||||||
|
|
||||||
|
@ -125,7 +125,7 @@ class element extends \mod_customcert\element {
|
||||||
$date = time();
|
$date = time();
|
||||||
} else {
|
} else {
|
||||||
// Get the page.
|
// Get the page.
|
||||||
$page = $DB->get_record('customcert_pages', array('id' => $this->element->pageid), '*', MUST_EXIST);
|
$page = $DB->get_record('customcert_pages', array('id' => $this->get_pageid()), '*', MUST_EXIST);
|
||||||
// Get the customcert this page belongs to.
|
// Get the customcert this page belongs to.
|
||||||
$customcert = $DB->get_record('customcert', array('templateid' => $page->templateid), '*', MUST_EXIST);
|
$customcert = $DB->get_record('customcert', array('templateid' => $page->templateid), '*', MUST_EXIST);
|
||||||
// Now we can get the issue for this user.
|
// Now we can get the issue for this user.
|
||||||
|
@ -175,12 +175,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->element->data)) {
|
if (empty($this->get_data())) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Decode the information stored in the database.
|
// Decode the information stored in the database.
|
||||||
$dateinfo = json_decode($this->element->data);
|
$dateinfo = json_decode($this->get_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));
|
||||||
|
@ -193,10 +193,14 @@ 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->element->data)) {
|
if (!empty($this->get_data())) {
|
||||||
$dateinfo = json_decode($this->element->data);
|
$dateinfo = json_decode($this->get_data());
|
||||||
$this->element->dateitem = $dateinfo->dateitem;
|
|
||||||
$this->element->dateformat = $dateinfo->dateformat;
|
$element = $mform->getElement('dateitem');
|
||||||
|
$element->setValue($dateinfo->dateitem);
|
||||||
|
|
||||||
|
$element = $mform->getElement('dateformat');
|
||||||
|
$element->setValue($dateinfo->dateformat);
|
||||||
}
|
}
|
||||||
|
|
||||||
parent::definition_after_data($mform);
|
parent::definition_after_data($mform);
|
||||||
|
@ -213,10 +217,10 @@ class element extends \mod_customcert\element {
|
||||||
public function after_restore($restore) {
|
public function after_restore($restore) {
|
||||||
global $DB;
|
global $DB;
|
||||||
|
|
||||||
$dateinfo = json_decode($this->element->data);
|
$dateinfo = json_decode($this->get_data());
|
||||||
if ($newitem = \restore_dbops::get_backup_ids_record($restore->get_restoreid(), 'course_module', $dateinfo->dateitem)) {
|
if ($newitem = \restore_dbops::get_backup_ids_record($restore->get_restoreid(), 'course_module', $dateinfo->dateitem)) {
|
||||||
$dateinfo->dateitem = $newitem->newitemid;
|
$dateinfo->dateitem = $newitem->newitemid;
|
||||||
$DB->set_field('customcert_elements', 'data', self::save_unique_data($dateinfo), array('id' => $this->element->id));
|
$DB->set_field('customcert_elements', 'data', self::save_unique_data($dateinfo), array('id' => $this->get_id()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -96,14 +96,14 @@ 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->element->data)) {
|
if (empty($this->get_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->element->data);
|
$gradeinfo = json_decode($this->get_data());
|
||||||
|
|
||||||
// If we are previewing this certificate then just show a demonstration grade.
|
// If we are previewing this certificate then just show a demonstration grade.
|
||||||
if ($preview) {
|
if ($preview) {
|
||||||
|
@ -129,12 +129,12 @@ 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->element->data)) {
|
if (empty($this->get_data())) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Decode the information stored in the database.
|
// Decode the information stored in the database.
|
||||||
$gradeinfo = json_decode($this->element->data);
|
$gradeinfo = json_decode($this->get_data());
|
||||||
|
|
||||||
$courseitem = \grade_item::fetch_course_item($COURSE->id);
|
$courseitem = \grade_item::fetch_course_item($COURSE->id);
|
||||||
// Define how many decimals to display.
|
// Define how many decimals to display.
|
||||||
|
@ -154,10 +154,14 @@ 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->element->data)) {
|
if (!empty($this->get_data())) {
|
||||||
$gradeinfo = json_decode($this->element->data);
|
$gradeinfo = json_decode($this->get_data());
|
||||||
$this->element->gradeitem = $gradeinfo->gradeitem;
|
|
||||||
$this->element->gradeformat = $gradeinfo->gradeformat;
|
$element = $mform->getElement('gradeitem');
|
||||||
|
$element->setValue($gradeinfo->gradeitem);
|
||||||
|
|
||||||
|
$element = $mform->getElement('gradeformat');
|
||||||
|
$element->setValue($gradeinfo->gradeformat);
|
||||||
}
|
}
|
||||||
|
|
||||||
parent::definition_after_data($mform);
|
parent::definition_after_data($mform);
|
||||||
|
@ -174,10 +178,10 @@ class element extends \mod_customcert\element {
|
||||||
public function after_restore($restore) {
|
public function after_restore($restore) {
|
||||||
global $DB;
|
global $DB;
|
||||||
|
|
||||||
$gradeinfo = json_decode($this->element->data);
|
$gradeinfo = json_decode($this->get_data());
|
||||||
if ($newitem = \restore_dbops::get_backup_ids_record($restore->get_restoreid(), 'course_module', $gradeinfo->gradeitem)) {
|
if ($newitem = \restore_dbops::get_backup_ids_record($restore->get_restoreid(), 'course_module', $gradeinfo->gradeitem)) {
|
||||||
$gradeinfo->gradeitem = $newitem->newitemid;
|
$gradeinfo->gradeitem = $newitem->newitemid;
|
||||||
$DB->set_field('customcert_elements', 'data', self::save_unique_data($gradeinfo), array('id' => $this->element->id));
|
$DB->set_field('customcert_elements', 'data', self::save_unique_data($gradeinfo), array('id' => $this->get_id()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -74,9 +74,9 @@ 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->element->data)) {
|
if (!empty($this->get_data())) {
|
||||||
// Get the course module information.
|
// Get the course module information.
|
||||||
$cm = $DB->get_record('course_modules', array('id' => $this->element->data), '*', MUST_EXIST);
|
$cm = $DB->get_record('course_modules', array('id' => $this->get_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.
|
||||||
|
@ -98,9 +98,9 @@ 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->element->data)) {
|
if (!empty($this->get_data())) {
|
||||||
// Get the course module information.
|
// Get the course module information.
|
||||||
$cm = $DB->get_record('course_modules', array('id' => $this->element->data), '*', MUST_EXIST);
|
$cm = $DB->get_record('course_modules', array('id' => $this->get_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.
|
||||||
|
@ -118,8 +118,9 @@ 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->element->data)) {
|
if (!empty($this->get_data())) {
|
||||||
$this->element->gradeitem = $this->element->data;
|
$element = $mform->getElement('gradeitem');
|
||||||
|
$element->setValue($this->get_data());
|
||||||
}
|
}
|
||||||
parent::definition_after_data($mform);
|
parent::definition_after_data($mform);
|
||||||
}
|
}
|
||||||
|
|
|
@ -172,11 +172,11 @@ 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->element->data)) {
|
if (empty($this->get_data())) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
$imageinfo = json_decode($this->element->data);
|
$imageinfo = json_decode($this->get_data());
|
||||||
|
|
||||||
if ($file = $this->get_file()) {
|
if ($file = $this->get_file()) {
|
||||||
$location = make_request_directory() . '/target';
|
$location = make_request_directory() . '/target';
|
||||||
|
@ -184,9 +184,9 @@ class element extends \mod_customcert\element {
|
||||||
|
|
||||||
$mimetype = $file->get_mimetype();
|
$mimetype = $file->get_mimetype();
|
||||||
if ($mimetype == 'image/svg+xml') {
|
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 {
|
} 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() {
|
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->element->data)) {
|
if (empty($this->get_data())) {
|
||||||
return '';
|
return '';
|
||||||
}
|
}
|
||||||
|
|
||||||
$imageinfo = json_decode($this->element->data);
|
$imageinfo = json_decode($this->get_data());
|
||||||
|
|
||||||
// Get the image.
|
// Get the image.
|
||||||
$fs = get_file_storage();
|
$fs = get_file_storage();
|
||||||
|
@ -246,12 +246,17 @@ 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->element->data)) {
|
if (!empty($this->get_data())) {
|
||||||
$imageinfo = json_decode($this->element->data);
|
$imageinfo = json_decode($this->get_data());
|
||||||
if ($file = $this->get_file()) {
|
if ($file = $this->get_file()) {
|
||||||
$this->element->fileid = $file->get_id();
|
$element = $mform->getElement('fileid');
|
||||||
$this->element->width = $imageinfo->width;
|
$element->setValue($this->get_data());
|
||||||
$this->element->height = $imageinfo->height;
|
|
||||||
|
$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;
|
global $DB;
|
||||||
|
|
||||||
// Get the current data we have stored for this element.
|
// 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.
|
// Update the context.
|
||||||
$elementinfo->contextid = \context_course::instance($restore->get_courseid())->id;
|
$elementinfo->contextid = \context_course::instance($restore->get_courseid())->id;
|
||||||
|
@ -291,7 +296,7 @@ class element extends \mod_customcert\element {
|
||||||
$elementinfo = json_encode($elementinfo);
|
$elementinfo = json_encode($elementinfo);
|
||||||
|
|
||||||
// Perform the update.
|
// 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
|
* @return \stored_file|bool stored_file instance if exists, false if not
|
||||||
*/
|
*/
|
||||||
public function get_file() {
|
public function get_file() {
|
||||||
$imageinfo = json_decode($this->element->data);
|
$imageinfo = json_decode($this->get_data());
|
||||||
|
|
||||||
$fs = get_file_storage();
|
$fs = get_file_storage();
|
||||||
|
|
||||||
|
|
|
@ -71,7 +71,7 @@ class element extends \mod_customcert\element {
|
||||||
public function render($pdf, $preview, $user) {
|
public function render($pdf, $preview, $user) {
|
||||||
global $DB;
|
global $DB;
|
||||||
|
|
||||||
$teacher = $DB->get_record('user', array('id' => $this->element->data));
|
$teacher = $DB->get_record('user', array('id' => $this->get_data()));
|
||||||
$teachername = fullname($teacher);
|
$teachername = fullname($teacher);
|
||||||
|
|
||||||
\mod_customcert\element_helper::render_content($pdf, $this, $teachername);
|
\mod_customcert\element_helper::render_content($pdf, $this, $teachername);
|
||||||
|
@ -88,7 +88,7 @@ class element extends \mod_customcert\element {
|
||||||
public function render_html() {
|
public function render_html() {
|
||||||
global $DB;
|
global $DB;
|
||||||
|
|
||||||
$teacher = $DB->get_record('user', array('id' => $this->element->data));
|
$teacher = $DB->get_record('user', array('id' => $this->get_data()));
|
||||||
$teachername = fullname($teacher);
|
$teachername = fullname($teacher);
|
||||||
|
|
||||||
return \mod_customcert\element_helper::render_html_content($this, $teachername);
|
return \mod_customcert\element_helper::render_html_content($this, $teachername);
|
||||||
|
@ -121,8 +121,9 @@ 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->element->data)) {
|
if (!empty($this->get_data())) {
|
||||||
$this->element->teacher = $this->element->data;
|
$element = $mform->getElement('teacher');
|
||||||
|
$element->setValue($this->get_data());
|
||||||
}
|
}
|
||||||
parent::definition_after_data($mform);
|
parent::definition_after_data($mform);
|
||||||
}
|
}
|
||||||
|
|
|
@ -67,7 +67,7 @@ class element extends \mod_customcert\element {
|
||||||
* @param \stdClass $user the user we are rendering this for
|
* @param \stdClass $user the user we are rendering this for
|
||||||
*/
|
*/
|
||||||
public function render($pdf, $preview, $user) {
|
public function render($pdf, $preview, $user) {
|
||||||
\mod_customcert\element_helper::render_content($pdf, $this, $this->element->data);
|
\mod_customcert\element_helper::render_content($pdf, $this, $this->get_data());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -79,7 +79,7 @@ class element extends \mod_customcert\element {
|
||||||
* @return string the html
|
* @return string the html
|
||||||
*/
|
*/
|
||||||
public function render_html() {
|
public function render_html() {
|
||||||
return \mod_customcert\element_helper::render_html_content($this, $this->element->data);
|
return \mod_customcert\element_helper::render_html_content($this, $this->get_data());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -88,8 +88,9 @@ 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->element->data)) {
|
if (!empty($this->get_data())) {
|
||||||
$this->element->text = $this->element->data;
|
$element = $mform->getElement('text');
|
||||||
|
$element->setValue($this->get_data());
|
||||||
}
|
}
|
||||||
parent::definition_after_data($mform);
|
parent::definition_after_data($mform);
|
||||||
}
|
}
|
||||||
|
|
|
@ -101,7 +101,7 @@ class element extends \mod_customcert\element {
|
||||||
global $CFG, $DB;
|
global $CFG, $DB;
|
||||||
|
|
||||||
// The user field to display.
|
// The user field to display.
|
||||||
$field = $this->element->data;
|
$field = $this->get_data();
|
||||||
// The value to display on the PDF.
|
// The value to display on the PDF.
|
||||||
$value = '';
|
$value = '';
|
||||||
if (is_number($field)) { // Must be a custom user profile field.
|
if (is_number($field)) { // Must be a custom user profile field.
|
||||||
|
@ -132,7 +132,7 @@ class element extends \mod_customcert\element {
|
||||||
global $CFG, $DB, $USER;
|
global $CFG, $DB, $USER;
|
||||||
|
|
||||||
// The user field to display.
|
// The user field to display.
|
||||||
$field = $this->element->data;
|
$field = $this->get_data();
|
||||||
// The value to display - we always want to show a value here so it can be repositioned.
|
// The value to display - we always want to show a value here so it can be repositioned.
|
||||||
$value = $field;
|
$value = $field;
|
||||||
if (is_number($field)) { // Must be a custom user profile field.
|
if (is_number($field)) { // Must be a custom user profile field.
|
||||||
|
@ -164,8 +164,9 @@ 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->element->data)) {
|
if (!empty($this->get_data())) {
|
||||||
$this->element->userfield = $this->element->data;
|
$element = $mform->getElement('userfield');
|
||||||
|
$element->setValue($this->get_data());
|
||||||
}
|
}
|
||||||
parent::definition_after_data($mform);
|
parent::definition_after_data($mform);
|
||||||
}
|
}
|
||||||
|
|
|
@ -113,11 +113,11 @@ 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->element->data)) {
|
if (empty($this->get_data())) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
$imageinfo = json_decode($this->element->data);
|
$imageinfo = json_decode($this->get_data());
|
||||||
|
|
||||||
$context = \context_user::instance($user->id);
|
$context = \context_user::instance($user->id);
|
||||||
|
|
||||||
|
@ -138,10 +138,10 @@ class element extends \mod_customcert\element {
|
||||||
if ($file) {
|
if ($file) {
|
||||||
$location = make_request_directory() . '/target';
|
$location = make_request_directory() . '/target';
|
||||||
$file->copy_content_to($location);
|
$file->copy_content_to($location);
|
||||||
$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);
|
||||||
} else if ($preview) { // Can't find an image, but we are in preview mode then display default pic.
|
} else if ($preview) { // Can't find an image, but we are in preview mode then display default pic.
|
||||||
$location = $CFG->dirroot . '/pix/u/f1.png';
|
$location = $CFG->dirroot . '/pix/u/f1.png';
|
||||||
$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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -157,11 +157,11 @@ 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->element->data)) {
|
if (empty($this->get_data())) {
|
||||||
return '';
|
return '';
|
||||||
}
|
}
|
||||||
|
|
||||||
$imageinfo = json_decode($this->element->data);
|
$imageinfo = json_decode($this->get_data());
|
||||||
|
|
||||||
// Get the image.
|
// Get the image.
|
||||||
$userpicture = new \user_picture($USER);
|
$userpicture = new \user_picture($USER);
|
||||||
|
@ -194,10 +194,14 @@ 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->element->data)) {
|
if (!empty($this->get_data())) {
|
||||||
$imageinfo = json_decode($this->element->data);
|
$imageinfo = json_decode($this->get_data());
|
||||||
$this->element->width = $imageinfo->width;
|
|
||||||
$this->element->height = $imageinfo->height;
|
$element = $mform->getElement('width');
|
||||||
|
$element->setValue($imageinfo->width);
|
||||||
|
|
||||||
|
$element = $mform->getElement('height');
|
||||||
|
$element->setValue($imageinfo->height);
|
||||||
}
|
}
|
||||||
|
|
||||||
parent::definition_after_data($mform);
|
parent::definition_after_data($mform);
|
||||||
|
|
Loading…
Reference in a new issue