original_string: public function list_from_records($paged = false, $offset = 0) {
          $this->paged = $paged;
          $this->offset = $offset;
          $this->get_records();
          $records = $this->records;
          $page = $this->page;
          if (!empty($page)) {
              $this->firstitem = ($page - 1) * $this->itemsperpage;
              $this->lastitem = $this->firstitem + $this->itemsperpage - 1;
          }
          $itemiter = $offset;
          //make a simple array which is easier to search
          $this->childparent = array();
          foreach ($records as $record) {
              $this->childparent[$record->id] = $record->parent;
          }
  
          //create top level list items and they're responsible for creating their children
          foreach ($records as $record) {
              if (array_key_exists($record->parent, $this->childparent)) {
                  // This record is a child of another record, so it will be dealt
                  // with by a call to list_item::create_children, not here.
                  continue;
              }
  
              $inpage = $itemiter >= $this->firstitem && $itemiter <= $this->lastitem;
  
              // Make list item for top level for all items
              // we need the info about the top level items for reordering peers.
              if ($this->parentitem !== null) {
                  $newattributes = $this->parentitem->attributes;
              } else {
                  $newattributes = '';
              }
  
              $this->items[$itemiter] = new $this->listitemclassname($record, $this, $newattributes, $inpage);
  
              if ($inpage) {
                  $this->items[$itemiter]->create_children($records, $this->childparent, $record->id);
              } else {
                  // Don't recurse down the tree for items that are not on this page
                  $this->paged = true;
              }
  
              $itemiter++;
          }
          return array($this->paged, $itemiter);
      }
code: public function list_from_records($paged = false, $offset = 0) {
          $this->paged = $paged;
          $this->offset = $offset;
          $this->get_records();
          $records = $this->records;
          $page = $this->page;
          if (!empty($page)) {
              $this->firstitem = ($page - 1) * $this->itemsperpage;
              $this->lastitem = $this->firstitem + $this->itemsperpage - 1;
          }
          $itemiter = $offset;
          //make a simple array which is easier to search
          $this->childparent = array();
          foreach ($records as $record) {
              $this->childparent[$record->id] = $record->parent;
          }
  
          //create top level list items and they're responsible for creating their children
          foreach ($records as $record) {
              if (array_key_exists($record->parent, $this->childparent)) {
                  // This record is a child of another record, so it will be dealt
                  // with by a call to list_item::create_children, not here.
                  continue;
              }
  
              $inpage = $itemiter >= $this->firstitem && $itemiter <= $this->lastitem;
  
              // Make list item for top level for all items
              // we need the info about the top level items for reordering peers.
              if ($this->parentitem !== null) {
                  $newattributes = $this->parentitem->attributes;
              } else {
                  $newattributes = '';
              }
  
              $this->items[$itemiter] = new $this->listitemclassname($record, $this, $newattributes, $inpage);
  
              if ($inpage) {
                  $this->items[$itemiter]->create_children($records, $this->childparent, $record->id);
              } else {
                  // Don't recurse down the tree for items that are not on this page
                  $this->paged = true;
              }
  
              $itemiter++;
          }
          return array($this->paged, $itemiter);
      }
code_tokens: public function list_from_records ( $ paged = false , $ offset = 0 ) { $ this -> paged = $ paged ; $ this -> offset = $ offset ; $ this -> get_records ( ) ; $ records = $ this -> records ; $ page = $ this -> page ; if ( ! empty ( $ page ) ) { $ this -> firstitem = ( $ page - 1 ) * $ this -> itemsperpage ; $ this -> lastitem = $ this -> firstitem + $ this -> itemsperpage - 1 ; } $ itemiter = $ offset ; //make a simple array which is easier to search $ this -> childparent = array ( ) ; foreach ( $ records as $ record ) { $ this -> childparent [ $ record -> id ] = $ record -> parent ; } //create top level list items and they're responsible for creating their children foreach ( $ records as $ record ) { if ( array_key_exists ( $ record -> parent , $ this -> childparent ) ) { // This record is a child of another record, so it will be dealt // with by a call to list_item::create_children, not here. continue ; } $ inpage = $ itemiter >= $ this -> firstitem && $ itemiter <= $ this -> lastitem ; // Make list item for top level for all items // we need the info about the top level items for reordering peers. if ( $ this -> parentitem !== null ) { $ newattributes = $ this -> parentitem -> attributes ; } else { $ newattributes = '' ; } $ this -> items [ $ itemiter ] = new $ this -> listitemclassname ( $ record , $ this , $ newattributes , $ inpage ) ; if ( $ inpage ) { $ this -> items [ $ itemiter ] -> create_children ( $ records , $ this -> childparent , $ record -> id ) ; } else { // Don't recurse down the tree for items that are not on this page $ this -> paged = true ; } $ itemiter ++ ; } return array ( $ this -> paged , $ itemiter ) ; }
docstring: Produces a hierarchical tree of list items from a flat array of records.
  'parent' field is expected to point to a parent record.
  records are already sorted.
  If the parent field doesn't point to another record in the array then this is
  a top level list
  
  @param integer $offset how many list toplevel items are there in lists before this one
  @return array(boolean, integer) whether there is more than one page, $offset + how many toplevel items where there in this list.
docstring_tokens: Produces a hierarchical tree of list items from a flat array of records . parent field is expected to point to a parent record . records are already sorted . If the parent field doesn t point to another record in the array then this is a top level list