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 * prints the forms to choose an item-typ to create items and to choose a template to use
20 * @author Andreas Grabs
21 * @license http://www.gnu.org/copyleft/gpl.html GNU Public License
22 * @package mod_feedback
25 //It must be included from a Moodle page
26 if (!defined('MOODLE_INTERNAL')) {
27 die('Direct access to this script is forbidden.');
30 require_once($CFG->libdir
.'/formslib.php');
33 * The feedback_edit_use_template_form
35 * @deprecated since 4.0 new dynamic forms created
37 class feedback_edit_use_template_form
extends moodleform
{
38 public function __construct($action = null, $customdata = null, $method = 'post', $target = '',
39 $attributes = null, $editable = true, $ajaxformdata = null) {
40 debugging('Class feedback_edit_use_template_form is deprecated. Replaced with dynamic forms.', DEBUG_DEVELOPER
);
41 parent
::__construct($action, $customdata, $method, $target, $attributes, $editable, $ajaxformdata);
45 * Overrides parent static method for deprecation purposes.
47 * @deprecated since 4.0
50 public static function get_js_module() {
51 debugging('Class feedback_edit_use_template_form is deprecated. Replaced with dynamic forms.', DEBUG_DEVELOPER
);
52 return parent
::get_js_module();
56 * Overrides parent static method for deprecation purposes.
58 * @deprecated since 4.0
59 * @param array $simulatedsubmitteddata
60 * @param array $simulatedsubmittedfiles
61 * @param string $method
62 * @param null $formidentifier
65 public static function mock_ajax_submit($simulatedsubmitteddata, $simulatedsubmittedfiles = array(),
66 $method = 'post', $formidentifier = null) {
67 debugging('Class feedback_edit_use_template_form is deprecated. Replaced with dynamic forms.', DEBUG_DEVELOPER
);
68 return parent
::mock_ajax_submit($simulatedsubmitteddata, $simulatedsubmittedfiles, $method, $formidentifier);
72 * Overrides parent static method for deprecation purposes.
74 * @deprecated since 4.0
78 public static function mock_generate_submit_keys($data = []) {
79 debugging('Class feedback_edit_use_template_form is deprecated. Replaced with dynamic forms.', DEBUG_DEVELOPER
);
80 return parent
::mock_generate_submit_keys($data);
84 * Overrides parent static method for deprecation purposes.
86 * @deprecated since 4.0
87 * @param array $simulatedsubmitteddata
88 * @param array $simulatedsubmittedfiles
89 * @param string $method
90 * @param null $formidentifier
92 public static function mock_submit($simulatedsubmitteddata, $simulatedsubmittedfiles = array(),
93 $method = 'post', $formidentifier = null) {
94 debugging('Class feedback_edit_use_template_form is deprecated. Replaced with dynamic forms.', DEBUG_DEVELOPER
);
95 parent
::mock_submit($simulatedsubmitteddata, $simulatedsubmittedfiles, $method, $formidentifier);
101 public function definition() {
102 $mform =& $this->_form
;
104 $course = $this->_customdata
['course'];
106 $elementgroup = array();
108 $mform->addElement('header', 'using_templates', get_string('using_templates', 'feedback'));
110 $mform->addElement('hidden', 'id');
111 $mform->setType('id', PARAM_INT
);
114 $templates_options = array();
115 $owntemplates = feedback_get_template_list($course, 'own');
116 $publictemplates = feedback_get_template_list($course, 'public');
119 if ($owntemplates or $publictemplates) {
120 $options[''] = array('' => get_string('choosedots'));
123 $courseoptions = array();
124 foreach ($owntemplates as $template) {
125 $courseoptions[$template->id
] = format_string($template->name
);
127 $options[get_string('course')] = $courseoptions;
130 if ($publictemplates) {
131 $publicoptions = array();
132 foreach ($publictemplates as $template) {
133 $publicoptions[$template->id
] = format_string($template->name
);
135 $options[get_string('public', 'feedback')] = $publicoptions;
139 'onChange="this.form.submit()"',
140 'data-form-change-checker-override="1"',
142 $elementgroup[] = $mform->createElement(
145 get_string('using_templates', 'feedback'),
147 implode(' ', $attributes)
150 $elementgroup[] = $mform->createElement('submit',
152 get_string('use_this_template', 'feedback'),
153 array('class' => 'hiddenifjs'));
155 $mform->addGroup($elementgroup, 'elementgroup', '', array(' '), false);
157 $mform->addElement('static', 'info', get_string('no_templates_available_yet', 'feedback'));
160 $this->set_data(array('id' => $this->_customdata
['id']));
165 * The feedback_edit_create_template_form
167 * @deprecated since 4.0, new dynamic forms have been created instead.
169 class feedback_edit_create_template_form
extends moodleform
{
170 public function __construct($action = null, $customdata = null, $method = 'post',
171 $target = '', $attributes = null, $editable = true, $ajaxformdata = null) {
172 debugging('Class feedback_edit_create_template_form is deprecated. Replaced with dynamic forms.', DEBUG_DEVELOPER
);
173 parent
::__construct($action, $customdata, $method, $target, $attributes, $editable, $ajaxformdata);
177 * Overrides parent static method for deprecation purposes.
179 * @deprecated since 4.0
182 public static function get_js_module() {
183 debugging('Class feedback_edit_create_template_form is deprecated. Replaced with dynamic forms.', DEBUG_DEVELOPER
);
184 return parent
::get_js_module();
188 * Overrides parent static method for deprecation purposes.
190 * @deprecated since 4.0
191 * @param array $simulatedsubmitteddata
192 * @param array $simulatedsubmittedfiles
193 * @param string $method
194 * @param null $formidentifier
197 public static function mock_ajax_submit($simulatedsubmitteddata, $simulatedsubmittedfiles = array(),
198 $method = 'post', $formidentifier = null) {
199 debugging('Class feedback_edit_create_template_form is deprecated. Replaced with dynamic forms.', DEBUG_DEVELOPER
);
200 return parent
::mock_ajax_submit($simulatedsubmitteddata, $simulatedsubmittedfiles, $method, $formidentifier);
204 * Overrides parent static method for deprecation purposes.
206 * @deprecated since 4.0
210 public static function mock_generate_submit_keys($data = []) {
211 debugging('Class feedback_edit_create_template_form is deprecated. Replaced with dynamic forms.', DEBUG_DEVELOPER
);
212 return parent
::mock_generate_submit_keys($data);
216 * Overrides parent static method for deprecation purposes.
218 * @deprecated since 4.0
219 * @param array $simulatedsubmitteddata
220 * @param array $simulatedsubmittedfiles
221 * @param string $method
222 * @param null $formidentifier
224 public static function mock_submit($simulatedsubmitteddata, $simulatedsubmittedfiles = array(),
225 $method = 'post', $formidentifier = null) {
226 debugging('Class feedback_edit_create_template_form is deprecated. Replaced with dynamic forms.', DEBUG_DEVELOPER
);
227 parent
::mock_submit($simulatedsubmitteddata, $simulatedsubmittedfiles, $method, $formidentifier);
233 public function definition() {
234 $mform =& $this->_form
;
237 $mform->addElement('hidden', 'id');
238 $mform->setType('id', PARAM_INT
);
239 $mform->addElement('hidden', 'do_show');
240 $mform->setType('do_show', PARAM_ALPHANUMEXT
);
241 $mform->setConstant('do_show', 'edit');
244 $elementgroup = array();
246 $elementgroup[] = $mform->createElement('text',
248 get_string('name', 'feedback'),
249 ['maxlength' => '200']);
251 if (has_capability('mod/feedback:createpublictemplate', context_system
::instance())) {
252 $elementgroup[] = $mform->createElement('checkbox',
254 get_string('public', 'feedback'));
258 $mform->addGroup($elementgroup,
260 get_string('name', 'feedback'),
265 $mform->addElement('submit', 'create_template', get_string('save_as_new_template', 'feedback'));
267 $mform->setType('templatename', PARAM_TEXT
);
269 $this->set_data(array('id' => $this->_customdata
['id']));
275 * @param array $data array of ("fieldname"=>value) of submitted data
276 * @param array $files array of uploaded files "element_name"=>tmp_file_path
277 * @return array of "element_name"=>"error_description" if there are errors,
278 * or an empty array if everything is OK (true allowed for backwards compatibility too).
280 public function validation($data, $files) {
281 $errors = parent
::validation($data, $files);
282 if (!isset($data['templatename']) ||
trim(strval($data['templatename'])) === '') {
283 $errors['elementgroup'] = get_string('name_required', 'feedback');