MDL-25805 Roles propagated ugly hack for parent seeing child activities into navigati...
authorAparup Banerjee <aparup@moodle.com>
Fri, 15 Apr 2011 10:04:45 +0000 (18:04 +0800)
committerAparup Banerjee <aparup@moodle.com>
Mon, 2 May 2011 12:08:08 +0000 (20:08 +0800)
course/user.php
lib/navigationlib.php
mod/forum/user.php
user/view.php

index b5ab6cd..81bcc84 100644 (file)
@@ -152,6 +152,7 @@ if ($course->id != SITEID && has_capability('moodle/course:viewparticipants', $c
 }
 
 $PAGE->navigation->extend_for_user($user);
+$PAGE->navigation->set_userid_for_parent_nav_hack($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);
 echo $OUTPUT->header();
index 4434d7c..dbf035f 100644 (file)
@@ -829,6 +829,8 @@ class global_navigation extends navigation_node {
     protected $addedcourses = array();
     /** @var int */
     protected $expansionlimit = 0;
+    /** @var int */
+    protected $uglyunsupportedparenthack_userid = 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_nav_hack($userid) {
+        $this->uglyunsupportedparenthack_userid = $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->uglyunsupportedparenthack_userid) {
+                        $currentuser = ($this->uglyunsupportedparenthack_userid == $USER->id);
+                        if (!$currentuser) {
+                            $usercontext   = get_context_instance(CONTEXT_USER, $this->uglyunsupportedparenthack_userid, 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);
index 6576056..0efe8ba 100644 (file)
@@ -86,6 +86,7 @@ if (has_capability('moodle/course:viewparticipants', get_context_instance(CONTEX
 }
 
 $PAGE->navigation->extend_for_user($user);
+$PAGE->navigation->set_userid_for_parent_nav_hack($id); // see MDL-25805 for reasons and for full commit reference for reversal when fixed.
 $PAGE->set_title("$course->shortname: $fullname: $strmode");
 $PAGE->set_heading($course->fullname);
 echo $OUTPUT->header();
index c77ba7c..ea56d61 100644 (file)
@@ -80,6 +80,7 @@ if (!$currentuser
     //       please note this is just a guess!
     require_login();
     $isparent = true;
+    $PAGE->navigation->set_userid_for_parent_nav_hack($id);
 } else {
     // normal course
     require_login($course);