2 // This file is part of Moodle - http://moodle.org/
4 // Moodle is free software: you can redistribute it and/or modify
5 // it under the terms of the GNU General Public License as published by
6 // the Free Software Foundation, either version 3 of the License, or
7 // (at your option) any later version.
9 // Moodle is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
14 // You should have received a copy of the GNU General Public License
15 // along with Moodle. If not, see <http://www.gnu.org/licenses/>.
18 * This file defines a base class for all grading strategy editing forms.
20 * @package mod_workshop
21 * @copyright 2009 David Mudrak <david.mudrak@gmail.com>
22 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
25 defined('MOODLE_INTERNAL') ||
die();
27 require_once($CFG->libdir
. '/formslib.php'); // parent class definition
30 * Base class for editing all the strategy grading forms.
32 * This defines the common fields that all strategy grading forms need.
33 * Strategies should define their own class that inherits from this one, and
34 * implements the definition_inner() method.
38 class workshop_edit_strategy_form
extends moodleform
{
40 /** strategy logic instance that this class is editor of */
44 * Add the fields that are common for all grading strategies.
46 * If the strategy does not support all these fields, then you can override
47 * this method and remove the ones you don't want with
48 * $mform->removeElement().
49 * Stretegy subclassess should define their own fields in definition_inner()
53 public function definition() {
56 $mform = $this->_form
;
57 $this->workshop
= $this->_customdata
['workshop'];
58 $this->strategy
= $this->_customdata
['strategy'];
60 $mform->addElement('hidden', 'workshopid', $this->workshop
->id
); // workshopid
61 $mform->setType('workshopid', PARAM_INT
);
63 $mform->addElement('hidden', 'strategy', $this->workshop
->strategy
); // strategy name
64 $mform->setType('strategy', PARAM_PLUGIN
);
66 $this->definition_inner($mform);
68 // todo - tags support
69 //if (!empty($CFG->usetags)) {
70 // $mform->addElement('header', 'tagsheader', get_string('tags'));
71 // $mform->addElement('tags', 'tags', get_string('tags'));
74 $buttonarray = array();
75 $buttonarray[] = $mform->createElement('submit', 'saveandcontinue', get_string('saveandcontinue', 'workshop'));
76 $buttonarray[] = $mform->createElement('submit', 'saveandpreview', get_string('saveandpreview', 'workshop'));
77 $buttonarray[] = $mform->createElement('submit', 'saveandclose', get_string('saveandclose', 'workshop'));
78 $buttonarray[] = $mform->createElement('cancel');
79 $mform->addGroup($buttonarray, 'buttonar', '', array(' '), false);
80 $mform->closeHeaderBefore('buttonar');
84 * Validate the submitted form data.
86 * Grading strategy plugins can provide their own validation rules by
87 * overriding the {@link self::validation_inner()} method.
93 final public function validation($data, $files) {
95 parent
::validation($data, $files),
96 $this->validation_inner($data, $files)
101 * Add any strategy specific form fields.
103 * @param stdClass $mform the form being built.
105 protected function definition_inner(&$mform) {
106 // By default, do nothing.
110 * Add strategy specific validation rules.
113 * @param array $files
116 protected function validation_inner($data, $files) {