3 // This file is part of Moodle - http://moodle.org/
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.
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/>.
19 * Aggregates the grades for submission and grades for assessments
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
); // course module
30 $confirm = optional_param('confirm', false, PARAM_BOOL
); // confirmation
32 // the params to be re-passed to view.php
33 $page = optional_param('page', 0, PARAM_INT
);
34 $sortby = optional_param('sortby', 'lastname', PARAM_ALPHA
);
35 $sorthow = optional_param('sorthow', 'ASC', PARAM_ALPHA
);
37 $cm = get_coursemodule_from_id('workshop', $cmid, 0, false, MUST_EXIST
);
38 $course = $DB->get_record('course', array('id' => $cm->course
), '*', MUST_EXIST
);
39 $workshop = $DB->get_record('workshop', array('id' => $cm->instance
), '*', MUST_EXIST
);
40 $workshop = new workshop($workshop, $cm, $course);
42 $PAGE->set_url($workshop->aggregate_url(), compact('confirm', 'page', 'sortby', 'sorthow'));
44 require_login($course, false, $cm);
45 require_capability('mod/workshop:overridegrades', $PAGE->context
);
47 // load and init the grading evaluator
48 $evaluator = $workshop->grading_evaluation_instance();
49 $settingsform = $evaluator->get_settings_form($PAGE->url
);
51 if ($settingsdata = $settingsform->get_data()) {
52 $workshop->aggregate_submission_grades(); // updates 'grade' in {workshop_submissions}
53 $evaluator->update_grading_grades($settingsdata); // updates 'gradinggrade' in {workshop_assessments}
54 $workshop->aggregate_grading_grades(); // updates 'gradinggrade' in {workshop_aggregations}
57 redirect(new moodle_url($workshop->view_url(), compact('page', 'sortby', 'sorthow')));