/** * Change the navigation block and bar only for external users * Force course or activity navigation and modify CSS also * Please note that this function is only called in pages where the navigation block is present * * @global moodle_user $USER * @global moodle_database $DB * @param navigation_node $nav Current navigation object */ function local_ltiprovider_extend_navigation($nav) { global $USER, $PAGE, $SESSION; // Check capabilities for tool providers // TODO Change this for Moodle 2.3: // use extend_navigation_course and extend_navigation_user if ($PAGE->course->id and $PAGE->course->id != SITEID and has_capability('local/ltiprovider:view', $PAGE->context)) { $ltiurl = new moodle_url('/local/ltiprovider/index.php', array('courseid' => $PAGE->course->id)); $coursenode = $nav->find($PAGE->course->id, $nav::TYPE_COURSE); $coursenode->add(get_string('pluginname', 'local_ltiprovider'), $ltiurl, $nav::TYPE_CONTAINER, null, 'ltiprovider' . $PAGE->course->id); } if (isset($USER) and isset($USER->auth) and $USER->auth == 'nologin' and strpos($USER->username, 'ltiprovider') === 0) { // Force course or activity navigation if (isset($SESSION->ltiprovider) and $SESSION->ltiprovider->forcenavigation) { $context = $SESSION->ltiprovider->context; $urltogo = ''; if ($context->contextlevel == CONTEXT_COURSE and $PAGE->course->id != $SESSION->ltiprovider->courseid) { $urltogo = new moodle_url('/course/view.php', array('id' => $SESSION->ltiprovider->courseid)); } else if ($context->contextlevel == CONTEXT_MODULE and $PAGE->context->id != $context->id) { $cm = get_coursemodule_from_id(false, $context->instanceid, 0, false, MUST_EXIST); $urltogo = new moodle_url('/mod/' . $cm->modname . '/view.php', array('id' => $cm->id)); } if ($urltogo) { redirect($urltogo); } } // Delete all the navigation nodes except the course one $coursenode = $nav->find($PAGE->course->id, $nav::TYPE_COURSE); foreach (array('myprofile', 'users', 'site', 'home', 'myhome', 'mycourses', 'courses', '1') as $nodekey) { if ($node = $nav->get($nodekey)) { $node->remove(); } } $nav->children->add($coursenode); // Custom CSS if (isset($SESSION->ltiprovider)) { $PAGE->requires->css(new moodle_url('/local/ltiprovider/styles.php', array('id' => $SESSION->ltiprovider->id))); } } }
public function test_find() { $node1 = $this->node->find('demo1', navigation_node::TYPE_COURSE); $node2 = $this->node->find('demo5', navigation_node::TYPE_COURSE); $node3 = $this->node->find('demo5', navigation_node::TYPE_CATEGORY); $node4 = $this->node->find('demo0', navigation_node::TYPE_COURSE); $this->assertIsA($node1, 'navigation_node'); $this->assertIsA($node2, 'navigation_node'); $this->assertNotA($node3, 'navigation_node'); $this->assertNotA($node4, 'navigation_node'); }
public function test_find() { $node1 = $this->node->find('demo1', navigation_node::TYPE_COURSE); $node2 = $this->node->find('demo5', navigation_node::TYPE_COURSE); $node3 = $this->node->find('demo5', navigation_node::TYPE_CATEGORY); $node4 = $this->node->find('demo0', navigation_node::TYPE_COURSE); $this->assertInstanceOf('navigation_node', $node1); $this->assertInstanceOf('navigation_node', $node2); $this->assertNotInstanceOf('navigation_node', $node3); $this->assertNotInstanceOf('navigation_node', $node4); }
/** * Change the navigation block and bar only for external users * Force course or activity navigation and modify CSS also * Please note that this function is only called in pages where the navigation block is present * * @global moodle_user $USER * @global moodle_database $DB * @param navigation_node $nav Current navigation object */ function local_ltiprovider_extends_navigation($nav) { global $CFG, $USER, $PAGE, $SESSION, $ME; // Check capabilities for tool providers // Only for Moodle < 2.3 versions if ($CFG->version < 2012062500 and $PAGE->course->id and $PAGE->course->id != SITEID and has_capability('local/ltiprovider:view', $PAGE->context)) { $ltiurl = new moodle_url('/local/ltiprovider/index.php', array('courseid' => $PAGE->course->id)); $coursenode = $nav->find($PAGE->course->id, $nav::TYPE_COURSE); $coursenode->add(get_string('pluginname', 'local_ltiprovider'), $ltiurl, $nav::TYPE_CONTAINER, null, 'ltiprovider' . $PAGE->course->id); } if (isset($USER) and isset($USER->auth) and strpos($USER->username, 'ltiprovider') === 0) { // Force course or activity navigation if (isset($SESSION->ltiprovider) and $SESSION->ltiprovider->forcenavigation) { $context = $SESSION->ltiprovider->context; $urltogo = ''; if ($context->contextlevel == CONTEXT_COURSE and $PAGE->course->id != $SESSION->ltiprovider->courseid) { $urltogo = new moodle_url('/course/view.php', array('id' => $SESSION->ltiprovider->courseid)); } else { if ($context->contextlevel == CONTEXT_MODULE and $PAGE->context->id != $context->id) { $cm = get_coursemodule_from_id(false, $context->instanceid, 0, false, MUST_EXIST); $urltogo = new moodle_url('/mod/' . $cm->modname . '/view.php', array('id' => $cm->id)); } } // Special case, user policy, we don't have to do nothing to avoid infinites loops. if (strpos($ME, 'user/policy.php')) { return; } if ($urltogo) { redirect($urltogo); } } // Delete all the navigation nodes except the course one if ($coursenode = $nav->find($PAGE->course->id, $nav::TYPE_COURSE)) { foreach (array('myprofile', 'users', 'site', 'home', 'myhome', 'mycourses', 'courses', '1') as $nodekey) { if ($node = $nav->get($nodekey)) { $node->remove(); } } $nav->children->add($coursenode); } // Custom CSS if (isset($SESSION->ltiprovider) and !$PAGE->requires->is_head_done()) { $PAGE->requires->css(new moodle_url('/local/ltiprovider/styles.php', array('id' => $SESSION->ltiprovider->id))); } else { $url = new moodle_url('/local/ltiprovider/styles.js.php', array('id' => $SESSION->ltiprovider->id, 'rand' => rand(0, 1000))); $PAGE->requires->js($url); } } }
/** * Searches this nodes children and their children to find a navigation node * with the matching key and type. * * This method is recursive and searches children so until either a node is * found or there are no more nodes to search. * * If you know that the node being searched for is a child of this node * then use the {@link global_navigation::get()} method instead. * * Note: If you are trying to set the active node {@link navigation_node::override_active_url()} * may be of more use to you. * * @param string|int $key The key of the node you wish to receive. * @param int $type One of navigation_node::TYPE_* * @return navigation_node|false */ public function find($key, $type) { if (!$this->initialised) { $this->initialise(); } return parent::find($key, $type); }
/** * Searches this nodes children and their children to find a navigation node * with the matching key and type. * * This method is recursive and searches children so until either a node is * found or there are no more nodes to search. * * If you know that the node being searched for is a child of this node * then use the {@link global_navigation::get()} method instead. * * Note: If you are trying to set the active node {@link navigation_node::override_active_url()} * may be of more use to you. * * @param string|int $key The key of the node you wish to receive. * @param int $type One of navigation_node::TYPE_* * @return navigation_node|false */ public function find($key, $type) { if (!$this->initialised) { $this->initialise(); } if ($type == self::TYPE_ROOTNODE && array_key_exists($key, $this->rootnodes)) { return $this->rootnodes[$key]; } return parent::find($key, $type); }
/** * Adds a structured category to the navigation in the correct order/place * * @param stdClass $category * @param navigation_node $parent */ protected function add_category(stdClass $category, navigation_node $parent, $nodetype = self::TYPE_CATEGORY) { if (!$this->expandtocourses && $parent->key == 'courses' || $parent->find($category->id, self::TYPE_CATEGORY)) { return; } $url = new moodle_url('/course/category.php', array('id' => $category->id)); $context = context_coursecat::instance($category->id); $categoryname = format_string($category->name, true, array('context' => $context)); $categorynode = $parent->add($categoryname, $url, $nodetype, $categoryname, $category->id); if (empty($category->visible)) { if (has_capability('moodle/category:viewhiddencategories', context_system::instance())) { $categorynode->hidden = true; } else { $categorynode->display = false; } } $this->addedcategories[$category->id] = $categorynode; }