moodle-mod_htmlcert/classes/edit_form.php

120 lines
4 KiB
PHP

<?php
// This file is part of the htmlcert 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
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* This file contains the form for handling the layout of the htmlcert instance.
*
* @package mod_htmlcert
* @copyright 2013 Mark Nelson <markn@moodle.com>, 2021 Klaus-Uwe Mitterer <kumitterer@kumi.systems>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace mod_htmlcert;
defined('MOODLE_INTERNAL') || die('Direct access to this script is forbidden.');
require_once($CFG->dirroot . '/course/moodleform_mod.php');
/**
* The form for handling the layout of the htmlcert instance.
*
* @package mod_htmlcert
* @copyright 2013 Mark Nelson <markn@moodle.com>, 2021 Klaus-Uwe Mitterer <kumitterer@kumi.systems>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class edit_form extends \moodleform {
/**
* @var int The id of the template being used.
*/
protected $tid = null;
/**
* Form definition.
*/
public function definition() {
global $DB, $OUTPUT;
$mform =& $this->_form;
$mform->addElement('text', 'name', get_string('name', 'htmlcert'), 'maxlength="255"');
$mform->setType('name', PARAM_TEXT);
$mform->addRule('name', null, 'required');
$mform->addElement('textarea', 'html', get_string('html', 'htmlcert'));
$mform->setType('html', PARAM_RAW);
$mform->addRule('html', null, 'required');
// Add the submit buttons.
$group = array();
$group[] = $mform->createElement('submit', 'submitbtn', get_string('savechanges'));
$group[] = $mform->createElement('submit', 'previewbtn', get_string('savechangespreview', 'htmlcert'), array(), false);
$mform->addElement('group', 'submitbtngroup', '', $group, '', false);
}
/**
* Fill in the current page data for this htmlcert.
*/
public function definition_after_data() {
global $DB;
$mform = $this->_form;
}
/**
* Some basic validation.
*
* @param array $data
* @param array $files
* @return array the errors that were found
*/
public function validation($data, $files) {
$errors = parent::validation($data, $files);
if (\core_text::strlen($data['name']) > 255) {
$errors['name'] = get_string('nametoolong', 'htmlcert');
}
return $errors;
}
/**
* Adds the page elements to the form.
*
* @param \stdClass $page the htmlcert page
*/
protected function add_htmlcert_page_elements($page) {
global $DB, $OUTPUT;
// Create the form object.
$mform =& $this->_form;
$editlink = '/mod/htmlcert/edit.php';
$editlinkparams = array('tid' => $this->tid, 'sesskey' => sesskey());
$mform->addElement('text', 'pagewidth', get_string('width', 'htmlcert'));
$mform->setType('pagewidth', PARAM_INT);
$mform->setDefault('pagewidth', '210');
$mform->addRule('pagewidth', null, 'required', null, 'client');
$mform->addHelpButton('pagewidth', 'width', 'htmlcert');
$mform->addElement('text', 'pageheight', get_string('height', 'htmlcert'));
$mform->setType('pageheight', PARAM_INT);
$mform->setDefault('pageheight', '297');
$mform->addRule('pageheight', null, 'required', null, 'client');
$mform->addHelpButton('pageheight', 'height', 'htmlcert');
}
}