MDL-81717 h5p: Improve robustness content type fetching
[moodle.git] / mod / workshop / editform.php
blob8da5fcb09eab849ebc57f2b28cbe4bd98a2bb220
1 <?php
3 // This file is part of Moodle - http://moodle.org/
4 //
5 // Moodle is free software: you can redistribute it and/or modify
6 // it under the terms of the GNU General Public License as published by
7 // the Free Software Foundation, either version 3 of the License, or
8 // (at your option) any later version.
9 //
10 // Moodle is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU General Public License for more details.
15 // You should have received a copy of the GNU General Public License
16 // along with Moodle. If not, see <http://www.gnu.org/licenses/>.
18 /**
19 * Edit grading form in for a particular instance of workshop
21 * @package mod_workshop
22 * @copyright 2009 David Mudrak <david.mudrak@gmail.com>
23 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
26 require(__DIR__.'/../../config.php');
27 require_once(__DIR__.'/locallib.php');
29 $cmid = required_param('cmid', PARAM_INT);
31 $cm = get_coursemodule_from_id('workshop', $cmid, 0, false, MUST_EXIST);
32 $course = $DB->get_record('course', array('id' => $cm->course), '*', MUST_EXIST);
34 require_login($course, false, $cm);
35 require_capability('mod/workshop:editdimensions', $PAGE->context);
37 $workshop = $DB->get_record('workshop', array('id' => $cm->instance), '*', MUST_EXIST);
38 $workshop = new workshop($workshop, $cm, $course);
40 // todo: check if there already is some assessment done and do not allowed the change of the form
41 // once somebody already used it to assess
43 $PAGE->set_url($workshop->editform_url());
44 $PAGE->set_title($workshop->name);
45 $PAGE->set_heading($course->fullname);
46 $PAGE->activityheader->set_attrs([
47 'hidecompletion' => true,
48 'description' => ''
49 ]);
50 $PAGE->navbar->add(get_string('editingassessmentform', 'workshop'));
52 // load the grading strategy logic
53 $strategy = $workshop->grading_strategy_instance();
55 // load the form to edit the grading strategy dimensions
56 $mform = $strategy->get_edit_strategy_form($PAGE->url);
58 if ($mform->is_cancelled()) {
59 redirect($workshop->view_url());
60 } elseif ($data = $mform->get_data()) {
61 if (($data->workshopid != $workshop->id) or ($data->strategy != $workshop->strategy)) {
62 // this may happen if someone changes the workshop setting while the user had the
63 // editing form opened
64 throw new invalid_parameter_exception('Invalid workshop ID or the grading strategy has changed.');
66 $strategy->save_edit_strategy_form($data);
67 if (isset($data->saveandclose)) {
68 redirect($workshop->view_url());
69 } elseif (isset($data->saveandpreview)) {
70 redirect($workshop->previewform_url());
71 } else {
72 // save and continue - redirect to self to prevent data being re-posted by pressing "Reload"
73 redirect($PAGE->url);
77 // Output starts here
79 echo $OUTPUT->header();
80 echo $OUTPUT->heading(get_string('pluginname', 'workshopform_' . $workshop->strategy), 3);
82 $mform->display();
84 echo $OUTPUT->footer();