Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

navigation MDL-22749 Added course information to a users navigation w…

…hen viewing another user.
  • Loading branch information...
commit 9acb82412234bccdb30c2c3de08a29eb3b19f23c 1 parent 4fdb592
Sam Hemelryk samhemelryk authored

Showing 1 changed file with 67 additions and 3 deletions. Show diff stats Hide diff stats

  1. +67 3 lib/navigationlib.php
70 lib/navigationlib.php
@@ -1553,7 +1553,8 @@ protected function load_for_user($user=null, $forceforcontext=false) {
1553 1553
1554 1554 // Add a reports tab and then add reports the the user has permission to see.
1555 1555 $anyreport = has_capability('moodle/user:viewuseractivitiesreport', $usercontext);
1556   - $viewreports = ($anyreport || ($course->showreports && $iscurrentuser));
  1556 +
  1557 + $viewreports = ($anyreport || ($course->showreports && $iscurrentuser && $forceforcontext));
1557 1558 if ($viewreports) {
1558 1559 $reporttab = $usernode->add(get_string('activityreports'));
1559 1560 $reportargs = array('user'=>$user->id);
@@ -1608,15 +1609,78 @@ protected function load_for_user($user=null, $forceforcontext=false) {
1608 1609 }
1609 1610 }
1610 1611
1611   -
1612 1612 // If the user is the current user add the repositories for the current user
  1613 + $hiddenfields = array_flip(explode(',', $CFG->hiddenuserfields));
1613 1614 if ($iscurrentuser) {
1614   -
1615 1615 require_once($CFG->dirroot . '/repository/lib.php');
1616 1616 $editabletypes = repository::get_editable_types($usercontext);
1617 1617 if (!empty($editabletypes)) {
1618 1618 $usernode->add(get_string('repositories', 'repository'), new moodle_url('/repository/manage_instances.php', array('contextid' => $usercontext->id)));
1619 1619 }
  1620 + } else if ($course->id == SITEID && has_capability('moodle/user:viewdetails', $usercontext) && (!in_array('mycourses', $hiddenfields) || has_capability('moodle/user:viewhiddendetails', $coursecontext))) {
  1621 +
  1622 + // Add view grade report is permitted
  1623 + $reports = get_plugin_list('gradereport');
  1624 + arsort($reports); // user is last, we want to test it first
  1625 +
  1626 + $userscourses = enrol_get_users_courses($user->id);
  1627 + $userscoursesnode = $usernode->add(get_string('courses'));
  1628 +
  1629 + foreach ($userscourses as $usercourse) {
  1630 + $usercoursecontext = get_context_instance(CONTEXT_COURSE, $usercourse->id);
  1631 + $usercoursenode = $userscoursesnode->add($usercourse->shortname, new moodle_url('/user/view.php', array('id'=>$user->id, 'course'=>$usercourse->id)), self::TYPE_CONTAINER);
  1632 +
  1633 + $gradeavailable = has_capability('moodle/grade:viewall', $usercoursecontext);
  1634 + if (!$gradeavailable && !empty($usercourse->showgrades) && is_array($reports) && !empty($reports)) {
  1635 + foreach ($reports as $plugin => $plugindir) {
  1636 + if (has_capability('gradereport/'.$plugin.':view', $usercoursecontext)) {
  1637 + //stop when the first visible plugin is found
  1638 + $gradeavailable = true;
  1639 + break;
  1640 + }
  1641 + }
  1642 + }
  1643 +
  1644 + if ($gradeavailable) {
  1645 + $url = new moodle_url('/grade/report/index.php', array('id'=>$usercourse->id));
  1646 + $usercoursenode->add(get_string('grades'), $url, self::TYPE_SETTING, null, null, new pix_icon('i/grades', ''));
  1647 + }
  1648 +
  1649 + // Add a node to view the users notes if permitted
  1650 + if (!empty($CFG->enablenotes) && has_any_capability(array('moodle/notes:manage', 'moodle/notes:view'), $usercoursecontext)) {
  1651 + $url = new moodle_url('/notes/index.php',array('user'=>$user->id, 'course'=>$usercourse->id));
  1652 + $usercoursenode->add(get_string('notes', 'notes'), $url, self::TYPE_SETTING);
  1653 + }
  1654 +
  1655 + if (has_capability('moodle/course:view', get_context_instance(CONTEXT_COURSE, $usercourse->id))) {
  1656 + $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', ''));
  1657 + }
  1658 +
  1659 + $outlinetreport = ($anyreport || has_capability('coursereport/outline:view', $usercoursecontext));
  1660 + $logtodayreport = ($anyreport || has_capability('coursereport/log:viewtoday', $usercoursecontext));
  1661 + $logreport = ($anyreport || has_capability('coursereport/log:view', $usercoursecontext));
  1662 + $statsreport = ($anyreport || has_capability('coursereport/stats:view', $usercoursecontext));
  1663 + if ($outlinetreport || $logtodayreport || $logreport || $statsreport) {
  1664 + $reporttab = $usercoursenode->add(get_string('activityreports'));
  1665 + $reportargs = array('user'=>$user->id, 'id'=>$usercourse->id);
  1666 + if ($outlinetreport) {
  1667 + $reporttab->add(get_string('outlinereport'), new moodle_url('/course/user.php', array_merge($reportargs, array('mode'=>'outline'))));
  1668 + $reporttab->add(get_string('completereport'), new moodle_url('/course/user.php', array_merge($reportargs, array('mode'=>'complete'))));
  1669 + }
  1670 +
  1671 + if ($logtodayreport) {
  1672 + $reporttab->add(get_string('todaylogs'), new moodle_url('/course/user.php', array_merge($reportargs, array('mode'=>'todaylogs'))));
  1673 + }
  1674 +
  1675 + if ($logreport) {
  1676 + $reporttab->add(get_string('alllogs'), new moodle_url('/course/user.php', array_merge($reportargs, array('mode'=>'alllogs'))));
  1677 + }
  1678 +
  1679 + if (!empty($CFG->enablestats) && $statsreport) {
  1680 + $reporttab->add(get_string('stats'), new moodle_url('/course/user.php', array_merge($reportargs, array('mode'=>'stats'))));
  1681 + }
  1682 + }
  1683 + }
1620 1684 }
1621 1685 return true;
1622 1686 }

0 comments on commit 9acb824

Please sign in to comment.
Something went wrong with that request. Please try again.