2013-02-20 12:21:57 +00:00
|
|
|
<?php
|
|
|
|
// This file is part of the customcert module for Moodle - http://moodle.org/
|
|
|
|
//
|
|
|
|
// Moodle is free software: you can redistribute it and/or modify
|
|
|
|
// it under the terms of the GNU General Public License as published by
|
|
|
|
// the Free Software Foundation, either version 3 of the License, or
|
|
|
|
// (at your option) any later version.
|
|
|
|
//
|
|
|
|
// Moodle is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
// GNU General Public License for more details.
|
|
|
|
//
|
|
|
|
// You should have received a copy of the GNU General Public License
|
2013-07-22 05:06:18 +00:00
|
|
|
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
2013-02-20 12:21:57 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* The base class for the customcert elements.
|
|
|
|
*
|
2013-04-26 07:30:33 +00:00
|
|
|
* @package mod_customcert
|
2013-07-22 05:06:18 +00:00
|
|
|
* @copyright 2013 Mark Nelson <markn@moodle.com>
|
2013-02-20 12:21:57 +00:00
|
|
|
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
|
|
|
*/
|
|
|
|
|
2013-04-10 09:17:19 +00:00
|
|
|
defined('MOODLE_INTERNAL') || die('Direct access to this script is forbidden.');
|
2013-02-20 12:21:57 +00:00
|
|
|
|
2013-06-12 10:35:27 +00:00
|
|
|
/**
|
2013-06-21 09:35:14 +00:00
|
|
|
* Class customcert_element_base
|
2013-06-12 10:35:27 +00:00
|
|
|
*
|
|
|
|
* All customercert element plugins are based on this class.
|
|
|
|
*/
|
2013-06-21 09:35:14 +00:00
|
|
|
abstract class customcert_element_base {
|
2013-02-20 12:21:57 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* The data for the element we are adding.
|
|
|
|
*/
|
|
|
|
public $element;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Constructor.
|
|
|
|
*
|
|
|
|
* @param stdClass $element the element data
|
|
|
|
*/
|
2013-07-23 04:29:27 +00:00
|
|
|
public function __construct($element) {
|
2013-06-06 10:59:08 +00:00
|
|
|
$this->element = clone($element);
|
2013-02-20 12:21:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* This function renders the form elements when adding a customcert element.
|
2013-02-26 09:22:52 +00:00
|
|
|
* Can be overridden if more functionality is needed.
|
2013-02-20 12:21:57 +00:00
|
|
|
*
|
2013-06-12 10:35:27 +00:00
|
|
|
* @param mod_customcert_edit_element_form $mform the edit_form instance.
|
2013-02-20 12:21:57 +00:00
|
|
|
*/
|
|
|
|
public function render_form_elements($mform) {
|
2013-05-30 08:28:47 +00:00
|
|
|
// Render the common elements.
|
2013-06-21 09:35:14 +00:00
|
|
|
$this->render_form_element_font($mform);
|
|
|
|
$this->render_form_element_colour($mform);
|
|
|
|
$this->render_form_element_position($mform);
|
2013-05-03 10:51:41 +00:00
|
|
|
}
|
2013-02-20 12:21:57 +00:00
|
|
|
|
2013-06-06 10:59:08 +00:00
|
|
|
/**
|
|
|
|
* Sets the data on the form when editing an element.
|
|
|
|
* Can be overridden if more functionality is needed.
|
|
|
|
*
|
2013-06-12 10:35:27 +00:00
|
|
|
* @param mod_customcert_edit_element_form $mform the edit_form instance
|
2013-06-06 10:59:08 +00:00
|
|
|
* @param array the form elements to set
|
|
|
|
*/
|
|
|
|
public function definition_after_data($mform) {
|
|
|
|
// Loop through the properties of the element and set the values
|
|
|
|
// of the corresponding form element, if it exists.
|
|
|
|
foreach ($this->element as $property => $value) {
|
|
|
|
if ($mform->elementExists($property)) {
|
|
|
|
$element = $mform->getElement($property);
|
|
|
|
$element->setValue($value);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-02-20 12:21:57 +00:00
|
|
|
/**
|
|
|
|
* Performs validation on the element values.
|
|
|
|
* Can be overridden if more functionality is needed.
|
|
|
|
*
|
|
|
|
* @param array $data the submitted data
|
2013-03-14 01:16:37 +00:00
|
|
|
* @param array $files the submitted files
|
2013-02-20 12:21:57 +00:00
|
|
|
* @return array the validation errors
|
|
|
|
*/
|
|
|
|
public function validate_form_elements($data, $files) {
|
2013-05-30 08:28:47 +00:00
|
|
|
// Array to return the errors.
|
2013-02-20 12:21:57 +00:00
|
|
|
$errors = array();
|
|
|
|
|
2013-05-30 08:28:47 +00:00
|
|
|
// Common validation methods.
|
2013-06-21 09:35:14 +00:00
|
|
|
$errors += $this->validate_form_element_colour($data);
|
|
|
|
$errors += $this->validate_form_element_position($data);
|
2013-02-20 12:21:57 +00:00
|
|
|
|
|
|
|
return $errors;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Handles saving the form elements created by this element.
|
2013-04-29 10:10:06 +00:00
|
|
|
* Can be overridden if more functionality is needed.
|
2013-02-20 12:21:57 +00:00
|
|
|
*
|
2013-06-06 10:59:08 +00:00
|
|
|
* @param stdClass $data the form data
|
2013-02-20 12:21:57 +00:00
|
|
|
*/
|
|
|
|
public function save_form_elements($data) {
|
|
|
|
global $DB;
|
|
|
|
|
|
|
|
// Get the data from the form.
|
|
|
|
$element = new stdClass();
|
2013-06-06 10:59:08 +00:00
|
|
|
$element->name = $data->name;
|
2013-05-30 08:28:47 +00:00
|
|
|
$element->data = $this->save_unique_data($data);
|
2013-06-06 10:59:08 +00:00
|
|
|
$element->font = (isset($data->font)) ? $data->font : null;
|
|
|
|
$element->size = (isset($data->size)) ? $data->size : null;
|
|
|
|
$element->colour = (isset($data->colour)) ? $data->colour : null;
|
|
|
|
$element->posx = (isset($data->posx)) ? $data->posx : null;
|
|
|
|
$element->posy = (isset($data->posy)) ? $data->posy : null;
|
2015-07-29 01:29:16 +00:00
|
|
|
$element->width = (isset($data->width)) ? $data->width : null;
|
2015-07-30 04:51:50 +00:00
|
|
|
$element->refpoint = (isset($data->refpoint)) ? $data->refpoint : null;
|
2013-04-24 09:24:57 +00:00
|
|
|
$element->timemodified = time();
|
2013-02-20 12:21:57 +00:00
|
|
|
|
2013-06-06 10:59:08 +00:00
|
|
|
// Check if we are updating, or inserting a new element.
|
|
|
|
if (!empty($this->element->id)) { // Must be updating a record in the database.
|
|
|
|
$element->id = $this->element->id;
|
|
|
|
$DB->update_record('customcert_elements', $element);
|
|
|
|
} else { // Must be adding a new one.
|
|
|
|
$element->element = $data->element;
|
|
|
|
$element->pageid = $data->pageid;
|
|
|
|
$element->sequence = $this->get_element_sequence($element->pageid);
|
|
|
|
$element->timecreated = time();
|
|
|
|
$DB->insert_record('customcert_elements', $element);
|
|
|
|
}
|
2013-02-20 12:21:57 +00:00
|
|
|
}
|
|
|
|
|
2013-02-22 08:15:32 +00:00
|
|
|
/**
|
|
|
|
* This will handle how form data will be saved into the data column in the
|
|
|
|
* customcert column.
|
2013-04-29 10:10:06 +00:00
|
|
|
* Can be overridden if more functionality is needed.
|
2013-02-22 08:15:32 +00:00
|
|
|
*
|
2013-06-06 10:59:08 +00:00
|
|
|
* @param stdClass $data the form data
|
2013-05-28 08:33:46 +00:00
|
|
|
* @return string the unique data to save
|
2013-02-22 08:15:32 +00:00
|
|
|
*/
|
|
|
|
public function save_unique_data($data) {
|
2013-05-28 08:33:46 +00:00
|
|
|
return '';
|
2013-02-22 08:15:32 +00:00
|
|
|
}
|
|
|
|
|
2013-05-03 10:51:41 +00:00
|
|
|
/**
|
|
|
|
* This will handle how individual elements save their data
|
|
|
|
* to a template to be loaded later.
|
|
|
|
* Can be overridden if more functionality is needed.
|
|
|
|
*
|
2013-05-28 08:33:46 +00:00
|
|
|
* @param stdClass $data the form data
|
|
|
|
* @return bool returns true if the data was saved to the template, false otherwise
|
2013-05-03 10:51:41 +00:00
|
|
|
*/
|
|
|
|
public function save_data_to_template($data) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* This will handle how individual elements load their data
|
|
|
|
* from a template to an existing customcert.
|
|
|
|
* Can be overridden if more functionality is needed.
|
|
|
|
*
|
2013-05-28 08:33:46 +00:00
|
|
|
* @param stdClass $data the form data
|
|
|
|
* @return bool returns true if the data was loaded from the template, false otherwise
|
2013-05-03 10:51:41 +00:00
|
|
|
*/
|
|
|
|
public function load_data_from_template($data) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2013-02-20 12:21:57 +00:00
|
|
|
/**
|
2013-04-10 09:53:56 +00:00
|
|
|
* Handles rendering the element on the pdf.
|
2013-04-29 10:10:06 +00:00
|
|
|
* Must be overridden.
|
2013-02-20 12:21:57 +00:00
|
|
|
*
|
2013-06-12 10:35:27 +00:00
|
|
|
* @param pdf $pdf the pdf object
|
2013-06-28 07:17:43 +00:00
|
|
|
* @param bool $preview true if it is a preview, false otherwise
|
2013-02-20 12:21:57 +00:00
|
|
|
*/
|
2013-07-25 05:53:45 +00:00
|
|
|
public abstract function render($pdf, $preview);
|
2013-02-20 12:21:57 +00:00
|
|
|
|
2013-04-11 10:42:23 +00:00
|
|
|
/**
|
|
|
|
* Common behaviour for rendering specified content on the pdf.
|
|
|
|
*
|
2013-06-12 10:35:27 +00:00
|
|
|
* @param pdf $pdf the pdf object
|
2013-06-05 08:42:18 +00:00
|
|
|
* @param string $content the content to render
|
2013-04-11 10:42:23 +00:00
|
|
|
*/
|
|
|
|
public function render_content($pdf, $content) {
|
2015-08-05 05:38:35 +00:00
|
|
|
list($font, $attr) = $this->get_font();
|
|
|
|
$pdf->setFont($font, $attr, $this->element->size);
|
2013-04-11 10:42:23 +00:00
|
|
|
$fontcolour = TCPDF_COLORS::convertHTMLColorToDec($this->element->colour, $fontcolour);
|
|
|
|
$pdf->SetTextColor($fontcolour['R'], $fontcolour['G'], $fontcolour['B']);
|
2015-07-30 04:51:50 +00:00
|
|
|
|
|
|
|
$x = $this->element->posx;
|
|
|
|
$y = $this->element->posy;
|
|
|
|
$w = $this->element->width;
|
|
|
|
$refpoint = $this->element->refpoint;
|
|
|
|
$actualwidth = $pdf->GetStringWidth($content);
|
|
|
|
|
|
|
|
if ($w and $w < $actualwidth) {
|
|
|
|
$actualwidth = $w;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch ($refpoint) {
|
|
|
|
case CUSTOMCERT_REF_POINT_TOPRIGHT:
|
|
|
|
$x = $this->element->posx - $actualwidth;
|
|
|
|
if ($x < 0) {
|
|
|
|
$x = 0;
|
|
|
|
$w = $this->element->posx;
|
2015-08-05 05:23:08 +00:00
|
|
|
} else {
|
|
|
|
$w = $actualwidth;
|
2015-07-30 04:51:50 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case CUSTOMCERT_REF_POINT_TOPCENTER:
|
|
|
|
$x = $this->element->posx - $actualwidth / 2;
|
|
|
|
if ($x < 0) {
|
|
|
|
$x = 0;
|
|
|
|
$w = $this->element->posx * 2;
|
2015-08-05 05:23:08 +00:00
|
|
|
} else {
|
|
|
|
$w = $actualwidth;
|
2015-07-30 04:51:50 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2015-08-05 05:23:08 +00:00
|
|
|
if ($w) {
|
|
|
|
$w += 0.0001;
|
|
|
|
}
|
|
|
|
$pdf->setCellPaddings(0, 0, 0, 0);
|
2015-12-06 12:54:18 +00:00
|
|
|
$pdf->writeHTMLCell($w, 0, $x, $y, $content, 0, 0, false, true);
|
2013-04-11 10:42:23 +00:00
|
|
|
}
|
|
|
|
|
2015-08-05 05:38:35 +00:00
|
|
|
/**
|
|
|
|
* Render the element in html.
|
|
|
|
*
|
|
|
|
* Must be overridden.
|
|
|
|
*
|
|
|
|
* This function is used to render the element when we are using the
|
|
|
|
* drag and drop interface to position it.
|
|
|
|
*/
|
|
|
|
public abstract function render_html();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Common behaviour for rendering specified content on the drag and drop page.
|
|
|
|
*
|
|
|
|
* @param string $content the content to render
|
|
|
|
* @return string the html
|
|
|
|
*/
|
|
|
|
public function render_html_content($content) {
|
|
|
|
list($font, $attr) = $this->get_font();
|
|
|
|
$fontstyle = 'font-family: ' . $font;
|
|
|
|
if (strpos($attr, 'B') !== false) {
|
|
|
|
$fontstyle .= ': font-weight: bold';
|
|
|
|
}
|
|
|
|
if (strpos($attr, 'I') !== false) {
|
|
|
|
$fontstyle .= ': font-style: italic';
|
|
|
|
}
|
|
|
|
$style = $fontstyle . '; color: ' . $this->element->colour . '; font-size: ' . $this->element->size . 'pt';
|
|
|
|
return html_writer::tag('span', $content, array('style' => $style));
|
|
|
|
}
|
|
|
|
|
2013-02-20 12:21:57 +00:00
|
|
|
/**
|
|
|
|
* Handles deleting any data this element may have introduced.
|
2013-04-29 10:10:06 +00:00
|
|
|
* Can be overridden if more functionality is needed.
|
2013-02-20 12:21:57 +00:00
|
|
|
*
|
|
|
|
* @return bool success return true if deletion success, false otherwise
|
|
|
|
*/
|
|
|
|
public function delete_element() {
|
|
|
|
global $DB;
|
|
|
|
|
|
|
|
return $DB->delete_records('customcert_elements', array('id' => $this->element->id));
|
|
|
|
}
|
2013-02-24 15:41:33 +00:00
|
|
|
|
2013-05-30 08:28:47 +00:00
|
|
|
/**
|
|
|
|
* Helper function that returns the sequence on a specified customcert page for a
|
|
|
|
* newly created element.
|
|
|
|
*
|
|
|
|
* @param int $pageid the id of the page we are adding this element to
|
|
|
|
* @return int the element number
|
|
|
|
*/
|
|
|
|
public static function get_element_sequence($pageid) {
|
|
|
|
global $DB;
|
|
|
|
|
|
|
|
// Set the sequence of the element we are creating.
|
|
|
|
$sequence = 1;
|
|
|
|
// Check if there already elements that exist, if so, overwrite value.
|
|
|
|
$sql = "SELECT MAX(sequence) as maxsequence
|
2015-03-11 08:22:44 +00:00
|
|
|
FROM {customcert_elements}
|
|
|
|
WHERE pageid = :id";
|
2013-05-30 08:28:47 +00:00
|
|
|
// Get the current max sequence on this page and add 1 to get the new sequence.
|
|
|
|
if ($maxseq = $DB->get_record_sql($sql, array('id' => $pageid))) {
|
|
|
|
$sequence = $maxseq->maxsequence + 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return $sequence;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Helper function to render the font elements.
|
|
|
|
*
|
2013-06-12 10:35:27 +00:00
|
|
|
* @param mod_customcert_edit_element_form $mform the edit_form instance.
|
2013-05-30 08:28:47 +00:00
|
|
|
*/
|
2013-06-21 09:35:14 +00:00
|
|
|
public function render_form_element_font($mform) {
|
2013-06-06 10:59:08 +00:00
|
|
|
$mform->addElement('select', 'font', get_string('font', 'customcert'), customcert_get_fonts());
|
|
|
|
$mform->setType('font', PARAM_TEXT);
|
|
|
|
$mform->setDefault('font', 'times');
|
|
|
|
$mform->addHelpButton('font', 'font', 'customcert');
|
|
|
|
|
|
|
|
$mform->addElement('select', 'size', get_string('fontsize', 'customcert'), customcert_get_font_sizes());
|
|
|
|
$mform->setType('size', PARAM_INT);
|
|
|
|
$mform->setDefault('size', 12);
|
|
|
|
$mform->addHelpButton('size', 'fontsize', 'customcert');
|
2013-05-30 08:28:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Helper function to render the colour elements.
|
|
|
|
*
|
2013-06-12 10:35:27 +00:00
|
|
|
* @param mod_customcert_edit_element_form $mform the edit_form instance.
|
2013-05-30 08:28:47 +00:00
|
|
|
*/
|
2013-06-21 09:35:14 +00:00
|
|
|
public function render_form_element_colour($mform) {
|
2013-06-06 10:59:08 +00:00
|
|
|
$mform->addElement('customcert_colourpicker', 'colour', get_string('fontcolour', 'customcert'));
|
|
|
|
$mform->setType('colour', PARAM_RAW); // Need to validate that this is a valid colour.
|
|
|
|
$mform->setDefault('colour', '#000000');
|
|
|
|
$mform->addHelpButton('colour', 'fontcolour', 'customcert');
|
2013-05-30 08:28:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Helper function to render the position elements.
|
|
|
|
*
|
2013-06-12 10:35:27 +00:00
|
|
|
* @param mod_customcert_edit_element_form $mform the edit_form instance.
|
2013-05-30 08:28:47 +00:00
|
|
|
*/
|
2013-06-21 09:35:14 +00:00
|
|
|
public function render_form_element_position($mform) {
|
2013-06-06 10:59:08 +00:00
|
|
|
$mform->addElement('text', 'posx', get_string('posx', 'customcert'), array('size' => 10));
|
|
|
|
$mform->setType('posx', PARAM_INT);
|
|
|
|
$mform->setDefault('posx', '0');
|
|
|
|
$mform->addHelpButton('posx', 'posx', 'customcert');
|
|
|
|
|
|
|
|
$mform->addElement('text', 'posy', get_string('posy', 'customcert'), array('size' => 10));
|
|
|
|
$mform->setType('posy', PARAM_INT);
|
|
|
|
$mform->setDefault('posy', '0');
|
|
|
|
$mform->addHelpButton('posy', 'posy', 'customcert');
|
2015-07-29 01:29:16 +00:00
|
|
|
|
|
|
|
$mform->addElement('text', 'width', get_string('elementwidth', 'customcert'), array('size' => 10));
|
|
|
|
$mform->setType('width', PARAM_INT);
|
|
|
|
$mform->setDefault('width', '');
|
|
|
|
$mform->addHelpButton('width', 'elementwidth', 'customcert');
|
2015-07-30 04:51:50 +00:00
|
|
|
|
|
|
|
$refpointoptions = array();
|
|
|
|
$refpointoptions[CUSTOMCERT_REF_POINT_TOPLEFT] = get_string('topleft', 'customcert');
|
|
|
|
$refpointoptions[CUSTOMCERT_REF_POINT_TOPCENTER] = get_string('topcenter', 'customcert');
|
|
|
|
$refpointoptions[CUSTOMCERT_REF_POINT_TOPRIGHT] = get_string('topright', 'customcert');
|
|
|
|
|
|
|
|
$mform->addElement('select', 'refpoint', get_string('refpoint', 'customcert'), $refpointoptions);
|
|
|
|
$mform->setType('refpoint', PARAM_INT);
|
|
|
|
$mform->setDefault('refpoint', '');
|
|
|
|
$mform->addHelpButton('refpoint', 'refpoint', 'customcert');
|
2013-05-30 08:28:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Helper function to performs validation on the colour element.
|
|
|
|
*
|
|
|
|
* @param array $data the submitted data
|
|
|
|
* @return array the validation errors
|
|
|
|
*/
|
2013-06-21 09:35:14 +00:00
|
|
|
public function validate_form_element_colour($data) {
|
2013-05-30 08:28:47 +00:00
|
|
|
$errors = array();
|
|
|
|
|
|
|
|
// Validate the colour.
|
2013-06-06 10:59:08 +00:00
|
|
|
if (!$this->validate_colour($data['colour'])) {
|
|
|
|
$errors['colour'] = get_string('invalidcolour', 'customcert');
|
2013-05-30 08:28:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return $errors;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Helper function to performs validation on the position elements.
|
|
|
|
*
|
|
|
|
* @param array $data the submitted data
|
|
|
|
* @return array the validation errors
|
|
|
|
*/
|
2013-06-21 09:35:14 +00:00
|
|
|
public function validate_form_element_position($data) {
|
2013-05-30 08:28:47 +00:00
|
|
|
$errors = array();
|
|
|
|
|
|
|
|
// Check if posx is not set, or not numeric or less than 0.
|
2013-06-06 10:59:08 +00:00
|
|
|
if ((!isset($data['posx'])) || (!is_numeric($data['posx'])) || ($data['posx'] < 0)) {
|
|
|
|
$errors['posx'] = get_string('invalidposition', 'customcert', 'X');
|
2013-05-30 08:28:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Check if posy is not set, or not numeric or less than 0.
|
2013-06-06 10:59:08 +00:00
|
|
|
if ((!isset($data['posy'])) || (!is_numeric($data['posy'])) || ($data['posy'] < 0)) {
|
|
|
|
$errors['posy'] = get_string('invalidposition', 'customcert', 'Y');
|
2013-05-30 08:28:47 +00:00
|
|
|
}
|
|
|
|
|
2015-07-29 01:29:16 +00:00
|
|
|
// Check if width is less than 0.
|
|
|
|
if (isset($data['width']) && $data['width'] < 0) {
|
|
|
|
$errors['width'] = get_string('invalidelementwidth', 'customcert');
|
|
|
|
}
|
|
|
|
|
2013-05-30 08:28:47 +00:00
|
|
|
return $errors;
|
|
|
|
}
|
|
|
|
|
2013-05-17 04:15:01 +00:00
|
|
|
/**
|
2015-08-05 05:38:35 +00:00
|
|
|
* Returns the font used for this element.
|
2013-05-17 04:15:01 +00:00
|
|
|
*
|
2015-08-05 05:38:35 +00:00
|
|
|
* @return array the font and font attributes
|
2013-05-17 04:15:01 +00:00
|
|
|
*/
|
2015-08-05 05:38:35 +00:00
|
|
|
public function get_font() {
|
2013-05-17 04:15:01 +00:00
|
|
|
// Variable for the font.
|
|
|
|
$font = $this->element->font;
|
|
|
|
// Get the last two characters of the font name.
|
|
|
|
$fontlength = strlen($font);
|
|
|
|
$lastchar = $font[$fontlength - 1];
|
|
|
|
$secondlastchar = $font[$fontlength - 2];
|
|
|
|
// The attributes of the font.
|
|
|
|
$attr = '';
|
|
|
|
// Check if the last character is 'i'.
|
|
|
|
if ($lastchar == 'i') {
|
|
|
|
// Remove the 'i' from the font name.
|
|
|
|
$font = substr($font, 0, -1);
|
|
|
|
// Check if the second last char is b.
|
|
|
|
if ($secondlastchar == 'b') {
|
|
|
|
// Remove the 'b' from the font name.
|
|
|
|
$font = substr($font, 0, -1);
|
|
|
|
$attr .= 'B';
|
|
|
|
}
|
|
|
|
$attr .= 'I';
|
|
|
|
} else if ($lastchar == 'b') {
|
|
|
|
// Remove the 'b' from the font name.
|
|
|
|
$font = substr($font, 0, -1);
|
|
|
|
$attr .= 'B';
|
|
|
|
}
|
2015-08-05 05:38:35 +00:00
|
|
|
return array($font, $attr);
|
2013-05-17 04:15:01 +00:00
|
|
|
}
|
|
|
|
|
2013-07-23 05:21:54 +00:00
|
|
|
/**
|
|
|
|
* This function is responsible for handling the restoration process of the element.
|
|
|
|
*
|
|
|
|
* For example, the function may save data that is related to another course module, this
|
|
|
|
* data will need to be updated if we are restoring the course as the course module id will
|
|
|
|
* be different in the new course.
|
|
|
|
*
|
|
|
|
* @param restore_customcert_activity_task $restore
|
|
|
|
*/
|
|
|
|
public function after_restore($restore) {
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2013-02-24 15:41:33 +00:00
|
|
|
/**
|
|
|
|
* Validates the colour selected.
|
|
|
|
*
|
2013-05-28 08:33:46 +00:00
|
|
|
* @param string $colour
|
|
|
|
* @return bool returns true if the colour is valid, false otherwise
|
2013-02-24 15:41:33 +00:00
|
|
|
*/
|
|
|
|
protected function validate_colour($colour) {
|
2013-07-23 04:32:07 +00:00
|
|
|
// List of valid HTML colour names.
|
2013-02-24 15:41:33 +00:00
|
|
|
$colournames = array(
|
|
|
|
'aliceblue', 'antiquewhite', 'aqua', 'aquamarine', 'azure',
|
|
|
|
'beige', 'bisque', 'black', 'blanchedalmond', 'blue',
|
|
|
|
'blueviolet', 'brown', 'burlywood', 'cadetblue', 'chartreuse',
|
|
|
|
'chocolate', 'coral', 'cornflowerblue', 'cornsilk', 'crimson',
|
|
|
|
'cyan', 'darkblue', 'darkcyan', 'darkgoldenrod', 'darkgray',
|
|
|
|
'darkgrey', 'darkgreen', 'darkkhaki', 'darkmagenta',
|
|
|
|
'darkolivegreen', 'darkorange', 'darkorchid', 'darkred',
|
|
|
|
'darksalmon', 'darkseagreen', 'darkslateblue', 'darkslategray',
|
|
|
|
'darkslategrey', 'darkturquoise', 'darkviolet', 'deeppink',
|
|
|
|
'deepskyblue', 'dimgray', 'dimgrey', 'dodgerblue', 'firebrick',
|
|
|
|
'floralwhite', 'forestgreen', 'fuchsia', 'gainsboro',
|
|
|
|
'ghostwhite', 'gold', 'goldenrod', 'gray', 'grey', 'green',
|
|
|
|
'greenyellow', 'honeydew', 'hotpink', 'indianred', 'indigo',
|
|
|
|
'ivory', 'khaki', 'lavender', 'lavenderblush', 'lawngreen',
|
|
|
|
'lemonchiffon', 'lightblue', 'lightcoral', 'lightcyan',
|
|
|
|
'lightgoldenrodyellow', 'lightgray', 'lightgrey', 'lightgreen',
|
|
|
|
'lightpink', 'lightsalmon', 'lightseagreen', 'lightskyblue',
|
|
|
|
'lightslategray', 'lightslategrey', 'lightsteelblue', 'lightyellow',
|
|
|
|
'lime', 'limegreen', 'linen', 'magenta', 'maroon',
|
|
|
|
'mediumaquamarine', 'mediumblue', 'mediumorchid', 'mediumpurple',
|
|
|
|
'mediumseagreen', 'mediumslateblue', 'mediumspringgreen',
|
|
|
|
'mediumturquoise', 'mediumvioletred', 'midnightblue', 'mintcream',
|
|
|
|
'mistyrose', 'moccasin', 'navajowhite', 'navy', 'oldlace', 'olive',
|
|
|
|
'olivedrab', 'orange', 'orangered', 'orchid', 'palegoldenrod',
|
|
|
|
'palegreen', 'paleturquoise', 'palevioletred', 'papayawhip',
|
|
|
|
'peachpuff', 'peru', 'pink', 'plum', 'powderblue', 'purple', 'red',
|
|
|
|
'rosybrown', 'royalblue', 'saddlebrown', 'salmon', 'sandybrown',
|
|
|
|
'seagreen', 'seashell', 'sienna', 'silver', 'skyblue', 'slateblue',
|
|
|
|
'slategray', 'slategrey', 'snow', 'springgreen', 'steelblue', 'tan',
|
|
|
|
'teal', 'thistle', 'tomato', 'turquoise', 'violet', 'wheat', 'white',
|
|
|
|
'whitesmoke', 'yellow', 'yellowgreen'
|
|
|
|
);
|
|
|
|
|
|
|
|
if (preg_match('/^#?([[:xdigit:]]{3}){1,2}$/', $colour)) {
|
|
|
|
return true;
|
|
|
|
} else if (in_array(strtolower($colour), $colournames)) {
|
|
|
|
return true;
|
|
|
|
}
|
2013-04-11 11:25:55 +00:00
|
|
|
|
|
|
|
return false;
|
2013-02-24 15:41:33 +00:00
|
|
|
}
|
|
|
|
}
|