Merge branch 'install_23_STABLE' of git://git.moodle.cz/moodle-install into MOODLE_23...
[moodle.git] / mod / workshop / editform.php
blob5c6d2f100b3f1fc904f0894ee3155bfe916803f3
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
22 * @subpackage workshop
23 * @copyright 2009 David Mudrak <david.mudrak@gmail.com>
24 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
27 require_once(dirname(dirname(dirname(__FILE__))).'/config.php');
28 require_once(dirname(__FILE__).'/locallib.php');
30 $cmid = required_param('cmid', PARAM_INT);
32 $cm = get_coursemodule_from_id('workshop', $cmid, 0, false, MUST_EXIST);
33 $course = $DB->get_record('course', array('id' => $cm->course), '*', MUST_EXIST);
35 require_login($course, false, $cm);
36 require_capability('mod/workshop:editdimensions', $PAGE->context);
38 $workshop = $DB->get_record('workshop', array('id' => $cm->instance), '*', MUST_EXIST);
39 $workshop = new workshop($workshop, $cm, $course);
41 // todo: check if there already is some assessment done and do not allowed the change of the form
42 // once somebody already used it to assess
44 $PAGE->set_url($workshop->editform_url());
45 $PAGE->set_title($workshop->name);
46 $PAGE->set_heading($course->fullname);
47 $PAGE->navbar->add(get_string('editingassessmentform', 'workshop'));
49 // load the grading strategy logic
50 $strategy = $workshop->grading_strategy_instance();
52 // load the form to edit the grading strategy dimensions
53 $mform = $strategy->get_edit_strategy_form($PAGE->url);
55 if ($mform->is_cancelled()) {
56 redirect($workshop->view_url());
57 } elseif ($data = $mform->get_data()) {
58 if (($data->workshopid != $workshop->id) or ($data->strategy != $workshop->strategy)) {
59 // this may happen if someone changes the workshop setting while the user had the
60 // editing form opened
61 throw new invalid_parameter_exception('Invalid workshop ID or the grading strategy has changed.');
63 $strategy->save_edit_strategy_form($data);
64 if (isset($data->saveandclose)) {
65 redirect($workshop->view_url());
66 } elseif (isset($data->saveandpreview)) {
67 redirect($workshop->previewform_url());
68 } else {
69 // save and continue - redirect to self to prevent data being re-posted by pressing "Reload"
70 redirect($PAGE->url);
74 // Output starts here
76 echo $OUTPUT->header();
77 echo $OUTPUT->heading(get_string('pluginname', 'workshopform_' . $workshop->strategy));
79 $mform->display();
81 echo $OUTPUT->footer();