This repository has been archived by the owner on Jun 24, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.php
177 lines (144 loc) · 5.61 KB
/
index.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
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
<?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/>.
/**
* My Grades Report.
*
* @package report_mygrades
* @author David Bezemer <[email protected]>
* @credits Based on original work block_mygrades by Karen Holland, Mei Jin, Jiajia Chen
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
require('../../config.php');
require_once($CFG->libdir . '/gradelib.php');
require_once $CFG->dirroot . '/grade/report/overview/lib.php';
require_once $CFG->dirroot . '/grade/lib.php';
global $PAGE, $COURSE;
$url = new moodle_url('/report/mygrades/index.php');
$PAGE->set_url($url);
$PAGE->set_pagelayout('report');
$PAGE->set_context(context_course::instance($COURSE->id));
$PAGE->navigation->add(get_string('pluginname', 'report_mygrades'), $url);
$PAGE->set_heading($COURSE->fullname);
$PAGE->set_title(get_string('pluginname', 'report_mygrades'));
$PAGE->requires->jquery();
$PAGE->requires->jquery_plugin('dataTables', 'report_mygrades');
require_login();
echo $OUTPUT->header();
$userid = optional_param('userid', 0, PARAM_INT); // user id
if (empty($userid)) {
$userid = $USER->id;
$usercontext = context_user::instance($userid, MUST_EXIST);
} else {
$usercontext = context_user::instance($userid, MUST_EXIST);
}
if ($userid != $USER->id && !has_capability('moodle/user:viewdetails', $usercontext)) {
echo $OUTPUT->notification(get_string('usernotavailable', 'error'));
die;
}
global $DB,$CFG;
$user = $DB->get_record('user', array('id' => $userid, 'deleted' => 0));
$userlinked = "<a href='".$CFG->wwwroot."/user/view.php?id=".$userid."'>".$user->firstname." ".$user->lastname."</a>";
if (empty($user->username)) {
echo $OUTPUT->notification(get_string('userdeleted'));
die;
}
echo $OUTPUT->heading(get_string('pluginname', 'report_mygrades')." ".get_string('for', 'calendar')." ".$userlinked);
class report_mygrades extends block_base {
public function init() {
$this->title = get_string('my_grades', 'report_mygrades');
}
public function get_content() {
global $DB, $USER, $COURSE;
$userid = optional_param('userid', 0, PARAM_INT); // user id
if ($this->content !== null) {
return $this->content;
}
if (empty($userid)) {
$userid = $USER->id;
}
$this->content = new stdClass;
/// return tracking object
$gpr = new grade_plugin_return(array('type'=>'report', 'plugin'=>'overview', 'userid'=>$USER->id));
// Create a report instance
$context = context_course::instance($COURSE->id);
$report = new grade_report_overview($userid, $gpr, $context);
$newdata=$this->grade_data($report);
if (is_array($newdata))
{
if (count($newdata)>0)
{
$newtext="<table class=\"grades\" id=\"grades\"><thead><tr><th>".get_string('gradetblheader_course', 'report_mygrades')."</th><th>".get_string('gradetblheader_grade', 'report_mygrades')."</th></tr></thead>";
foreach($newdata as $newgrade)
{
// need to put data into table for display here
$newtext.="<tr><td>{$newgrade[0]}</td><td>{$newgrade[1]}</td></tr>";
}
$newtext.="</table>";
$this->content->text = $newtext;
}
}
else
{
$this->content->text = $newdata;
}
return $this->content;
}
public function instance_allow_multiple() {
return false;
}
public function grade_data($report) {
global $CFG, $DB, $OUTPUT;
$data = array();
if ($courses = enrol_get_users_courses($report->user->id, false, 'id, shortname, showgrades')) {
$numusers = $report->get_numusers(false);
foreach ($courses as $course) {
if (!$course->showgrades) {
continue;
}
$coursecontext = context_course::instance($course->id);
if (!$course->visible && !has_capability('moodle/course:viewhiddencourses', $coursecontext)) {
// The course is hidden and the user isn't allowed to see it
continue;
}
$courseshortname = format_string($course->shortname, true, array('context' => $coursecontext));
$courselink = html_writer::link(new moodle_url('/grade/report/user/index.php', array('id' => $course->id, 'userid' => $report->user->id)), $courseshortname);
$canviewhidden = has_capability('moodle/grade:viewhidden', $coursecontext);
// Get course grade_item
$course_item = grade_item::fetch_course_item($course->id);
// Get the stored grade
$course_grade = new grade_grade(array('itemid'=>$course_item->id, 'userid'=>$report->user->id));
$course_grade->grade_item =& $course_item;
$finalgrade = $course_grade->finalgrade;
$data[] = array($courselink, grade_format_gradevalue($finalgrade, $course_item, true));
}
if (count($data)==0) {
return $OUTPUT->notification(get_string('noenrolments', 'report_mygrades'));
} else {
return $data;
}
} else {
return $OUTPUT->notification(get_string('noenrolments', 'report_mygrades'));
}
}
}
$report = new report_mygrades;
$report->init();
$content = $report->get_content();
echo $content->text;
echo $OUTPUT->container_start('info');
echo $OUTPUT->container_end();
echo $OUTPUT->footer();
echo "<script>$('#grades').dataTable({'aaSorting': []});</script>";