original_string: public function get_area_tree($contextid, $component, $filearea, $itemid) {
          $result = array('dirname'=>'', 'dirfile'=>null, 'subdirs'=>array(), 'files'=>array());
          $files = $this->get_area_files($contextid, $component, $filearea, $itemid, '', true);
          // first create directory structure
          foreach ($files as $hash=>$dir) {
              if (!$dir->is_directory()) {
                  continue;
              }
              unset($files[$hash]);
              if ($dir->get_filepath() === '/') {
                  $result['dirfile'] = $dir;
                  continue;
              }
              $parts = explode('/', trim($dir->get_filepath(),'/'));
              $pointer =& $result;
              foreach ($parts as $part) {
                  if ($part === '') {
                      continue;
                  }
                  if (!isset($pointer['subdirs'][$part])) {
                      $pointer['subdirs'][$part] = array('dirname'=>$part, 'dirfile'=>null, 'subdirs'=>array(), 'files'=>array());
                  }
                  $pointer =& $pointer['subdirs'][$part];
              }
              $pointer['dirfile'] = $dir;
              unset($pointer);
          }
          foreach ($files as $hash=>$file) {
              $parts = explode('/', trim($file->get_filepath(),'/'));
              $pointer =& $result;
              foreach ($parts as $part) {
                  if ($part === '') {
                      continue;
                  }
                  $pointer =& $pointer['subdirs'][$part];
              }
              $pointer['files'][$file->get_filename()] = $file;
              unset($pointer);
          }
          $result = $this->sort_area_tree($result);
          return $result;
      }
code: public function get_area_tree($contextid, $component, $filearea, $itemid) {
          $result = array('dirname'=>'', 'dirfile'=>null, 'subdirs'=>array(), 'files'=>array());
          $files = $this->get_area_files($contextid, $component, $filearea, $itemid, '', true);
          // first create directory structure
          foreach ($files as $hash=>$dir) {
              if (!$dir->is_directory()) {
                  continue;
              }
              unset($files[$hash]);
              if ($dir->get_filepath() === '/') {
                  $result['dirfile'] = $dir;
                  continue;
              }
              $parts = explode('/', trim($dir->get_filepath(),'/'));
              $pointer =& $result;
              foreach ($parts as $part) {
                  if ($part === '') {
                      continue;
                  }
                  if (!isset($pointer['subdirs'][$part])) {
                      $pointer['subdirs'][$part] = array('dirname'=>$part, 'dirfile'=>null, 'subdirs'=>array(), 'files'=>array());
                  }
                  $pointer =& $pointer['subdirs'][$part];
              }
              $pointer['dirfile'] = $dir;
              unset($pointer);
          }
          foreach ($files as $hash=>$file) {
              $parts = explode('/', trim($file->get_filepath(),'/'));
              $pointer =& $result;
              foreach ($parts as $part) {
                  if ($part === '') {
                      continue;
                  }
                  $pointer =& $pointer['subdirs'][$part];
              }
              $pointer['files'][$file->get_filename()] = $file;
              unset($pointer);
          }
          $result = $this->sort_area_tree($result);
          return $result;
      }
code_tokens: public function get_area_tree ( $ contextid , $ component , $ filearea , $ itemid ) { $ result = array ( 'dirname' => '' , 'dirfile' => null , 'subdirs' => array ( ) , 'files' => array ( ) ) ; $ files = $ this -> get_area_files ( $ contextid , $ component , $ filearea , $ itemid , '' , true ) ; // first create directory structure foreach ( $ files as $ hash => $ dir ) { if ( ! $ dir -> is_directory ( ) ) { continue ; } unset ( $ files [ $ hash ] ) ; if ( $ dir -> get_filepath ( ) === '/' ) { $ result [ 'dirfile' ] = $ dir ; continue ; } $ parts = explode ( '/' , trim ( $ dir -> get_filepath ( ) , '/' ) ) ; $ pointer = & $ result ; foreach ( $ parts as $ part ) { if ( $ part === '' ) { continue ; } if ( ! isset ( $ pointer [ 'subdirs' ] [ $ part ] ) ) { $ pointer [ 'subdirs' ] [ $ part ] = array ( 'dirname' => $ part , 'dirfile' => null , 'subdirs' => array ( ) , 'files' => array ( ) ) ; } $ pointer = & $ pointer [ 'subdirs' ] [ $ part ] ; } $ pointer [ 'dirfile' ] = $ dir ; unset ( $ pointer ) ; } foreach ( $ files as $ hash => $ file ) { $ parts = explode ( '/' , trim ( $ file -> get_filepath ( ) , '/' ) ) ; $ pointer = & $ result ; foreach ( $ parts as $ part ) { if ( $ part === '' ) { continue ; } $ pointer = & $ pointer [ 'subdirs' ] [ $ part ] ; } $ pointer [ 'files' ] [ $ file -> get_filename ( ) ] = $ file ; unset ( $ pointer ) ; } $ result = $ this -> sort_area_tree ( $ result ) ; return $ result ; }
docstring: Returns array based tree structure of area files
  
  @param int $contextid context ID
  @param string $component component
  @param string $filearea file area
  @param int $itemid item ID
  @return array each dir represented by dirname, subdirs, files and dirfile array elements
docstring_tokens: Returns array based tree structure of area files