2013-06-06 10:59:08 +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-06-06 10:59:08 +00:00
|
|
|
|
2017-02-16 12:12:19 +00:00
|
|
|
/**
|
|
|
|
* This file contains the form for handling editing a customcert element.
|
|
|
|
*
|
|
|
|
* @package mod_customcert
|
|
|
|
* @copyright 2013 Mark Nelson <markn@moodle.com>
|
|
|
|
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
|
|
|
*/
|
|
|
|
|
2016-02-16 09:03:34 +00:00
|
|
|
namespace mod_customcert;
|
|
|
|
|
2013-06-06 10:59:08 +00:00
|
|
|
defined('MOODLE_INTERNAL') || die('Direct access to this script is forbidden.');
|
|
|
|
|
|
|
|
require_once($CFG->dirroot . '/course/moodleform_mod.php');
|
|
|
|
require_once($CFG->dirroot . '/mod/customcert/includes/colourpicker.php');
|
|
|
|
|
2016-02-16 09:03:34 +00:00
|
|
|
\MoodleQuickForm::registerElementType('customcert_colourpicker',
|
2013-06-06 10:59:08 +00:00
|
|
|
$CFG->dirroot . '/mod/customcert/includes/colourpicker.php', 'MoodleQuickForm_customcert_colourpicker');
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The form for handling editing a customcert element.
|
|
|
|
*
|
|
|
|
* @package mod_customcert
|
2013-07-22 05:06:18 +00:00
|
|
|
* @copyright 2013 Mark Nelson <markn@moodle.com>
|
2013-06-06 10:59:08 +00:00
|
|
|
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
|
|
|
*/
|
2016-02-16 09:03:34 +00:00
|
|
|
class edit_element_form extends \moodleform {
|
2013-06-06 10:59:08 +00:00
|
|
|
|
|
|
|
/**
|
2016-02-16 09:03:34 +00:00
|
|
|
* @var \mod_customcert\element The element object.
|
2013-06-06 10:59:08 +00:00
|
|
|
*/
|
2016-02-16 09:03:34 +00:00
|
|
|
protected $element;
|
2013-06-06 10:59:08 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Form definition.
|
|
|
|
*/
|
2013-07-23 06:44:11 +00:00
|
|
|
public function definition() {
|
2013-06-06 10:59:08 +00:00
|
|
|
$mform =& $this->_form;
|
|
|
|
|
2016-06-13 11:39:57 +00:00
|
|
|
$mform->updateAttributes(array('id' => 'editelementform'));
|
|
|
|
|
2013-06-06 10:59:08 +00:00
|
|
|
$element = $this->_customdata['element'];
|
|
|
|
|
2016-10-21 13:33:59 +00:00
|
|
|
// Add the field for the name of the element, this is required for all elements.
|
2017-01-31 09:15:49 +00:00
|
|
|
$mform->addElement('text', 'name', get_string('elementname', 'customcert'), 'maxlength="255"');
|
2016-10-21 13:33:59 +00:00
|
|
|
$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');
|
2013-06-06 10:59:08 +00:00
|
|
|
|
2017-08-26 05:27:19 +00:00
|
|
|
$this->element = \mod_customcert\element_factory::get_element_instance($element);
|
2019-05-10 02:56:33 +00:00
|
|
|
$this->element->set_edit_element_form($this);
|
2013-06-06 10:59:08 +00:00
|
|
|
$this->element->render_form_elements($mform);
|
|
|
|
|
|
|
|
$this->add_action_buttons(true);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Fill in the current page data for this customcert.
|
|
|
|
*/
|
2013-07-23 06:44:11 +00:00
|
|
|
public function definition_after_data() {
|
2015-12-10 07:26:49 +00:00
|
|
|
$this->element->definition_after_data($this->_form);
|
2013-06-06 10:59:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Validation.
|
|
|
|
*
|
2013-06-12 10:35:27 +00:00
|
|
|
* @param array $data
|
|
|
|
* @param array $files
|
2013-06-06 10:59:08 +00:00
|
|
|
* @return array the errors that were found
|
|
|
|
*/
|
|
|
|
public function validation($data, $files) {
|
2017-01-31 09:15:49 +00:00
|
|
|
$errors = array();
|
|
|
|
|
|
|
|
if (\core_text::strlen($data['name']) > 255) {
|
|
|
|
$errors['name'] = get_string('nametoolong', 'customcert');
|
|
|
|
}
|
|
|
|
|
|
|
|
$errors += $this->element->validate_form_elements($data, $files);
|
|
|
|
|
|
|
|
return $errors;
|
2013-06-06 10:59:08 +00:00
|
|
|
}
|
|
|
|
}
|