Merge branch 'wip-MDL-29678-m21' of git://github.com/samhemelryk/moodle into MOODLE_2...
[moodle.git] / mod / workshop / aggregate.php
blobee8fb9b35ef5b171523bd34fc02c36b47754fea9
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 * Aggregates the grades for submission and grades for assessments
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); // course module
31 $confirm = optional_param('confirm', false, PARAM_BOOL); // confirmation
33 // the params to be re-passed to view.php
34 $page = optional_param('page', 0, PARAM_INT);
35 $sortby = optional_param('sortby', 'lastname', PARAM_ALPHA);
36 $sorthow = optional_param('sorthow', 'ASC', PARAM_ALPHA);
38 $cm = get_coursemodule_from_id('workshop', $cmid, 0, false, MUST_EXIST);
39 $course = $DB->get_record('course', array('id' => $cm->course), '*', MUST_EXIST);
40 $workshop = $DB->get_record('workshop', array('id' => $cm->instance), '*', MUST_EXIST);
41 $workshop = new workshop($workshop, $cm, $course);
43 $PAGE->set_url($workshop->aggregate_url(), compact('confirm', 'page', 'sortby', 'sorthow'));
45 require_login($course, false, $cm);
46 require_capability('mod/workshop:overridegrades', $PAGE->context);
48 // load and init the grading evaluator
49 $evaluator = $workshop->grading_evaluation_instance();
50 $settingsform = $evaluator->get_settings_form($PAGE->url);
52 if ($settingsdata = $settingsform->get_data()) {
53 $workshop->aggregate_submission_grades(); // updates 'grade' in {workshop_submissions}
54 $evaluator->update_grading_grades($settingsdata); // updates 'gradinggrade' in {workshop_assessments}
55 $workshop->aggregate_grading_grades(); // updates 'gradinggrade' in {workshop_aggregations}
56 $workshop->log('update aggregate grades');
59 redirect(new moodle_url($workshop->view_url(), compact('page', 'sortby', 'sorthow')));