-
Notifications
You must be signed in to change notification settings - Fork 0
/
select_source.php
111 lines (91 loc) · 4.04 KB
/
select_source.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Select source pages for local_sitsgradepush to select source for assessment component.
*
* @package local_sitsgradepush
* @copyright 2023 onwards University College London {@link https://www.ucl.ac.uk/}
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
* @author Alex Yeung <[email protected]>
*/
namespace local_sitsgradepush;
use context_course;
use moodle_exception;
use moodle_url;
require_once('../../config.php');
// Course ID.
$courseid = required_param('courseid', PARAM_INT);
$mabid = required_param('mabid', PARAM_INT);
$reassess = optional_param('reassess', 0, PARAM_INT);
// Get course context.
$context = context_course::instance($courseid);
// Get course instance.
if (!$course = get_course($courseid)) {
throw new moodle_exception('course not found.', 'local_sitsgradepush');
}
// Get the component grades.
$manager = manager::get_manager();
// Throw exception if not mapping for re-assessment and the course is not in current academic year.
if (!$manager->is_current_academic_year_activity($courseid) && $reassess == 0) {
throw new moodle_exception('error:pastactivity', 'local_sitsgradepush');
}
// Check MAB exists.
if (!$mab = $manager->get_local_component_grade_by_id($mabid)) {
throw new moodle_exception('error:mab_not_found', 'local_sitsgradepush', '', $mabid);
}
// Check if the component grade is valid for mapping.
list($mabvalid, $errormessages) = $manager->is_component_grade_valid_for_mapping($mab);
if (!$mabvalid) {
throw new moodle_exception('error:mab_invalid_for_mapping', 'local_sitsgradepush', '', implode(', ', $errormessages));
}
// Check there is no task running and no marks transfer records.
if (!$manager->can_change_source($mabid, $reassess)) {
throw new moodle_exception('error:cannot_change_source', 'local_sitsgradepush');
}
// Make sure user is authenticated.
require_login($course);
// Check user's capability.
require_capability('local/sitsgradepush:mapassessment', $context);
// Set the required data into the PAGE object.
$param = ['courseid' => $courseid, 'mabid' => $mabid];
if ($reassess == 1) {
// Check re-assessment marks transfer is enabled.
if (get_config('local_sitsgradepush', 'reassessment_enabled') !== '1') {
throw new moodle_exception('error:reassessmentdisabled', 'local_sitsgradepush');
}
$param['reassess'] = $reassess;
}
$url = new moodle_url('/local/sitsgradepush/select_source.php', $param);
$PAGE->set_context($context);
$PAGE->set_url($url);
$PAGE->set_title(get_string('selectsource:title', 'local_sitsgradepush'));
$PAGE->set_secondary_navigation(false);
// Set the breadcrumbs.
$PAGE->navbar->add(get_string('courses'), new moodle_url('/course/index.php'));
$PAGE->navbar->add($course->fullname, new moodle_url('/course/view.php', ['id' => $courseid]));
$PAGE->navbar->add(get_string('pluginname', 'local_sitsgradepush'),
new moodle_url('/local/sitsgradepush/dashboard.php', ['id' => $courseid]));
$PAGE->navbar->add(get_string('selectsource:header', 'local_sitsgradepush'),
new moodle_url('/local/sitsgradepush/select_source.php', $param));
// Page header.
echo $OUTPUT->header();
// Render the page.
$renderer = $PAGE->get_renderer('local_sitsgradepush');
echo $renderer->render_select_source_page($courseid, $mab, $reassess);
// Include JS.
$PAGE->requires->js_call_amd('local_sitsgradepush/select_source', 'init', []);
// Page footer.
echo $OUTPUT->footer();