original_string: protected function generate_sections_and_activities(stdClass $course) {
          global $CFG;
          require_once($CFG->dirroot.'/course/lib.php');
  
          $modinfo = get_fast_modinfo($course);
          $sections = $modinfo->get_section_info_all();
  
          // For course formats using 'numsections' trim the sections list
          $courseformatoptions = course_get_format($course)->get_format_options();
          if (isset($courseformatoptions['numsections'])) {
              $sections = array_slice($sections, 0, $courseformatoptions['numsections']+1, true);
          }
  
          $activities = array();
  
          foreach ($sections as $key => $section) {
              // Clone and unset summary to prevent $SESSION bloat (MDL-31802).
              $sections[$key] = clone($section);
              unset($sections[$key]->summary);
              $sections[$key]->hasactivites = false;
              if (!array_key_exists($section->section, $modinfo->sections)) {
                  continue;
              }
              foreach ($modinfo->sections[$section->section] as $cmid) {
                  $cm = $modinfo->cms[$cmid];
                  $activity = new stdClass;
                  $activity->id = $cm->id;
                  $activity->course = $course->id;
                  $activity->section = $section->section;
                  $activity->name = $cm->name;
                  $activity->icon = $cm->icon;
                  $activity->iconcomponent = $cm->iconcomponent;
                  $activity->hidden = (!$cm->visible);
                  $activity->modname = $cm->modname;
                  $activity->nodetype = navigation_node::NODETYPE_LEAF;
                  $activity->onclick = $cm->onclick;
                  $url = $cm->url;
                  if (!$url) {
                      $activity->url = null;
                      $activity->display = false;
                  } else {
                      $activity->url = $url->out();
                      $activity->display = $cm->is_visible_on_course_page() ? true : false;
                      if (self::module_extends_navigation($cm->modname)) {
                          $activity->nodetype = navigation_node::NODETYPE_BRANCH;
                      }
                  }
                  $activities[$cmid] = $activity;
                  if ($activity->display) {
                      $sections[$key]->hasactivites = true;
                  }
              }
          }
  
          return array($sections, $activities);
      }
code: protected function generate_sections_and_activities(stdClass $course) {
          global $CFG;
          require_once($CFG->dirroot.'/course/lib.php');
  
          $modinfo = get_fast_modinfo($course);
          $sections = $modinfo->get_section_info_all();
  
          // For course formats using 'numsections' trim the sections list
          $courseformatoptions = course_get_format($course)->get_format_options();
          if (isset($courseformatoptions['numsections'])) {
              $sections = array_slice($sections, 0, $courseformatoptions['numsections']+1, true);
          }
  
          $activities = array();
  
          foreach ($sections as $key => $section) {
              // Clone and unset summary to prevent $SESSION bloat (MDL-31802).
              $sections[$key] = clone($section);
              unset($sections[$key]->summary);
              $sections[$key]->hasactivites = false;
              if (!array_key_exists($section->section, $modinfo->sections)) {
                  continue;
              }
              foreach ($modinfo->sections[$section->section] as $cmid) {
                  $cm = $modinfo->cms[$cmid];
                  $activity = new stdClass;
                  $activity->id = $cm->id;
                  $activity->course = $course->id;
                  $activity->section = $section->section;
                  $activity->name = $cm->name;
                  $activity->icon = $cm->icon;
                  $activity->iconcomponent = $cm->iconcomponent;
                  $activity->hidden = (!$cm->visible);
                  $activity->modname = $cm->modname;
                  $activity->nodetype = navigation_node::NODETYPE_LEAF;
                  $activity->onclick = $cm->onclick;
                  $url = $cm->url;
                  if (!$url) {
                      $activity->url = null;
                      $activity->display = false;
                  } else {
                      $activity->url = $url->out();
                      $activity->display = $cm->is_visible_on_course_page() ? true : false;
                      if (self::module_extends_navigation($cm->modname)) {
                          $activity->nodetype = navigation_node::NODETYPE_BRANCH;
                      }
                  }
                  $activities[$cmid] = $activity;
                  if ($activity->display) {
                      $sections[$key]->hasactivites = true;
                  }
              }
          }
  
          return array($sections, $activities);
      }
code_tokens: protected function generate_sections_and_activities ( stdClass $ course ) { global $ CFG ; require_once ( $ CFG -> dirroot . '/course/lib.php' ) ; $ modinfo = get_fast_modinfo ( $ course ) ; $ sections = $ modinfo -> get_section_info_all ( ) ; // For course formats using 'numsections' trim the sections list $ courseformatoptions = course_get_format ( $ course ) -> get_format_options ( ) ; if ( isset ( $ courseformatoptions [ 'numsections' ] ) ) { $ sections = array_slice ( $ sections , 0 , $ courseformatoptions [ 'numsections' ] + 1 , true ) ; } $ activities = array ( ) ; foreach ( $ sections as $ key => $ section ) { // Clone and unset summary to prevent $SESSION bloat (MDL-31802). $ sections [ $ key ] = clone ( $ section ) ; unset ( $ sections [ $ key ] -> summary ) ; $ sections [ $ key ] -> hasactivites = false ; if ( ! array_key_exists ( $ section -> section , $ modinfo -> sections ) ) { continue ; } foreach ( $ modinfo -> sections [ $ section -> section ] as $ cmid ) { $ cm = $ modinfo -> cms [ $ cmid ] ; $ activity = new stdClass ; $ activity -> id = $ cm -> id ; $ activity -> course = $ course -> id ; $ activity -> section = $ section -> section ; $ activity -> name = $ cm -> name ; $ activity -> icon = $ cm -> icon ; $ activity -> iconcomponent = $ cm -> iconcomponent ; $ activity -> hidden = ( ! $ cm -> visible ) ; $ activity -> modname = $ cm -> modname ; $ activity -> nodetype = navigation_node :: NODETYPE_LEAF ; $ activity -> onclick = $ cm -> onclick ; $ url = $ cm -> url ; if ( ! $ url ) { $ activity -> url = null ; $ activity -> display = false ; } else { $ activity -> url = $ url -> out ( ) ; $ activity -> display = $ cm -> is_visible_on_course_page ( ) ? true : false ; if ( self :: module_extends_navigation ( $ cm -> modname ) ) { $ activity -> nodetype = navigation_node :: NODETYPE_BRANCH ; } } $ activities [ $ cmid ] = $ activity ; if ( $ activity -> display ) { $ sections [ $ key ] -> hasactivites = true ; } } } return array ( $ sections , $ activities ) ; }
docstring: Generates an array of sections and an array of activities for the given course.
  
  This method uses the cache to improve performance and avoid the get_fast_modinfo call
  
  @param stdClass $course
  @return array Array($sections, $activities)
docstring_tokens: Generates an array of sections and an array of activities for the given course .