Initial support for the grading management screen
[moodle.git] / grade / grading / manage.php
CommitLineData
6832a102
DM
1<?php
2
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.
14//
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/>.
17
18/**
19 * @package core
20 * @subpackage grading
21 * @copyright 2011 David Mudrak <david@moodle.com>
22 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
23 */
24
25require_once(dirname(dirname(dirname(__FILE__))).'/config.php');
26require_once($CFG->dirroot.'/grade/grading/lib.php');
27
28$areaid = optional_param('areaid', null, PARAM_INT);
29$contextid = optional_param('contextid', null, PARAM_INT);
30$component = optional_param('component', null, PARAM_COMPONENT);
31$area = optional_param('area', null, PARAM_AREA);
32$returnurl = optional_param('returnurl', null, PARAM_LOCALURL);
33$activemethod = optional_param('activemethod', null, PARAM_PLUGIN);
34
35if (!is_null($areaid)) {
36 // get manager by id
37 $manager = get_grading_manager($areaid);
38} else {
39 // get manager by context and component
40 if (is_null($contextid) or is_null($component)) {
41 throw new coding_exception('The caller script must identify the gradable area.');
42 }
43 $context = get_context_instance_by_id($contextid, MUST_EXIST);
44 $manager = get_grading_manager($context, $component, $area);
45}
46
47list($context, $course, $cm) = get_context_info_array($manager->get_context()->id);
48
49if (is_null($returnurl)) {
50 $returnurl = new moodle_url('/course/view.php', array('id' => $course->id));
51} else {
52 $returnurl = new moodle_url($returnurl);
53}
54
55require_login($course, true, $cm);
56require_capability('moodle/grade:managegradingforms', $context);
57
58$PAGE->set_url($manager->get_management_url($returnurl, $area));
59navigation_node::override_active_url($manager->get_management_url());
60$PAGE->set_title(get_string('gradingmanagement', 'core_grading'));
61$PAGE->set_heading(get_string('gradingmanagement', 'core_grading'));
62$output = $PAGE->get_renderer('core_grading');
63
64if (is_null($manager->get_area())) {
65 $areas = $manager->get_available_areas();
66
67 if (empty($areas)) {
68 throw new moodle_exception('no_gradable_area_available', 'core_grading');
69 }
70
71 if (count($areas) == 1) {
72 // if there is just one area available, set it automatically
73 $area = reset(array_keys($areas));
74 $manager->set_area($area);
75
76 } else {
77 // display area selector (we will make this page nicer once we have some real multi-area component)
78 echo $output->header();
79 echo $output->heading($manager->get_component_title());
80 echo $output->single_select($PAGE->url, 'area', $areas);
81 echo $output->footer();
82 die();
83 }
84}
85
86// process the eventual change of the active grading method
87if (!empty($activemethod)) {
88 require_sesskey();
89 if ($activemethod == 'none') {
90 // here we expect that noone would actually want to call their plugin as 'none'
91 $activemethod = null;
92 }
93 $manager->set_active_method($activemethod);
94 redirect($PAGE->url);
95}
96
97echo $output->header();
98echo $output->heading(get_string('gradingmanagementtitle', 'core_grading', array(
99 'component' => $manager->get_component_title(), 'area' => $manager->get_area_title())));
100
101// display the active grading method information and selector
102echo $output->management_method_selector($manager, $PAGE->url);
103
104// get the currently active method's controller
105$method = $manager->get_active_method();
106if (!empty($method)) {
107 $controller = $manager->get_controller($method);
108 // display relevant actions
109 echo $output->container_start('actions');
110 if ($controller->is_form_defined()) {
111 echo $output->management_action_icon($controller->get_editor_url($returnurl),
112 get_string('manageactionedit', 'core_grading'), 'b/document-properties');
113 echo $output->management_action_icon($PAGE->url,
114 get_string('manageactiondelete', 'core_grading'), 'b/edit-delete');
115 } else {
116 echo $output->management_action_icon($controller->get_editor_url($returnurl),
117 get_string('manageactionnew', 'core_grading'), 'b/document-new');
118 echo $output->management_action_icon($PAGE->url,
119 get_string('manageactionclone', 'core_grading'), 'b/edit-copy');
120 }
121 echo $output->container_end();
122
123 // display the grading form preview
124 if ($controller->is_form_defined()) {
125 echo $output->box($controller->render_preview($PAGE), 'preview');
126 }
127}
128
129
130echo $output->footer();