Niestety nie mam czasu narazie aby dostawic druga czesc arta bo goni mnie wszystko opocz biegunki

. Ale widze ze komus moze sie to przydac (i wszyscy wieszaja psy na klasie do rozwiniecia) wiec umieszczam wersje obslugujaca 99 cioro dzieci , a jesli ktos zechce to w piec minut przerobi ja na wersje z mozliwoscia dopisania 999 cioro dzieci do rodzica. Klasa nie wyglada jeszcze tak jakbym chcial ale mysle ze wybaczycie mi drobne niedociagniecia

. Jak tylko na uczelni zostawia mnie w spokoju to opisze klase , sprawie by jakos wygladala i dodam pare przydatnych metod.
<?php
class trees{
var $maxNest = 5; //liczone od zera()
var $table = \"groups\";
var $digitsPerSub = 2;
function trees(){
$this->db =& new db;
$this->levelNum = $this->maxNest*$this->digitsPerSub;
return true;
}
function newGroup( $name ){
return $this->db->execute(\"INSERT INTO \".$this->table.\" ( cluster, name, level, depth ) SELECT MAX(cluster)+1,'\".$name.\"', RPAD('0',\".$this->levelNum.\",'0'), 0 FROM \".$this->table.\" \");
}
function newChild( $name, $parentId ){
$parent = $this->db->getRow(\"select cluster, LEFT(level, depth*2) as cutLevel, depth FROM \".$this->table.\"
WHERE RIGHT(level,2) != '99' AND
id=\".$parentId);
if(!$parent){return false;}
return $this->db->execute(\" insert into \".$this->table.\" (cluster, name, level, depth ) select \".$parent['cluster'].\", '\".$name.\"', RPAD( CONCAT( '\".$parent['cutLevel'].\"' ,LPAD( SUBSTRING(g.level, (\".$parent['depth'].\"*2)+1, 2 ) + 1, 2, '0')), \". $this->levelNum .\", '0'),\".$parent['depth'].\"+1
FROM \".$this->table.\" AS g
LEFT
JOIN \".$this->table.\" AS p ON CONCAT(g.cluster,'|',RPAD( CONCAT( '\".$parent['cutLevel'].\"' ,LPAD( SUBSTRING(g.level, (\".$parent['depth'].\"*2)+1, 2 ) + 1, 2, '0')), \". $this->levelNum .\", '0')) = CONCAT(p.cluster,'|',p.level) where g.cluster = \".$parent['cluster'].\" and
g.level like CONCAT( '\".$parent['cutLevel'].\"','%') and
(\".$parent['depth'].\"*2) + 2 <= \".$this->levelNum.\" and
p.level is null
LIMIT 1\");
}
function delete( $id ){
$r = $this->db->getRow(\"SELECT cluster, LEFT(level, depth*2) as cutLevel,depth
FROM \".$this->table.\"
WHERE id=\".$id);
if(!$r){return false;}
return $this->db->execute(\"DELETE
FROM \".$this->table.\"
WHERE LEFT( level, \".$r['depth'].\"*2)='\".$r['cutLevel'].\"' AND
cluster =\".$r['cluster']);
}
function getAll( $cluster , $depth = null ){
$depth = (is_null($depth))?
$this->maxNest:$depth;
return $this->db->getArray(\"SELECT *, depth
FROM \".$this->table.\"
WHERE cluster = \".$cluster.\" AND
depth <= \".$depth.\"
ORDER BY level\");
}
function getPart( $parent_id, $depth = null ){
$depth = (is_null($depth))?
$this->maxNest:$depth;
$r = $this->db->getRow(\"SELECT cluster, LEFT(level, depth*2 ) as cutLevel, depth
FROM \".$this->table.\"
WHERE id=\".$parent_id
);
if(!$r){return false;}
return $this->db->getArray(\"
SELECT *, depth, depth - \".$r['depth'].\" as relativeDepth
FROM \".$this->table.\"
WHERE cluster = \".$r['cluster'].\" AND
LEFT (level, \".$r['depth'].\"*2) = '\".$r['cutLevel'].\"' AND
depth <= (\".$depth.\"+\".$r['depth'].\")
ORDER BY level\");
}
}
?>
i dodajcie kolumne depth (int) do poprzedniej tabeli