Merge branch 'install_30_STABLE' of https://git.in.moodle.com/amosbot/moodle-install...
[moodle.git] / mod / workshop / form / edit_form.php
blob708cdc4f1182b9e86cb3efc8d287e8d92700790c
1 <?php
2 // This file is part of Moodle - http://moodle.org/
3 //
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.
8 //
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/>.
17 /**
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
29 /**
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.
36 * @uses moodleform
38 class workshop_edit_strategy_form extends moodleform {
40 /** strategy logic instance that this class is editor of */
41 protected $strategy;
43 /**
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()
51 * @return void
53 public function definition() {
54 global $CFG;
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'));
72 //}
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');
83 /**
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.
89 * @param array $data
90 * @param array $files
91 * @return array
93 final public function validation($data, $files) {
94 return array_merge(
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.
112 * @param array $data
113 * @param array $files
114 * @return array
116 protected function validation_inner($data, $files) {
117 return array();