Merged MDL-25805 Renamed property and function to be a little more descriptive

This commit is contained in:
Sam Hemelryk
2011-05-03 15:41:34 +08:00
4 changed files with 38 additions and 4 deletions
+35 -4
View File
@@ -829,6 +829,8 @@ class global_navigation extends navigation_node {
protected $addedcourses = array();
/** @var int */
protected $expansionlimit = 0;
/** @var int */
protected $useridtouseforparentchecks = 0;
/**
* Constructs a new global navigation
@@ -875,6 +877,19 @@ class global_navigation extends navigation_node {
}
}
/**
* Mutator to set userid to allow parent to see child's profile
* page navigation. See MDL-25805 for initial issue. Linked to it
* is an issue explaining why this is a REALLY UGLY HACK thats not
* for you to use!
*
* @param int $userid userid of profile page that parent wants to navigate around.
*/
public function set_userid_for_parent_checks($userid) {
$this->useridtouseforparentchecks = $userid;
}
/**
* Initialises the navigation object.
*
@@ -986,12 +1001,28 @@ class global_navigation extends navigation_node {
// If the user is not enrolled then we only want to show the
// course node and not populate it.
$coursecontext = get_context_instance(CONTEXT_COURSE, $course->id);
// Not enrolled, can't view, and hasn't switched roles
// Not enrolled, can't view, and hasn't switched roles
if (!can_access_course($coursecontext)) {
$coursenode->make_active();
$canviewcourseprofile = false;
break;
// TODO: very ugly hack - do not force "parents" to enrol into course their child is enrolled in,
// this hack has been propagated from user/view.php to display the navigation node. (MDL-25805)
$isparent = false;
if ($this->useridtouseforparentchecks) {
$currentuser = ($this->useridtouseforparentchecks == $USER->id);
if (!$currentuser) {
$usercontext = get_context_instance(CONTEXT_USER, $this->useridtouseforparentchecks, MUST_EXIST);
if ($DB->record_exists('role_assignments', array('userid'=>$USER->id, 'contextid'=>$usercontext->id))
and has_capability('moodle/user:viewdetails', $usercontext)) {
$isparent = true;
}
}
}
if (!$isparent) {
$coursenode->make_active();
$canviewcourseprofile = false;
break;
}
}
// Add the essentials such as reports etc...
$this->add_course_essentials($coursenode, $course);