本文整理汇总了PHP中enrol_get_users_courses函数的典型用法代码示例。如果您正苦于以下问题:PHP enrol_get_users_courses函数的具体用法?PHP enrol_get_users_courses怎么用?PHP enrol_get_users_courses使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了enrol_get_users_courses函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: mycourses
protected function mycourses($CFG, $sidebar)
{
$mycourses = enrol_get_users_courses($_SESSION['USER']->id);
$courselist = array();
foreach ($mycourses as $key => $val) {
$courselist[] = $val->id;
}
$content = '';
for ($x = 1; $x <= sizeof($courselist); $x++) {
$course = get_course($courselist[$x - 1]);
$title = $course->fullname;
if ($course instanceof stdClass) {
require_once $CFG->libdir . '/coursecatlib.php';
$course = new course_in_list($course);
}
$url = $CFG->wwwroot . "/theme/keats/pix/coursenoimage.jpg";
foreach ($course->get_course_overviewfiles() as $file) {
$isimage = $file->is_valid_image();
$url = file_encode_url("{$CFG->wwwroot}/pluginfile.php", '/' . $file->get_contextid() . '/' . $file->get_component() . '/' . $file->get_filearea() . $file->get_filepath() . $file->get_filename(), !$isimage);
if (!$isimage) {
$url = $CFG->wwwroot . "/theme/keats/pix/coursenoimage.jpg";
}
}
$content .= '<div class="view view-second view-mycourse ' . ($x % 3 == 0 ? 'view-nomargin' : '') . '">
<img src="' . $url . '" />
<div class="mask">
<h2>' . $title . '</h2>
<a href="' . $CFG->wwwroot . '/course/view.php?id=' . $courselist[$x - 1] . '" class="info">Enter</a>
</div>
</div>';
}
return $content;
}
示例2: display_exams_list
/**
* Function to display a teacher's available exams. This uses all the
* courses that a teacher is enrolled in and checks which course has
* exams related to it. Shows the exam, the date and adds a
*/
function display_exams_list()
{
global $DB, $CFG, $USER;
$IP_Address = $tableName = 'Exams';
$user_table = 'user';
$table = new html_table();
$table->head = array('Course', 'Date', 'Navigation');
$table->tablealign = 'center';
$table->width = '100%';
$user_courses = enrol_get_users_courses($USER->id, true, '*', 'visible DESC,sortorder ASC');
/**
* Checks the teachers courses with available tests and if exists add to the main page.
*/
foreach ($user_courses as $uc) {
$rec = $DB->get_records_sql('SELECT booklet_id, year_semester_origin
FROM {mem_booklet_data}
WHERE course_id=?', array(intval($uc->id)));
$row_info = array();
if (count($rec) > 0) {
$row = new html_table_row(array($uc->fullname, current($rec)->year_semester_origin, '<div style="text-align: center"><a href=' . $CFG->wwwroot . '/local/memplugin/grid.php?course_id=' . intval($uc->id) . '>' . get_string('startmarking', 'local_memplugin') . '</a></div>'));
$table->data[] = $row;
}
}
echo html_writer::table($table);
}
示例3: __construct
/**
* Constructor. Sets local copies of user preferences and initialises grade_tree.
* @param int $userid
* @param object $gpr grade plugin return tracking object
* @param string $context
*/
public function __construct($userid, $gpr, $context)
{
global $CFG, $COURSE, $DB;
parent::__construct($COURSE->id, $gpr, $context);
// Get the user (for full name).
$this->user = $DB->get_record('user', array('id' => $userid));
// Load the user's courses.
$this->courses = enrol_get_users_courses($this->user->id, false, 'id, shortname, showgrades');
$this->showrank = array();
$this->showrank['any'] = false;
$this->showtotalsifcontainhidden = array();
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));
if ($this->showrank[$course->id]) {
$this->showrank['any'] = true;
}
$this->showtotalsifcontainhidden[$course->id] = grade_get_setting($course->id, 'report_overview_showtotalsifcontainhidden', $CFG->grade_report_overview_showtotalsifcontainhidden);
}
}
// base url for sorting by first/last name
$this->baseurl = $CFG->wwwroot . '/grade/overview/index.php?id=' . $userid;
$this->pbarurl = $this->baseurl;
$this->setup_table();
}
示例4: get_content
public function get_content() {
global $DB;
if ($this->content !== null) {
return $this->content;
}
global $CFG, $USER, $PAGE;
$this->content = new stdClass();
require_once($CFG->dirroot.'/blocks/queries/lib.php');
require_once($CFG->dirroot.'/blocks/queries/commentform.php');
require_once($CFG->dirroot.'/blocks/queries/queries_form.php');
//query to enrol users courses particulars
$courses = enrol_get_users_courses($USER->id);
//calling function for if login user instructor or not
$instructorlogin = block_queries_getrole_user($courses,'instructor');
//calling function for if login user registrar or not
$registrarlogin = block_queries_getrole_user($courses,'registrar');
//calling function for if login user student or not
$studentlogin = block_queries_getrole_user($courses,'student');
/************calling function for getting data to the logged in user*************/
$this->content->text = block_queries_display_view($USER,$instructorlogin,$registrarlogin,$studentlogin);
$this->content->footer = '';
$this->page->requires->js('/blocks/queries/js/commentform_popup.js');
// Return the content object
return $this->content;
}
示例5: get_users_courses
/**
* Get list of courses user is enrolled in (only active enrolments are returned).
* Please note the current user must be able to access the course, otherwise the course is not included.
*
* @param int $userid
* @return array of courses
*/
public static function get_users_courses($userid)
{
global $USER, $DB;
// Do basic automatic PARAM checks on incoming data, using params description
// If any problems are found then exceptions are thrown with helpful error messages
$params = self::validate_parameters(self::get_users_courses_parameters(), array('userid' => $userid));
$courses = enrol_get_users_courses($params['userid'], true, 'id, shortname, fullname, idnumber, visible');
$result = array();
foreach ($courses as $course) {
$context = context_course::instance($course->id, IGNORE_MISSING);
try {
self::validate_context($context);
} catch (Exception $e) {
// current user can not access this course, sorry we can not disclose who is enrolled in this course!
continue;
}
if ($userid != $USER->id and !has_capability('moodle/course:viewparticipants', $context)) {
// we need capability to view participants
continue;
}
list($enrolledsqlselect, $enrolledparams) = get_enrolled_sql($context);
$enrolledsql = "SELECT COUNT(*) FROM ({$enrolledsqlselect}) AS enrolleduserids";
$enrolledusercount = $DB->count_records_sql($enrolledsql, $enrolledparams);
$result[] = array('id' => $course->id, 'shortname' => $course->shortname, 'fullname' => $course->fullname, 'idnumber' => $course->idnumber, 'visible' => $course->visible, 'enrolledusercount' => $enrolledusercount);
}
return $result;
}
示例6: message_print_contact_selector
function message_print_contact_selector($countunreadtotal, $usergroup, $user1, $user2, $blockedusers, $onlinecontacts, $offlinecontacts, $strangers, $showcontactactionlinks, $page = 0)
{
global $PAGE;
echo html_writer::start_tag('div', array('class' => 'contactselector mdl-align'));
//if 0 unread messages and they've requested unread messages then show contacts
if ($countunreadtotal == 0 && $usergroup == VIEW_UNREAD_MESSAGES) {
$usergroup = VIEW_CONTACTS;
}
//if they have no blocked users and they've requested blocked users switch them over to contacts
if (count($blockedusers) == 0 && $usergroup == VIEW_BLOCKED) {
$usergroup = VIEW_CONTACTS;
}
$onlyactivecourses = true;
$courses = enrol_get_users_courses($user1->id, $onlyactivecourses);
$coursecontexts = message_get_course_contexts($courses);
//we need one of these again so holding on to them
$strunreadmessages = null;
if ($countunreadtotal > 0) {
//if there are unread messages
$strunreadmessages = get_string('unreadmessages', 'message', $countunreadtotal);
}
message_print_usergroup_selector($usergroup, $courses, $coursecontexts, $countunreadtotal, count($blockedusers), $strunreadmessages);
$refreshpage = false;
if ($usergroup == VIEW_UNREAD_MESSAGES) {
message_print_contacts($onlinecontacts, $offlinecontacts, $strangers, $refreshpage, $PAGE->url, 1, $showcontactactionlinks, $strunreadmessages, $user2);
} else {
if ($usergroup == VIEW_CONTACTS || $usergroup == VIEW_SEARCH) {
message_print_contacts($onlinecontacts, $offlinecontacts, $strangers, $refreshpage, $PAGE->url, 0, $showcontactactionlinks, $strunreadmessages, $user2);
} else {
if ($usergroup == VIEW_BLOCKED) {
message_print_blocked_users($blockedusers, $PAGE->url, $showcontactactionlinks, null, $user2);
} else {
if (substr($usergroup, 0, 7) == VIEW_COURSE) {
$courseidtoshow = intval(substr($usergroup, 7));
if (!empty($courseidtoshow) && array_key_exists($courseidtoshow, $coursecontexts) && has_capability('moodle/course:viewparticipants', $coursecontexts[$courseidtoshow])) {
message_print_participants($coursecontexts[$courseidtoshow], $courseidtoshow, $PAGE->url, $showcontactactionlinks, null, $page, $user2);
} else {
//shouldn't get here. User trying to access a course they're not in perhaps.
add_to_log(SITEID, 'message', 'view', 'index.php', $usergroup);
}
}
}
}
}
echo html_writer::start_tag('form', array('action' => 'index.php', 'method' => 'GET'));
echo html_writer::start_tag('fieldset');
$managebuttonclass = 'visible';
if ($usergroup == VIEW_SEARCH) {
$managebuttonclass = 'hiddenelement';
}
$strmanagecontacts = get_string('search', 'message');
echo html_writer::empty_tag('input', array('type' => 'hidden', 'name' => 'usergroup', 'value' => VIEW_SEARCH));
echo html_writer::empty_tag('input', array('type' => 'submit', 'value' => $strmanagecontacts, 'class' => $managebuttonclass));
echo html_writer::end_tag('fieldset');
echo html_writer::end_tag('form');
echo html_writer::end_tag('div');
}
示例7: execute
function execute($data, $user, $courseid)
{
global $DB, $CFG;
require_once $CFG->libdir . '/enrollib.php';
$finalcourses = array();
$mycourses = enrol_get_users_courses($user->id);
if (!empty($mycourses)) {
$finalcourses = array_keys($mycourses);
}
return $finalcourses;
}
示例8: definition
public function definition()
{
global $CFG, $USER, $DB;
$mform = $this->_form;
$mform->addElement('header', 'general', get_string('askaquestion', 'block_queries'));
$courses = enrol_get_users_courses($USER->id);
foreach ($courses as $course) {
// to get instructors in course level
$sql = "SELECT u.id, u.email, u.firstname, u.lastname\n FROM {context} AS cxt\n JOIN {role_assignments} AS ra\n ON cxt.id = ra.contextid \n JOIN {user} AS u\n ON ra.userid = u.id\n WHERE cxt.instanceid = {$course->id} AND ra.roleid = 10 AND cxt.contextlevel = 50";
$instructors = $DB->get_records_sql($sql);
$instructors12 = array();
foreach ($instructors as $instructor) {
$fullname = fullname($instructor);
$instructors12[$instructor->id . ',instructor'] = $fullname;
}
}
$registraroptions = array();
foreach ($courses as $course) {
// to get registrars in course level
$sql = "SELECT u.id, u.email, u.firstname, u.lastname\n FROM {context} AS cxt\n JOIN {role_assignments} AS ra\n ON cxt.id = ra.contextid \n JOIN {user} AS u\n ON ra.userid = u.id\n WHERE cxt.instanceid = {$course->id} AND ra.roleid = 9 AND cxt.contextlevel = 50";
$registrars = $DB->get_records_sql($sql);
foreach ($registrars as $registrar) {
$registrarfullname = fullname($registrar);
$registraroptions[$registrar->id . ',registrar'] = $registrarfullname;
}
}
$record = $DB->get_record_sql("SELECT * FROM {user} where id = 2");
$adminoption = array();
$adminoption[$record->id . ',admin'] = $record->firstname;
$options = array(get_string('instructor', 'block_queries') => $instructors12, get_string('registrar', 'block_queries') => $registraroptions, get_string('admin', 'block_queries') => $adminoption);
$mform->addElement('selectgroups', 'usertype', get_string('usertype', 'block_queries'), $options);
$mform->addRule('usertype', get_string('required'), 'required', null, 'client');
$adminoption[$record->id] = $record->firstname;
$mform->addElement('text', 'subject', get_string('subject', 'block_queries'));
$mform->setType('subject', PARAM_RAW);
$mform->addRule('subject', get_string('required'), 'required', null, 'client');
$mform->addElement('textarea', 'description', get_string('description', 'block_queries'), 'wrap="virtual" rows="3" cols="25"');
$mform->addRule('description', get_string('required'), 'required', null, 'client');
$this->add_action_buttons(FALSE, get_string('postquery', 'block_queries'));
$mform->addElement('html', html_writer::tag('a', get_string('mypreviewqueries', 'block_queries'), array('href' => $CFG->wwwroot . '/blocks/queries/display_queries.php?studentid=' . $USER->id, 'class' => 'mypreviewqueries')));
}
示例9: definition
function definition()
{
global $CFG, $DB, $USER;
$mform = $this->_form;
$attributes_heading = 'size="24"';
$attributes_radio_text = 'size="11"';
//General Section.
$mform->addElement('header', 'general', get_string('genheader', 'local_memplugin'));
//Get list of logged in user's enrolled courses and display as checkboxes.
$user_courses = enrol_get_users_courses($USER->id, true, '*', 'visible DESC,sortorder ASC');
$select_course_array = array();
$select_course_array[0] = '';
// Add a blank space to the select box.
$selectgroup = array();
//TODO Remove below Select code for checkboxes instead of dropdown
foreach ($user_courses as $uc) {
$select_course_array[$uc->id] = $uc->fullname;
}
$selectgroup[] = $mform->createElement('select', 'coursechoices', get_string('sectionheader', 'local_memplugin'), $select_course_array);
$mform->addElement('group', 'courseselect', get_string('courses', 'local_memplugin'), $selectgroup, array('<br>'), false);
//TODO For now we can only handle one course section but uncomment the following and get rid of the above
//Selection items to make it checkboxes again.
/*
foreach ($user_courses as $uc){
$courses_group[] =& $mform->createElement('advcheckbox', 'courseboxes['.$uc->id.']', null, $uc->fullname, array('group'=>0),array(0,1));
}
$mform->addElement('group', 'courseselect', get_string('courses', 'local_memplugin'), $courses_group, array('<br>'), false);
*/
$mform->addElement('header', 'fileheader', get_string('file', 'local_memplugin'));
//Switch to a filepicker for now until we figure out how it works.
//$mform->addElement('filemanager', 'files', get_string('exambatch', 'local_memplugin'), null, array('accepted_types' => 'image/png'));
$mform->addElement('filepicker', 'userfile', get_string('exambatch', 'local_memplugin'), null, array('accepted_types' => 'application/zip'));
$mform->closeHeaderBefore('buttonar');
$buttonarray = array();
//$buttonarray[] =& $mform->createElement('submit','savebutton', get_string('savebutton', 'local_memplugin'));
$buttonarray[] =& $mform->createElement('submit', 'markbutton', get_string('markbutton', 'local_memplugin'));
$buttonarray[] =& $mform->createElement('cancel');
$mform->addGroup($buttonarray, 'buttonar', '', array(' '), false);
}
示例10: __construct
/**
* Constructor. Sets local copies of user preferences and initialises grade_tree.
* @param int $userid
* @param object $gpr grade plugin return tracking object
* @param string $context
*/
public function __construct($userid, $gpr, $context)
{
global $CFG, $COURSE, $DB;
parent::__construct($COURSE->id, $gpr, $context);
// Get the user (for full name).
$this->user = $DB->get_record('user', array('id' => $userid));
// Load the user's courses.
$this->courses = enrol_get_users_courses($this->user->id, false, 'id, shortname, showgrades');
$this->showrank = array();
$this->showrank['any'] = false;
$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));
if ($this->showrank[$course->id]) {
$this->showrank['any'] = true;
}
$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;
}
}
}
// base url for sorting by first/last name
$this->baseurl = $CFG->wwwroot . '/grade/overview/index.php?id=' . $userid;
$this->pbarurl = $this->baseurl;
$this->setup_table();
}
示例11: count_unread_and_courses_messages
/**
* Returns unread messages count and courses
* @return array
*/
public static function count_unread_and_courses_messages($userid = '0')
{
global $DB, $USER;
//Parameter validation
//REQUIRED
$params = self::validate_parameters(self::count_unread_messages_parameters(), array('userid' => $userid));
//Context validation
//OPTIONAL but in most web service it should present
$context = get_context_instance(CONTEXT_USER, $USER->id);
self::validate_context($context);
//Capability checking
//OPTIONAL but in most web service it should present
if (!has_capability('moodle/user:viewdetails', $context)) {
throw new moodle_exception('cannotviewprofile');
}
$messagecount = $DB->count_records_select('message', 'useridto=' . (int) $userid);
$courses = enrol_get_users_courses($params['userid'], true, 'id, shortname, fullname, idnumber, visible');
$result = array('messagecount' => $messagecount, 'courses' => array());
foreach ($courses as $course) {
$context = context_course::instance($course->id, IGNORE_MISSING);
try {
self::validate_context($context);
} catch (Exception $e) {
// current user can not access this course, sorry we can not disclose who is enrolled in this course!
continue;
}
if ($userid != $USER->id and !has_capability('moodle/course:viewparticipants', $context)) {
// we need capability to view participants
continue;
}
list($enrolledsqlselect, $enrolledparams) = get_enrolled_sql($context);
$enrolledsql = "SELECT COUNT('x') FROM ({$enrolledsqlselect}) enrolleduserids";
$enrolledusercount = $DB->count_records_sql($enrolledsql, $enrolledparams);
$result['courses'][] = array('id' => $course->id, 'shortname' => $course->shortname, 'fullname' => $course->fullname, 'idnumber' => $course->idnumber, 'visible' => $course->visible, 'enrolledusercount' => $enrolledusercount);
}
return $result;
}
示例12: block_mystats_mycourses
function block_mystats_mycourses()
{
global $USER;
$mycourses = array();
$count = 0;
$enrolledcourses = enrol_get_users_courses($USER->id);
foreach ($enrolledcourses as $course) {
if (isset($USER->lastcourseaccess[$course->id])) {
$course->lastaccess = $USER->lastcourseaccess[$course->id];
} else {
$course->lastaccess = 0;
}
$mycourses[$course->id] = $course;
$count++;
}
if (is_enabled_auth('mnet')) {
$remotecourses = get_my_remotecourses();
foreach ($remotecourses as $course) {
$mycourses[$course->id] = $course;
$count++;
}
}
return $mycourses;
}
示例13: get_users_courses
/**
* Get list of courses user is enrolled in (only active enrolments are returned).
*
* Please note the current user must be able to access the course, otherwise the course is not included.
*
* @param int $userid
* @return array of courses
*/
public static function get_users_courses($userid)
{
global $USER;
// Do basic automatic PARAM checks on incoming data, using params description
// If any problems are found then exceptions are thrown with helpful error messages
$params = self::validate_parameters(self::get_users_courses_parameters(), array('userid' => $userid));
$courses = enrol_get_users_courses($params['userid'], true, 'id, shortname, fullname, idnumber, visible');
$result = array();
foreach ($courses as $course) {
$context = get_context_instance(CONTEXT_COURSE, $course->id);
try {
self::validate_context($context);
} catch (Exception $e) {
// current user can not access this course, sorry we can not disclose who is enrolled in this course!
continue;
}
if ($userid != $USER->id and !has_capability('moodle/course:viewparticipants', $context)) {
// we need capability to view participants
continue;
}
$result[] = array('id' => $course->id, 'shortname' => $course->shortname, 'fullname' => $course->fullname, 'idnumber' => $course->idnumber, 'visible' => $course->visible);
}
return $result;
}
示例14: block_mycourses_users
function block_mycourses_users()
{
global $CFG, $DB, $USER, $OUTPUT;
$courses = enrol_get_users_courses($USER->id);
//print_object($courses);
$output = '';
foreach ($courses as $course) {
$summary = $DB->get_record_sql("SELECT * FROM {course} WHERE id = {$course->id}");
//print_object($summary);
$output .= "<div>";
$output .= html_writer::tag('b', $course->fullname, array());
$output .= html_writer::tag('p', $summary->summary, array());
$output .= html_writer::tag('a', get_string('launch', 'block_mycourses'), array());
$data = array();
$line = array();
$user = $DB->get_record_sql("SELECT firstname FROM {user} WHERE id = {$USER->id}");
$line[] = $user->firstname;
$date1 = date('d/m/Y', $course->startdate);
$line[] = $date1;
$completed_date = $DB->get_record_sql("SELECT * FROM {course_completions} WHERE course = {$course->id}");
$date2 = date('d/m/Y', $completed_date->timecompleted);
if (!empty($date2)) {
$line[] = "--";
} else {
$line[] = $date2;
}
$data[] = $line;
$table = new html_table();
$table->head = array(get_string('training_name', 'block_mycourses'), get_string('training_code', 'block_mycourses'), get_string('launch', 'block_mycourses'));
$table->data = $data;
$output .= html_writer::table($table);
$output .= html_writer::tag('a', get_string('launch', 'block_mycourses'), array());
$output .= "</div>";
}
return $output;
}
示例15: load_for_user
//.........这里部分代码省略.........
$messageargs['user2'] = $user->id;
}
if ($course->id != $SITE->id) {
$messageargs['viewing'] = MESSAGE_VIEW_COURSE . $course->id;
}
$url = new moodle_url('/message/index.php', $messageargs);
$usernode->add(get_string('messages', 'message'), $url, self::TYPE_SETTING, null, 'messages');
}
// Add the "My private files" link.
// This link doesn't have a unique display for course context so only display it under the user's profile.
if ($issitecourse && $iscurrentuser && has_capability('moodle/user:manageownfiles', $usercontext)) {
$url = new moodle_url('/user/files.php');
$usernode->add(get_string('privatefiles'), $url, self::TYPE_SETTING);
}
// Add a node to view the users notes if permitted.
if (!empty($CFG->enablenotes) && has_any_capability(array('moodle/notes:manage', 'moodle/notes:view'), $coursecontext)) {
$url = new moodle_url('/notes/index.php', array('user' => $user->id));
if ($coursecontext->instanceid != SITEID) {
$url->param('course', $coursecontext->instanceid);
}
$usernode->add(get_string('notes', 'notes'), $url);
}
// Show the grades node.
if ($issitecourse && $iscurrentuser || has_capability('moodle/user:viewdetails', $usercontext)) {
require_once $CFG->dirroot . '/user/lib.php';
// Set the grades node to link to the "Grades" page.
if ($course->id == SITEID) {
$url = user_mygrades_url($user->id, $course->id);
} else {
// Otherwise we are in a course and should redirect to the user grade report (Activity report version).
$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, self::TYPE_SETTING, null, 'usergrades');
} else {
$usernode->add(get_string('grades', 'grades'), $url);
}
}
// If the user is the current user add the repositories for the current user.
$hiddenfields = array_flip(explode(',', $CFG->hiddenuserfields));
if (!$iscurrentuser && $course->id == $SITE->id && has_capability('moodle/user:viewdetails', $usercontext) && (!in_array('mycourses', $hiddenfields) || has_capability('moodle/user:viewhiddendetails', $coursecontext))) {
// Add view grade report is permitted.
$reports = core_component::get_plugin_list('gradereport');
arsort($reports);
// User is last, we want to test it first.
$userscourses = enrol_get_users_courses($user->id);
$userscoursesnode = $usernode->add(get_string('courses'));
$count = 0;
foreach ($userscourses as $usercourse) {
if ($count === (int) $CFG->navcourselimit) {
$url = new moodle_url('/user/profile.php', array('id' => $user->id, 'showallcourses' => 1));
$userscoursesnode->add(get_string('showallcourses'), $url);
break;
}
$count++;
$usercoursecontext = context_course::instance($usercourse->id);
$usercourseshortname = format_string($usercourse->shortname, true, array('context' => $usercoursecontext));
$usercoursenode = $userscoursesnode->add($usercourseshortname, new moodle_url('/user/view.php', array('id' => $user->id, 'course' => $usercourse->id)), self::TYPE_CONTAINER);
$gradeavailable = has_capability('moodle/grade:viewall', $usercoursecontext);
if (!$gradeavailable && !empty($usercourse->showgrades) && is_array($reports) && !empty($reports)) {
foreach ($reports as $plugin => $plugindir) {
if (has_capability('gradereport/' . $plugin . ':view', $usercoursecontext)) {
// Stop when the first visible plugin is found.
$gradeavailable = true;
break;
}
}
}
if ($gradeavailable) {
$url = new moodle_url('/grade/report/index.php', array('id' => $usercourse->id));
$usercoursenode->add(get_string('grades'), $url, self::TYPE_SETTING, null, null, new pix_icon('i/grades', ''));
}
// Add a node to view the users notes if permitted.
if (!empty($CFG->enablenotes) && has_any_capability(array('moodle/notes:manage', 'moodle/notes:view'), $usercoursecontext)) {
$url = new moodle_url('/notes/index.php', array('user' => $user->id, 'course' => $usercourse->id));
$usercoursenode->add(get_string('notes', 'notes'), $url, self::TYPE_SETTING);
}
if (can_access_course($usercourse, $user->id, '', true)) {
$usercoursenode->add(get_string('entercourse'), new moodle_url('/course/view.php', array('id' => $usercourse->id)), self::TYPE_SETTING, null, null, new pix_icon('i/course', ''));
}
$reporttab = $usercoursenode->add(get_string('activityreports'));
$reports = get_plugin_list_with_function('report', 'extend_navigation_user', 'lib.php');
foreach ($reports as $reportfunction) {
$reportfunction($reporttab, $user, $usercourse);
}
$reporttab->trim_if_empty();
}
}
// Let plugins hook into user navigation.
$pluginsfunction = get_plugins_with_function('extend_navigation_user', 'lib.php');
foreach ($pluginsfunction as $plugintype => $plugins) {
if ($plugintype != 'report') {
foreach ($plugins as $pluginfunction) {
$pluginfunction($usernode, $user, $usercontext, $course, $coursecontext);
}
}
}
}
return true;
}