Re: Help with references? again

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



OK, THIS one doesn't throw a syntax error ;)
class dir {

  var $name;
  var $subdirs;
  var $files;
  var $num;
  var $prio;

  function dir($name,$num,$prio) {
    $this->name = $name;
    $this->num = $num;
    $this->prio = $prio;
    $this->files = array();
    $this->subdirs = array();
  }

  function addFile($file) {
    $this->files[] =& $file;
    return $file;
  }

  function addDir($dir) {
    $this->subdirs[] =& $dir;
    return $dir;
  }

  function findDir($name) {
      foreach($this->subdirs as $v){
        if($v->name == $name)
          return $v;
      }
      return false;
  }

  function draw($parent) {


echo('d.add('.$this->num.','.$parent.',"'.$this->name."\",".$this->prio.");\n");

  foreach($this->subdirs as $v) {
      $v->draw($this->num);
}

  foreach($this->files as $v)
      if(is_object($v)) {
        echo("d.add(".$v->num.",".$this->num.",
\"".$v->name."\",".$v->prio.");\n");
      }
  }
}


class file {

  var $name;
  var $prio;
  var $size;
  var $num;

  function file($name,$num,$size,$prio) {
    $this->name = $name;
    $this->num = $num;
    $this->size = $size;
    $this->prio = $prio;

  }

}
$arFiles = array
  (
  0 => array
    (
    'path' => array
      (
      0 => 'folder1',
      1 => 'subfolder1',
      2 => 'file1.ext'
      ),
    'length' => 5464,
    'size' => 8765
),
  1 => array
    (
    'path' => array
      (
      0 => 'folder2/',
      1 => 'subfolder2/',
      2 => 'file2.ext'
      ),
    'length' => 5464,
    'size' => 8765
    ),
  2 => array
    (
    'path' => array
      (
      0 => 'folder3/',
      1 => 'subfolder3/',
      2 => 'file3.ext'
      ),
    'length' => 5464,
    'size' => 8765
    )
  );
$prio = array();
      for($i=0;$i<count($arFiles);$i++)
         $prio[$i] = -1;

 $dirnum = count($arFiles);
 $tree = new dir("/",$dirnum,isset($prio[$dirnum])?$prio[$dirnum]:-1);

 foreach( $arFiles as $filenum => $file) {
      $depth = count($file['path']);
      $branch =& $tree;
      for($i=0; $i < $depth; $i++){
        if ($i != $depth-1){
          $d =& $branch->findDir($file['path'][$i]);
          if($d)
 $branch =& $d;
          else{
            $dirnum++;
            $d =& $branch->addDir(new dir($file['path'][$i], $dirnum,
(isset($prio[$dirnum])?$prio[$dirnum]:-1)));
            $branch =& $d;
          }
        }else
          $branch->addFile(new
file($file['path'][$i]." (".$file['length'].")",$filenum,$file['size'],
$prio[$filenum]));
      }
    }
$tree->draw(-1);




On Sat, 2005-01-29 at 04:20 +0100, Jochem Maas wrote:
> Jon wrote:
> > This script only outputs the top level. i.e.
> > 
> 
> that script has syntax errors. ...
> 
> $arFiles = array(
>    array['file1'](
>      array(
>        ['path] => array(
>          [0] => 'folder1',
>          [1] => 'subfolder1'
>          [2] => 'file1.ext'
>      ),
>      ['length'] => 5464,
>      ['size'] => 8765
>    ),
>    array['file2'](
>      array(
>        ['path] => array(
>          [0] => 'folder2',
>          [1] => 'subfolder2'
>          [2] => 'file2.ext'
>      ),
>      ['length'] => 5464,
>      ['size'] => 8765
>    ),
>    array['file3'](
>      array(
>        ['path] => array(
>          [0] => 'folder3',
>          [1] => 'subfolder3'
>          [2] => 'file3.ext'
>      ),
>      ['length'] => 5464,
>      ['size'] => 8765
>    )
> )
> 

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux