My grades was originally only showing grades to a student.
Now the report will also show teachers what courses they are
teachers in.
Part of MDL-45774.
$coursecontext = context_course::instance($course->id);
$personalcontext = context_user::instance($user->id);
+$PAGE->set_context($personalcontext);
+
$PAGE->set_url('/course/user.php', array('id'=>$id, 'user'=>$user->id, 'mode'=>$mode));
require_login();
$PAGE->navigation->extend_for_user($user);
$PAGE->navigation->set_userid_for_parent_checks($user->id); // see MDL-25805 for reasons and for full commit reference for reversal when fixed.
$PAGE->set_title("$course->shortname: $stractivityreport ($mode)");
-$PAGE->set_heading($course->fullname);
+$PAGE->set_heading(fullname($user));
switch ($mode) {
case "grade":
// Change the navigation to point to the my grade node (If we are a student).
if ($USER->id == $user->id) {
require_once($CFG->dirroot . '/user/lib.php');
+ // Make the dashboard active so that it shows up in the navbar correctly.
+ $gradenode = $PAGE->settingsnav->find('dashboard', null)->make_active();
// Get the correct 'My grades' url to point to.
$activeurl = user_mygrades_url();
- $PAGE->navigation->override_active_url($activeurl);
- $activenode = $PAGE->navbar->add($course->shortname);
+ $navbar = $PAGE->navbar->add(get_string('mygrades', 'grades'), $activeurl, navigation_node::TYPE_SETTING);
+ $activenode = $navbar->add($course->shortname);
$activenode->make_active();
// Find the course node and collapse it.
$coursenode = $PAGE->navigation->find($course->id, navigation_node::TYPE_COURSE);
$coursenode->collapse = true;
$coursenode->make_inactive();
$url = new moodle_url('/course/user.php', array('id' => $id, 'user' => $user->id, 'mode' => $mode));
- $reportnode = $PAGE->navbar->add(get_string('pluginname', 'gradereport_user'), $url);
+ $reportnode = $activenode->add(get_string('pluginname', 'gradereport_user'), $url);
+ } else {
+ // Check to see if the active node is a user name.
+ $currentcoursenode = $PAGE->navigation->find('currentcourse', null);
+ $activenode = $currentcoursenode->find_active_node();
+ if (strpos($activenode->key, 'user') === false) { // No user name found.
+ $userurl = new moodle_url('/user/view.php', array('id' => $user->id, 'course' => $course->id));
+ // Add the user name.
+ $PAGE->navbar->add(fullname($user), $userurl, navigation_node::TYPE_SETTING);
+ }
+ $gradeurl = new moodle_url('/course/user.php', array('id'=>$id, 'user'=>$user->id, 'mode'=>$mode));
+ // Add the 'grades' node to the navbar.
+ $navbar = $PAGE->navbar->add(get_string('grades', 'grades'), $gradeurl, navigation_node::TYPE_SETTING);
}
echo $OUTPUT->header();
$personalcontext = context_user::instance($userid);
}
-if (isset($personalcontext)) {
+if (isset($personalcontext) && $courseid == SITEID) {
$PAGE->set_context($personalcontext);
} else {
$PAGE->set_context($context);
}
-$settings = $PAGE->settingsnav->find('mygrades', null);
-$settings->make_active();
+if ($userid == $USER->id) {
+ $settings = $PAGE->settingsnav->find('mygrades', null);
+ $settings->make_active();
+} else if ($courseid != SITEID) {
+ // Show some other navbar thing.
+ $user = $DB->get_record('user', array('id' => $userid));
+ $PAGE->navigation->extend_for_user($user);
+}
$access = false;
if (has_capability('moodle/grade:viewall', $systemcontext)) {
// Create a report instance
$report = new grade_report_overview($userid, $gpr, $context);
- // If the course id matches the site id then we don't have a course context to work with.
- // Display a standard page.
- if ($courseid == SITEID) {
+ if (!empty($report->studentcourseids)) {
+ // If the course id matches the site id then we don't have a course context to work with.
+ // Display a standard page.
+ if ($courseid == SITEID) {
+ $PAGE->set_pagelayout('standard');
+ $header = get_string('mygrades', 'grades') . ' - ' . fullname($report->user);
+ $PAGE->set_title($header);
+ $PAGE->set_heading(fullname($report->user));
+
+ if ($USER->id != $report->user->id) {
+ $PAGE->navigation->extend_for_user($report->user);
+ if ($node = $PAGE->settingsnav->get('userviewingsettings'.$report->user->id)) {
+ $node->forceopen = true;
+ }
+ } else if ($node = $PAGE->settingsnav->get('usercurrentsettings', navigation_node::TYPE_CONTAINER)) {
+ $node->forceopen = true;
+ }
+
+ echo $OUTPUT->header();
+ if ($report->fill_table(true, true)) {
+ echo html_writer::tag('h3', get_string('coursesiamtaking', 'grades'));
+ echo '<br />' . $report->print_table(true);
+ }
+ } else { // We have a course context. We must be navigating from the gradebook.
+ print_grade_page_head($courseid, 'report', 'overview', get_string('pluginname', 'gradereport_overview')
+ . ' - ' . fullname($report->user));
+ if ($report->fill_table()) {
+ echo '<br />' . $report->print_table(true);
+ }
+ }
+ } else {
$PAGE->set_pagelayout('standard');
$header = get_string('mygrades', 'grades') . ' - ' . fullname($report->user);
$PAGE->set_title($header);
$PAGE->set_heading(fullname($report->user));
+ echo $OUTPUT->header();
+ }
- if ($USER->id != $report->user->id) {
- $PAGE->navigation->extend_for_user($report->user);
- if ($node = $PAGE->settingsnav->get('userviewingsettings'.$report->user->id)) {
- $node->forceopen = true;
- }
- } else if ($node = $PAGE->settingsnav->get('usercurrentsettings', navigation_node::TYPE_CONTAINER)) {
- $node->forceopen = true;
- }
+ if (count($report->teachercourses)) {
+ echo html_writer::tag('h3', get_string('coursesiamteaching', 'grades'));
+ $report->print_teacher_table();
+ }
- echo $OUTPUT->header();
- if ($report->fill_table(true)) {
- echo '<br />'.$report->print_table(true);
- }
- } else { // We have a course context. We must be navigating from the gradebook.
- print_grade_page_head($courseid, 'report', 'overview', get_string('pluginname', 'gradereport_overview')
- . ' - ' . fullname($report->user));
- if ($report->fill_table()) {
- echo '<br />'.$report->print_table(true);
- }
+ if (empty($report->studentcourseids) && empty($report->teachercourses)) {
+ // We have no report to show the user. Let them know something.
+ echo $OUTPUT->notification(get_string('noreports', 'grades'), 'notifymessage');
}
}
*/
var $showtotalsifcontainhidden;
+ /**
+ * An array of course ids that the user is a student in.
+ * @var array $studentcourseids
+ */
+ public $studentcourseids;
+
+ /**
+ * An array of courses that the user is a teacher in.
+ * @var array $teachercourses
+ */
+ public $teachercourses;
+
/**
* Constructor. Sets local copies of user preferences and initialises grade_tree.
* @param int $userid
$this->showtotalsifcontainhidden = array();
+ $this->studentcourseids = array();
+ $this->teachercourses = array();
+ $roleids = explode(',', get_config('moodle', 'gradebookroles'));
+
if ($this->courses) {
foreach ($this->courses as $course) {
$this->showrank[$course->id] = grade_get_setting($course->id, 'report_overview_showrank', !empty($CFG->grade_report_overview_showrank));
}
$this->showtotalsifcontainhidden[$course->id] = grade_get_setting($course->id, 'report_overview_showtotalsifcontainhidden', $CFG->grade_report_overview_showtotalsifcontainhidden);
+
+ $coursecontext = context_course::instance($course->id);
+
+ foreach ($roleids as $roleid) {
+ if (user_has_role_assignment($userid, $roleid, $coursecontext->id)) {
+ $this->studentcourseids[$course->id] = $course->id;
+ // We only need to check if one of the roleids has been assigned.
+ break;
+ }
+ }
+
+ if (has_capability('moodle/grade:viewall', $coursecontext, $userid)) {
+ $this->teachercourses[$course->id] = $course;
+ }
}
}
* Fill the table for displaying.
*
* @param bool $activitylink If this report link to the activity report or the user report.
+ * @param bool $studentcoursesonly Only show courses that the user is a student of.
*/
- public function fill_table($activitylink = false) {
+ public function fill_table($activitylink = false, $studentcoursesonly = false) {
global $CFG, $DB, $OUTPUT, $USER;
+ if ($studentcoursesonly && count($this->studentcourseids) == 0) {
+ return false;
+ }
+
// Only show user's courses instead of all courses.
if ($this->courses) {
$numusers = $this->get_numusers(false);
continue;
}
+ // If we are only showing student courses and this course isn't part of the group, then move on.
+ if ($studentcoursesonly && !isset($this->studentcourseids[$course->id])) {
+ continue;
+ }
+
$coursecontext = context_course::instance($course->id);
if (!$course->visible && !has_capability('moodle/course:viewhiddencourses', $coursecontext)) {
}
}
+ /**
+ * Print a table to show courses that the user is able to grade.
+ */
+ public function print_teacher_table() {
+ $table = new html_table();
+ $table->head = array(get_string('coursename', 'grades'));
+ $table->data = null;
+ foreach ($this->teachercourses as $courseid => $course) {
+ $url = new moodle_url('/grade/report/index.php', array('id' => $courseid));
+ $table->data[] = array(html_writer::link($url, $course->fullname));
+ }
+ echo html_writer::table($table);
+ }
+
/**
* Processes the data sent by the form (grades and feedbacks).
* @var array $data
// print the page
echo '<div class="grade-report-user">'; // css fix to share styles with real report page
- echo $OUTPUT->context_header(array(
- 'heading' => fullname($report->user),
- 'user' => $user,
- 'usercontext' => context_user::instance($user->id)
- ));
-
if ($report->fill_table()) {
echo $report->print_table(true);
}
$string['coursegradedisplayupdated'] = 'The course grade display type has been updated.';
$string['coursegradesettings'] = 'Course grade settings';
$string['coursename'] = 'Course name';
+$string['coursesiamtaking'] = 'Courses I am taking';
+$string['coursesiamteaching'] = 'Courses I am teaching';
$string['coursescales'] = 'Course scales';
$string['coursesettings'] = 'Course settings';
$string['coursesettingsexplanation'] = 'Course settings determine how the gradebook appears for all participants in the course.';
$string['nooutcomes'] = 'Outcome items must be linked to a course outcome, but there are no outcomes for this course. Would you like to add one?';
$string['nopermissiontoresetweights'] = 'No permission to reset the weights';
$string['nopublish'] = 'Do not publish';
+$string['noreports'] = 'You are not enrolled in, nor teaching any courses on this site.';
$string['norolesdefined'] = 'No roles defined in Administration > Grades > General settings > Graded roles';
$string['noscales'] = 'Outcomes must be linked to a course scale or global scale, but there are none. Would you like to add one?';
$string['noselectedcategories'] = 'no categories were selected.';
$url = new moodle_url('/course/user.php', array('mode' => 'grade', 'id' => $course->id, 'user' => $user->id));
}
if ($USER->id != $user->id) {
- $usernode->add(get_string('grades', 'grades'), $url);
+ $usernode->add(get_string('grades', 'grades'), $url, self::TYPE_SETTING, null, 'usergrades');
} else {
$usernode->add(get_string('mygrades', 'grades'), $url);
}