moodle-mod_htmlcert/classes/edit_form.php

121 lines
4 KiB
PHP
Raw Normal View History

<?php
2021-11-24 07:29:43 +00:00
// 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/>.
2017-02-16 12:12:19 +00:00
/**
2021-11-24 07:29:43 +00:00
* This file contains the form for handling the layout of the htmlcert instance.
2017-02-16 12:12:19 +00:00
*
2021-11-24 07:29:43 +00:00
* @package mod_htmlcert
* @copyright 2013 Mark Nelson <markn@moodle.com>, 2021 Klaus-Uwe Mitterer <kumitterer@kumi.systems>
2017-02-16 12:12:19 +00:00
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
2021-11-24 07:29:43 +00:00
namespace mod_htmlcert;
defined('MOODLE_INTERNAL') || die('Direct access to this script is forbidden.');
require_once($CFG->dirroot . '/course/moodleform_mod.php');
/**
2021-11-24 07:29:43 +00:00
* The form for handling the layout of the htmlcert instance.
*
2021-11-24 07:29:43 +00:00
* @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 {
/**
2017-02-16 12:12:19 +00:00
* @var int The id of the template being used.
*/
protected $tid = null;
/**
* Form definition.
*/
2013-07-23 06:44:11 +00:00
public function definition() {
global $DB, $OUTPUT;
$mform =& $this->_form;
2021-11-24 07:29:43 +00:00
$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'));
2021-11-24 08:03:55 +00:00
$mform->setType('html', PARAM_RAW);
2021-11-24 07:29:43 +00:00
$mform->addRule('html', null, 'required');
// Add the submit buttons.
$group = array();
$group[] = $mform->createElement('submit', 'submitbtn', get_string('savechanges'));
2021-11-24 07:29:43 +00:00
$group[] = $mform->createElement('submit', 'previewbtn', get_string('savechangespreview', 'htmlcert'), array(), false);
$mform->addElement('group', 'submitbtngroup', '', $group, '', false);
}
/**
2021-11-24 07:29:43 +00:00
* Fill in the current page data for this htmlcert.
*/
2013-07-23 06:44:11 +00:00
public function definition_after_data() {
global $DB;
$mform = $this->_form;
}
/**
* Some basic validation.
*
2017-02-16 12:12:19 +00:00
* @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) {
2021-11-24 07:29:43 +00:00
$errors['name'] = get_string('nametoolong', 'htmlcert');
}
return $errors;
}
/**
* Adds the page elements to the form.
*
2021-11-24 07:29:43 +00:00
* @param \stdClass $page the htmlcert page
*/
2021-11-24 07:29:43 +00:00
protected function add_htmlcert_page_elements($page) {
global $DB, $OUTPUT;
// Create the form object.
$mform =& $this->_form;
2021-11-24 07:29:43 +00:00
$editlink = '/mod/htmlcert/edit.php';
2017-09-02 06:01:13 +00:00
$editlinkparams = array('tid' => $this->tid, 'sesskey' => sesskey());
2021-11-24 07:29:43 +00:00
$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');
2021-11-24 07:29:43 +00:00
$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');
}
}