示例#1
0
 /**
  * Allows course format to execute code on moodle_page::set_cm()
  *
  * If we are inside the main module for this course, remove extra node level
  * from navigation: substitute course node with activity node, move all children
  *
  * @param moodle_page $page instance of page calling set_cm
  */
 public function page_set_cm(moodle_page $page)
 {
     global $PAGE;
     parent::page_set_cm($page);
     if ($PAGE == $page && ($cm = $this->get_activity()) && $cm->uservisible && $cm->id === $page->cm->id && ($activitynode = $page->navigation->find($cm->id, navigation_node::TYPE_ACTIVITY)) && ($node = $page->navigation->find($page->course->id, navigation_node::TYPE_COURSE))) {
         // Substitute course node with activity node, move all children.
         $node->action = $activitynode->action;
         $node->type = $activitynode->type;
         $node->id = $activitynode->id;
         $node->key = $activitynode->key;
         $node->isactive = $node->isactive || $activitynode->isactive;
         $node->icon = null;
         if ($activitynode->children->count()) {
             foreach ($activitynode->children as &$child) {
                 $child->remove();
                 $node->add_node($child);
             }
         } else {
             $node->search_for_active_node();
         }
         $activitynode->remove();
     }
 }