X-Git-Url: https://git.llucax.com/mecon/meconlib.git/blobdiff_plain/fcfef745c429ee47bc1cd691b8d67166e4f645e4..47fcd9f1dbb0357868cb194eb9f3a65bbffbc489:/lib/MECON/HTML/Arbol/ArbolDB.php?ds=sidebyside diff --git a/lib/MECON/HTML/Arbol/ArbolDB.php b/lib/MECON/HTML/Arbol/ArbolDB.php index 09f53be..78dfd5f 100644 --- a/lib/MECON/HTML/Arbol/ArbolDB.php +++ b/lib/MECON/HTML/Arbol/ArbolDB.php @@ -1,67 +1,109 @@ - + Leandro Lucarella +------------------------------------------------------------------------------- +$Id$ +-----------------------------------------------------------------------------*/ +require_once 'MECON/HTML/Arbol.php'; +require_once 'DB.php'; class HTML_ArbolDB extends HTML_Arbol { - function ArbolDB() + var $padre = ''; + var $tabla; + var $nombre; + var $id; + var $id_activo; + var $link = ''; + var $link_append = ''; + var $where = ''; + var $order = ''; + var $db; + + function HTML_ArbolDB($dbdata, $titulo, $link_append = '') + { + if(isset($dbdata['id_padre'])) + $this->padre = $dbdata['id_padre']; + $this->tabla = $dbdata['tabla']; + $this->nombre = $dbdata['nombre']; + $this->id = $dbdata['id']; + $this->id_activo = @$dbdata['id_activo']; + // FIXME - Deprecated! + if(isset($dbdata['prepend_link'])) + $link_append = $dbdata['prepend_link']; + if(isset($dbdata['link'])) + $this->link = $dbdata['link']; + if(isset($dbdata['where'])) + $this->where = $dbdata['where']; + if(isset($dbdata['order'])) + $this->order = ' ORDER BY '.$dbdata['nombre'].' '.$dbdata['order']; + $this->db = $dbdata['db']; + parent::HTML_Arbol(array(), $titulo, $link_append); + $this->datos = $this->BuscarHijos(0); + } + + function BuscarHijos($id) { - $dat = array( - array( - 'titulo' => 'Nivel0a', - 'link' => 'blabla', - 'sub' => array(//sub0 - array( - 'titulo' => 'Nivel1a', - 'link' => 'blabla', - 'sub' => array(//sub1 - array( - 'titulo' => 'Nivel3a', - 'link' => 'blabla', - 'activado' => 1 - ), - array( - 'titulo' => 'Nivel3b', - 'link' => 'blabla', - 'sub' => array(//sub2 - array( - 'titulo' => 'Nivel4', - 'link' => 'blabla' - ) - )//sub2 - ), - array( - 'titulo' => 'Nivel3c', - 'link' => 'blabla' - ) - )//sub1 - ), - array( - 'titulo' => 'Nivel1b', - 'link' => 'blabla', - 'activado' => 1 - ), - array( - 'titulo' => 'Nivel1c', - 'link' => 'blabla' - ) - )//sub0 - ), - array( - 'titulo' => 'Nivel0b', - 'link' => 'blabla' - ), - array( - 'titulo' => 'Nivel0c', - 'link' => 'blabla' - ) - ); + $sql = "SELECT $this->nombre, $this->id "; + if($this->link) + $sql .= ", $this->link "; + $sql .= "FROM $this->tabla "; + if($this->padre or $this->where) + $sql .= 'WHERE '; + if($this->padre) { + $sql .= "$this->padre = '$id'"; + if ($this->where) + $sql .= ' AND'; + } elseif ($this->where) + $sql .= $this->where; + $sql .= $this->order; + $result = $this->db->query($sql); + if(DB::isError($result)) + die($result->getMessage()); + $dat = array(); + while($row = $result->fetchRow()) + { + $titulo = $row[0]; + $id = $row[1]; + if(!$this->padre) $sub = array(); + else $sub = $this->BuscarHijos($id); + $link = strval(@$row[2]); + $d = array( + 'titulo'=> $titulo, + 'link' => $link, + 'id' => $id, + 'sub' => $sub + ); + if (!is_null($this->id_activo) and $id == $this->id_activo) { + $d['activo'] = 1; + } + $dat[] = $d; + } + return $dat; - parent::Arbol($dat); } -} +} ?>