X-Git-Url: https://git.llucax.com/mecon/meconlib.git/blobdiff_plain/46e7344057aaab2b08a90cbcba5bd1ab109a2e09..ae92414569165d0e2c3e0c6f141be8aac51cb3db:/lib/MECON/HTML/Arbol/ArbolDB.php diff --git a/lib/MECON/HTML/Arbol/ArbolDB.php b/lib/MECON/HTML/Arbol/ArbolDB.php index d83d506..0594bcb 100644 --- a/lib/MECON/HTML/Arbol/ArbolDB.php +++ b/lib/MECON/HTML/Arbol/ArbolDB.php @@ -11,7 +11,10 @@ class HTML_ArbolDB extends HTML_Arbol var $tabla; var $nombre; var $id; - var $link; + var $link = null; + var $prepend_link = null; + var $where = ''; + var $order = ''; var $db; function HTML_ArbolDB($dbdata, $imagen) @@ -21,7 +24,14 @@ class HTML_ArbolDB extends HTML_Arbol $this->tabla = $dbdata['tabla']; $this->nombre = $dbdata['nombre']; $this->id = $dbdata['id']; - $this->link = $dbdata['link']; + if(isset($dbdata['prepend_link'])) + $this->prepend_link = $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']; $dat = $this->BuscarHijos(0); parent::HTML_Arbol($dat, $imagen); @@ -29,22 +39,35 @@ class HTML_ArbolDB extends HTML_Arbol function BuscarHijos($id) { - $sql = "SELECT $this->nombre, $this->id - FROM $this->tabla "; - if(!is_null$this->padre) - $sql .= "WHERE $this->padre = '$id'"; + $sql = "SELECT $this->nombre, $this->id "; + if(!is_null($this->link)) + $sql .= ", $this->link "; + $sql .= "FROM $this->tabla "; + if(!is_null($this->padre) or $this->where) + $sql .= 'WHERE '; + if(!is_null($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(); + $dat = array(); while($row = $result->fetchRow()) { $titulo = $row[0]; $id = $row[1]; + if(is_null($this->padre)) $sub = array(); + else $sub = $this->BuscarHijos($id); + if(!is_null($this->link)) $link = $this->prepend_link.$row[2]; + else $link = $this->prepend_link.$id; $dat[] = array( 'titulo'=> $titulo, - 'link' => $this->link.$id, - 'sub' => $this->BuscarHijos($id) + 'link' => $link, + 'sub' => $sub ); } return $dat;