forked from ltu-solent/moodle-report_grade
-
Notifications
You must be signed in to change notification settings - Fork 0
/
srsstatus.php
148 lines (129 loc) · 5.38 KB
/
srsstatus.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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
<?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/>.
/**
* SRS Status page. Lists all grades that should be sent to quercus and their status.
*
* @package report_grade
* @author Mark Sharp <[email protected]>
* @copyright 2022 Solent University {@link https://www.solent.ac.uk}
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
use local_solsits\sitsassign;
use report_grade\output\assignmentinfo;
use report_grade\tables\srsstatus as srsstatus_table;
require_once('../../config.php');
$qid = optional_param('qid', 0, PARAM_INT); // Quercus.
$sid = optional_param('sid', 0, PARAM_INT); // SITS.
$courseid = required_param('cid', PARAM_INT);
$coursecontext = context_course::instance($courseid);
require_login($courseid, false);
require_capability('report/grade:view', $coursecontext);
$course = $DB->get_record('course', ['id' => $courseid]);
$title = new lang_string('srstitlecourse', 'report_grade', ['shortname' => $course->shortname]);
$data = new stdClass();
$data->courseid = $courseid;
// Get all Quercus and SITS assignments for this course.
$qassignments = \local_quercus_tasks\api::get_quercus_assignments($data->courseid);
// Using get_records_select to get id indexed array result. See MDL-79574.
$sassignments = sitsassign::get_records_select('courseid = :courseid AND cmid > 0', ['courseid' => $data->courseid]);
$totalassignments = count($qassignments) + count($sassignments);
$pageparams = [
'cid' => $courseid,
];
if ($qid > 0) {
$pageparams['qid'] = $qid;
if (!isset($qassignments[$qid])) {
// This assignment doesn't exist in this course. Throw an error.
throw new moodle_exception('Invalid assignment specified');
}
$data->assignment = $qassignments[$qid];
$data->source = 'quercus';
$title = new lang_string('srstitlecourseassignment', 'report_grade', [
'shortname' => $course->shortname,
'assignname' => $data->assignment->name,
]);
}
if ($sid > 0) {
$pageparams['sid'] = $sid;
if (!isset($sassignments[$sid])) {
// This assignment doesn't exist in this course. Throw an error.
throw new moodle_exception('Invalid assignment specified');
}
$data->assignment = $sassignments[$sid];
$data->source = ['sits'];
$title = new lang_string('srstitlecourseassignment', 'report_grade', [
'shortname' => $course->shortname,
'assignname' => $data->assignment->get('title'),
]);
}
// If no assignment has been specified, find the first available one to display.
if ($totalassignments > 0 && !isset($data->assignment)) {
if (count($qassignments) > 0) {
$data->assignment = reset($qassignments);
$data->source = 'quercus';
$pageparams['qid'] = $data->assignment->id;
$title = new lang_string('srstitlecourseassignment', 'report_grade', [
'shortname' => $course->shortname,
'assignname' => $data->assignment->name,
]);
} else {
$data->assignment = reset($sassignments);
$data->source = 'sits';
$pageparams['sid'] = $data->assignment->get('id');
$title = new lang_string('srstitlecourseassignment', 'report_grade', [
'shortname' => $course->shortname,
'assignname' => $data->assignment->get('title'),
]);
}
}
$PAGE->set_url('/report/grade/srsstatus.php', $pageparams);
$PAGE->set_context($coursecontext);
$PAGE->set_title($title);
$PAGE->set_heading($title);
$PAGE->navbar->add(get_string('pluginname', 'report_grade'), new moodle_url('/report/grade/index.php', ['id' => $courseid]));
$PAGE->navbar->add(get_string('srsstatus', 'report_grade'), new moodle_url('/report/grade/srsstatus.php', $pageparams));
echo $OUTPUT->header();
if ($totalassignments == 0) {
echo $OUTPUT->notification(new lang_string('nosummativeassignments', 'report_grade'));
echo $OUTPUT->footer();
exit();
}
// We only need to list assignments if there's more than one.
if ($totalassignments > 1) {
$linklist = [];
foreach ($qassignments as $assign) {
$linklist[] = html_writer::link(
new moodle_url('/report/grade/srsstatus.php', [
'cid' => $data->courseid,
'qid' => $assign->id,
]), $assign->name);
}
foreach ($sassignments as $assign) {
$linklist[] = html_writer::link(
new moodle_url('/report/grade/srsstatus.php', [
'cid' => $data->courseid,
'sid' => $assign->get('id'),
]), $assign->get('title'));
}
echo html_writer::alist($linklist, ['class' => 'marksupload-assignment-list']);
}
if ($data->assignment) {
$assignmentinfo = new assignmentinfo($data);
echo $OUTPUT->render($assignmentinfo);
$table = new srsstatus_table($data);
$table->out(100, true);
}
echo $OUTPUT->footer();