original_string: protected static function get_tree($id) {
          global $DB;
          $coursecattreecache = cache::make('core', 'coursecattree');
          $rv = $coursecattreecache->get($id);
          if ($rv !== false) {
              return $rv;
          }
          // Re-build the tree.
          $sql = "SELECT cc.id, cc.parent, cc.visible
                  FROM {course_categories} cc
                  ORDER BY cc.sortorder";
          $rs = $DB->get_recordset_sql($sql, array());
          $all = array(0 => array(), '0i' => array());
          $count = 0;
          foreach ($rs as $record) {
              $all[$record->id] = array();
              $all[$record->id. 'i'] = array();
              if (array_key_exists($record->parent, $all)) {
                  $all[$record->parent][] = $record->id;
                  if (!$record->visible) {
                      $all[$record->parent. 'i'][] = $record->id;
                  }
              } else {
                  // Parent not found. This is data consistency error but next fix_course_sortorder() should fix it.
                  $all[0][] = $record->id;
                  if (!$record->visible) {
                      $all['0i'][] = $record->id;
                  }
              }
              $count++;
          }
          $rs->close();
          if (!$count) {
              // No categories found.
              // This may happen after upgrade of a very old moodle version.
              // In new versions the default category is created on install.
              $defcoursecat = self::create(array('name' => get_string('miscellaneous')));
              set_config('defaultrequestcategory', $defcoursecat->id);
              $all[0] = array($defcoursecat->id);
              $all[$defcoursecat->id] = array();
              $count++;
          }
          // We must add countall to all in case it was the requested ID.
          $all['countall'] = $count;
          $coursecattreecache->set_many($all);
          if (array_key_exists($id, $all)) {
              return $all[$id];
          }
          // Requested non-existing category.
          return array();
      }
code: protected static function get_tree($id) {
          global $DB;
          $coursecattreecache = cache::make('core', 'coursecattree');
          $rv = $coursecattreecache->get($id);
          if ($rv !== false) {
              return $rv;
          }
          // Re-build the tree.
          $sql = "SELECT cc.id, cc.parent, cc.visible
                  FROM {course_categories} cc
                  ORDER BY cc.sortorder";
          $rs = $DB->get_recordset_sql($sql, array());
          $all = array(0 => array(), '0i' => array());
          $count = 0;
          foreach ($rs as $record) {
              $all[$record->id] = array();
              $all[$record->id. 'i'] = array();
              if (array_key_exists($record->parent, $all)) {
                  $all[$record->parent][] = $record->id;
                  if (!$record->visible) {
                      $all[$record->parent. 'i'][] = $record->id;
                  }
              } else {
                  // Parent not found. This is data consistency error but next fix_course_sortorder() should fix it.
                  $all[0][] = $record->id;
                  if (!$record->visible) {
                      $all['0i'][] = $record->id;
                  }
              }
              $count++;
          }
          $rs->close();
          if (!$count) {
              // No categories found.
              // This may happen after upgrade of a very old moodle version.
              // In new versions the default category is created on install.
              $defcoursecat = self::create(array('name' => get_string('miscellaneous')));
              set_config('defaultrequestcategory', $defcoursecat->id);
              $all[0] = array($defcoursecat->id);
              $all[$defcoursecat->id] = array();
              $count++;
          }
          // We must add countall to all in case it was the requested ID.
          $all['countall'] = $count;
          $coursecattreecache->set_many($all);
          if (array_key_exists($id, $all)) {
              return $all[$id];
          }
          // Requested non-existing category.
          return array();
      }
code_tokens: protected static function get_tree ( $ id ) { global $ DB ; $ coursecattreecache = cache :: make ( 'core' , 'coursecattree' ) ; $ rv = $ coursecattreecache -> get ( $ id ) ; if ( $ rv !== false ) { return $ rv ; } // Re-build the tree. $ sql = "SELECT cc.id, cc.parent, cc.visible
                  FROM {course_categories} cc
                  ORDER BY cc.sortorder" ; $ rs = $ DB -> get_recordset_sql ( $ sql , array ( ) ) ; $ all = array ( 0 => array ( ) , '0i' => array ( ) ) ; $ count = 0 ; foreach ( $ rs as $ record ) { $ all [ $ record -> id ] = array ( ) ; $ all [ $ record -> id . 'i' ] = array ( ) ; if ( array_key_exists ( $ record -> parent , $ all ) ) { $ all [ $ record -> parent ] [ ] = $ record -> id ; if ( ! $ record -> visible ) { $ all [ $ record -> parent . 'i' ] [ ] = $ record -> id ; } } else { // Parent not found. This is data consistency error but next fix_course_sortorder() should fix it. $ all [ 0 ] [ ] = $ record -> id ; if ( ! $ record -> visible ) { $ all [ '0i' ] [ ] = $ record -> id ; } } $ count ++ ; } $ rs -> close ( ) ; if ( ! $ count ) { // No categories found. // This may happen after upgrade of a very old moodle version. // In new versions the default category is created on install. $ defcoursecat = self :: create ( array ( 'name' => get_string ( 'miscellaneous' ) ) ) ; set_config ( 'defaultrequestcategory' , $ defcoursecat -> id ) ; $ all [ 0 ] = array ( $ defcoursecat -> id ) ; $ all [ $ defcoursecat -> id ] = array ( ) ; $ count ++ ; } // We must add countall to all in case it was the requested ID. $ all [ 'countall' ] = $ count ; $ coursecattreecache -> set_many ( $ all ) ; if ( array_key_exists ( $ id , $ all ) ) { return $ all [ $ id ] ; } // Requested non-existing category. return array ( ) ; }
docstring: Returns the entry from categories tree and makes sure the application-level tree cache is built
  
  The following keys can be requested:
  
  'countall' - total number of categories in the system (always present)
  0 - array of ids of top-level categories (always present)
  '0i' - array of ids of top-level categories that have visible=0 (always present but may be empty array)
  $id (int) - array of ids of categories that are direct children of category with id $id. If
  category with id $id does not exist returns false. If category has no children returns empty array
  $id.'i' - array of ids of children categories that have visible=0
  
  @param int|string $id
  @return mixed
docstring_tokens: Returns the entry from categories tree and makes sure the application - level tree cache is built