#41 Add setting to display the position X and Y elements
This commit is contained in:
parent
c1c2f9957e
commit
527d453950
9 changed files with 115 additions and 18 deletions
|
@ -48,15 +48,12 @@ class edit_element_form extends \moodleform {
|
|||
|
||||
$element = $this->_customdata['element'];
|
||||
|
||||
// Do not display the name if we are on the rearrange page.
|
||||
if (!isset($this->_customdata['rearrange'])) {
|
||||
// Add the field for the name of the element, this is required for all elements.
|
||||
$mform->addElement('text', 'name', get_string('elementname', 'customcert'));
|
||||
$mform->setType('name', PARAM_TEXT);
|
||||
$mform->setDefault('name', get_string('pluginname', 'customcertelement_' . $element->element));
|
||||
$mform->addRule('name', get_string('required'), 'required', null, 'client');
|
||||
$mform->addHelpButton('name', 'elementname', 'customcert');
|
||||
}
|
||||
// Add the field for the name of the element, this is required for all elements.
|
||||
$mform->addElement('text', 'name', get_string('elementname', 'customcert'));
|
||||
$mform->setType('name', PARAM_TEXT);
|
||||
$mform->setDefault('name', get_string('pluginname', 'customcertelement_' . $element->element));
|
||||
$mform->addRule('name', get_string('required'), 'required', null, 'client');
|
||||
$mform->addHelpButton('name', 'elementname', 'customcert');
|
||||
|
||||
$this->element = \mod_customcert\element::instance($element);
|
||||
$this->element->render_form_elements($mform);
|
||||
|
|
|
@ -38,13 +38,21 @@ abstract class element {
|
|||
*/
|
||||
public $element;
|
||||
|
||||
/**
|
||||
* @var bool $showposxy Show position XY form elements?
|
||||
*/
|
||||
public $showposxy;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param \stdClass $element the element data
|
||||
*/
|
||||
public function __construct($element) {
|
||||
$showposxy = get_config('customcert', 'showposxy');
|
||||
|
||||
$this->element = clone($element);
|
||||
$this->showposxy = isset($showposxy) && $showposxy;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -57,7 +65,10 @@ abstract class element {
|
|||
// Render the common elements.
|
||||
element_helper::render_form_element_font($mform);
|
||||
element_helper::render_form_element_colour($mform);
|
||||
element_helper::render_form_element_position($mform);
|
||||
if ($this->showposxy) {
|
||||
element_helper::render_form_element_position($mform);
|
||||
}
|
||||
element_helper::render_form_element_width($mform);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -91,7 +102,10 @@ abstract class element {
|
|||
|
||||
// Common validation methods.
|
||||
$errors += element_helper::validate_form_element_colour($data);
|
||||
$errors += element_helper::validate_form_element_position($data);
|
||||
if ($this->showposxy) {
|
||||
$errors += element_helper::validate_form_element_position($data);
|
||||
}
|
||||
$errors += element_helper::validate_form_element_width($data);
|
||||
|
||||
return $errors;
|
||||
}
|
||||
|
@ -113,6 +127,10 @@ abstract class element {
|
|||
$element->font = (isset($data->font)) ? $data->font : null;
|
||||
$element->size = (isset($data->size)) ? $data->size : null;
|
||||
$element->colour = (isset($data->colour)) ? $data->colour : null;
|
||||
if ($this->showposxy) {
|
||||
$element->posx = (isset($data->posx)) ? $data->posx : null;
|
||||
$element->posy = (isset($data->posy)) ? $data->posy : null;
|
||||
}
|
||||
$element->width = (isset($data->width)) ? $data->width : null;
|
||||
$element->refpoint = (isset($data->refpoint)) ? $data->refpoint : null;
|
||||
$element->timemodified = time();
|
||||
|
|
|
@ -157,6 +157,22 @@ class element_helper {
|
|||
* @param \mod_customcert\edit_element_form $mform the edit_form instance.
|
||||
*/
|
||||
public static function render_form_element_position($mform) {
|
||||
$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');
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper function to render the width element.
|
||||
*
|
||||
* @param \mod_customcert\edit_element_form $mform the edit_form instance.
|
||||
*/
|
||||
public static function render_form_element_width($mform) {
|
||||
$mform->addElement('text', 'width', get_string('elementwidth', 'customcert'), array('size' => 10));
|
||||
$mform->setType('width', PARAM_INT);
|
||||
$mform->setDefault('width', 0);
|
||||
|
@ -194,10 +210,33 @@ class element_helper {
|
|||
*/
|
||||
public static function validate_form_element_position($data) {
|
||||
$errors = array();
|
||||
|
||||
// Check if posx is not set, or not numeric or less than 0.
|
||||
if ((!isset($data['posx'])) || (!is_numeric($data['posx'])) || ($data['posx'] < 0)) {
|
||||
$errors['posx'] = get_string('invalidposition', 'customcert', 'X');
|
||||
}
|
||||
// Check if posy is not set, or not numeric or less than 0.
|
||||
if ((!isset($data['posy'])) || (!is_numeric($data['posy'])) || ($data['posy'] < 0)) {
|
||||
$errors['posy'] = get_string('invalidposition', 'customcert', 'Y');
|
||||
}
|
||||
|
||||
return $errors;
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper function to perform validation on the width element.
|
||||
*
|
||||
* @param array $data the submitted data
|
||||
* @return array the validation errors
|
||||
*/
|
||||
public static function validate_form_element_width($data) {
|
||||
$errors = array();
|
||||
|
||||
// Check if width is less than 0.
|
||||
if (isset($data['width']) && $data['width'] < 0) {
|
||||
$errors['width'] = get_string('invalidelementwidth', 'customcert');
|
||||
}
|
||||
|
||||
return $errors;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue