예제 #1
0
 /**
  * Parse all callbacks and builds the tree.
  *
  * @param integer   $user ID of the user for which the profile is displayed.
  * @param bool      $iscurrentuser true if the profile being viewed is of current user, else false.
  * @param \stdClass $course Course object
  *
  * @return tree Fully build tree to be rendered on my profile page.
  */
 public static function build_tree($user, $iscurrentuser, $course = null)
 {
     global $CFG;
     $tree = new tree();
     // Add core nodes.
     require_once $CFG->libdir . "/myprofilelib.php";
     core_myprofile_navigation($tree, $user, $iscurrentuser, $course);
     // Core components.
     $components = \core_component::get_core_subsystems();
     foreach ($components as $component => $directory) {
         if (empty($directory)) {
             continue;
         }
         $file = $directory . "/lib.php";
         if (is_readable($file)) {
             require_once $file;
             $function = "core_" . $component . "_myprofile_navigation";
             if (function_exists($function)) {
                 $function($tree, $user, $iscurrentuser, $course);
             }
         }
     }
     // Plugins.
     $types = \core_component::get_plugin_types();
     foreach ($types as $type => $dir) {
         $pluginlist = get_plugin_list_with_function($type, "myprofile_navigation", "lib.php");
         foreach ($pluginlist as $function) {
             $function($tree, $user, $iscurrentuser, $course);
         }
     }
     $tree->sort_categories();
     return $tree;
 }
예제 #2
0
 /**
  * Parse all callbacks and builds the tree.
  *
  * @param integer   $user ID of the user for which the profile is displayed.
  * @param bool      $iscurrentuser true if the profile being viewed is of current user, else false.
  * @param \stdClass $course Course object
  *
  * @return tree Fully build tree to be rendered on my profile page.
  */
 public static function build_tree($user, $iscurrentuser, $course = null)
 {
     global $CFG;
     $tree = new tree();
     //print_r($user);
     // Add core nodes.
     require_once $CFG->libdir . "/myprofilelib.php";
     core_myprofile_navigation($tree, $user, $iscurrentuser, $course);
     // Core components.
     $components = \core_component::get_core_subsystems();
     foreach ($components as $component => $directory) {
         if (empty($directory)) {
             continue;
         }
         $file = $directory . "/lib.php";
         if (is_readable($file)) {
             require_once $file;
             $function = "core_" . $component . "_myprofile_navigation";
             //print_r($function);
             if (function_exists($function)) {
                 //echo "Current function: ".$function."<br>";
                 $function($tree, $user, $iscurrentuser, $course);
             }
         }
     }
     // Plugins.
     $pluginswithfunction = get_plugins_with_function('myprofile_navigation', 'lib.php');
     foreach ($pluginswithfunction as $plugins) {
         foreach ($plugins as $function) {
             $function($tree, $user, $iscurrentuser, $course);
         }
     }
     $tree->sort_categories();
     return $tree;
 }
예제 #3
0
 /**
  * Tests the core_myprofile_navigation() function as a user viewing another user's profile
  * ensuring the login activity links are not shown.
  */
 public function test_core_myprofile_navigationn_login_activity_without_permission()
 {
     // User without permission.
     set_config("hiddenuserfields", "firstaccess,lastaccess,lastip");
     $this->setUser($this->user2);
     $iscurrentuser = false;
     core_myprofile_navigation($this->tree, $this->user, $iscurrentuser, null);
     $reflector = new ReflectionObject($this->tree);
     $nodes = $reflector->getProperty('nodes');
     $nodes->setAccessible(true);
     $this->assertArrayNotHasKey('firstaccess', $nodes->getValue($this->tree));
     $this->assertArrayNotHasKey('lastaccess', $nodes->getValue($this->tree));
     $this->assertArrayNotHasKey('lastip', $nodes->getValue($this->tree));
 }