Beispiel #1
0
/**
 * Add nodes to myprofile page.
 *
 * @param \core_user\output\myprofile\tree $tree Tree object
 * @param stdClass $user user object
 * @param bool $iscurrentuser
 * @param stdClass $course Course object
 */
function gradereport_overview_myprofile_navigation(core_user\output\myprofile\tree $tree, $user, $iscurrentuser, $course)
{
    if (empty($course)) {
        // We want to display these reports under the site context.
        $course = get_fast_modinfo(SITEID)->get_course();
    }
    $systemcontext = context_system::instance();
    $usercontext = context_user::instance($user->id);
    $coursecontext = context_course::instance($course->id);
    if (grade_report_overview::check_access($systemcontext, $coursecontext, $usercontext, $course, $user->id)) {
        $url = new moodle_url('/grade/report/overview/index.php', array('userid' => $user->id));
        $node = new core_user\output\myprofile\node('reports', 'grades', get_string('gradesoverview', 'gradereport_overview'), null, $url);
        $tree->add_node($node);
    }
}
Beispiel #2
0
 /**
  * Trigger the user report events, do the same that the web interface view of the report
  *
  * @param int $courseid id of course
  * @param int $userid id of the user the report belongs to
  * @return array of warnings and status result
  * @since Moodle 3.2
  * @throws moodle_exception
  */
 public static function view_grade_report($courseid, $userid = 0)
 {
     global $USER;
     $params = self::validate_parameters(self::view_grade_report_parameters(), array('courseid' => $courseid, 'userid' => $userid));
     $warnings = array();
     $course = get_course($params['courseid']);
     $context = context_course::instance($course->id);
     self::validate_context($context);
     $userid = $params['userid'];
     if (empty($userid)) {
         $userid = $USER->id;
     } else {
         $user = core_user::get_user($userid, '*', MUST_EXIST);
         core_user::require_active_user($user);
     }
     $systemcontext = context_system::instance();
     $personalcontext = context_user::instance($userid);
     $access = grade_report_overview::check_access($systemcontext, $context, $personalcontext, $course, $userid);
     if (!$access) {
         throw new moodle_exception('nopermissiontoviewgrades', 'error');
     }
     grade_report_overview::viewed($context, $course->id, $userid);
     $result = array();
     $result['status'] = true;
     $result['warnings'] = $warnings;
     return $result;
 }
Beispiel #3
0
if (isset($personalcontext) && $courseid == SITEID) {
    $PAGE->set_context($personalcontext);
} else {
    $PAGE->set_context($context);
}
if ($userid == $USER->id) {
    $settings = $PAGE->settingsnav->find('mygrades', null);
    $settings->make_active();
} else {
    if ($courseid != SITEID && $userid) {
        // Show some other navbar thing.
        $user = $DB->get_record('user', array('id' => $userid), '*', MUST_EXIST);
        $PAGE->navigation->extend_for_user($user);
    }
}
$access = grade_report_overview::check_access($systemcontext, $context, $personalcontext, $course, $userid);
if (!$access) {
    // no access to grades!
    print_error('nopermissiontoviewgrades', 'error', $CFG->wwwroot . '/course/view.php?id=' . $courseid);
}
/// return tracking object
$gpr = new grade_plugin_return(array('type' => 'report', 'plugin' => 'overview', 'courseid' => $course->id, 'userid' => $userid));
/// last selected report session tracking
if (!isset($USER->grade_last_report)) {
    $USER->grade_last_report = array();
}
$USER->grade_last_report[$course->id] = 'overview';
// First make sure we have proper final grades.
grade_regrade_final_grades_if_required($course);
if (has_capability('moodle/grade:viewall', $context) && $courseid != SITEID) {
    // Please note this would be extremely slow if we wanted to implement this properly for all teachers.