]> git.nbdom.net Git - nb.git/commitdiff
Virtual
authorNicolas Boisselier <nicolas.boisselier@semantico.com>
Mon, 4 Jul 2016 16:30:57 +0000 (17:30 +0100)
committerNicolas Boisselier <nicolas.boisselier@semantico.com>
Mon, 4 Jul 2016 16:30:57 +0000 (17:30 +0100)
etc/dbs/ui.php
lib/php/db.php
lib/php/db/table.php

index d7a3216181a58d6d994093a166d69d9b98bab0f7..1a07cbf0cf18212ddbb937d6be01654ff2d5c5f2 100644 (file)
@@ -41,7 +41,7 @@ $CONF['_ui'] = array(
 
     'contact' => array(
       'extras'=> array(
-      ' pic' => '\'<img alt="" src="/scripts/gravatar/?email=\' || contact.email || \'" />\'',
+      'pic' => '\'<img alt="" src="/scripts/gravatar/?email=\' || contact.email || \'" />\'',
       ),
     ),
 
index ce3753d16ed60da60df797a389ac036e791b1e7f..1141d74684d69338b807b5ee50571e04c0a85fbb 100644 (file)
@@ -68,10 +68,28 @@ class Db extends nb {
 
     # Tables - Add missing infos
     if (!empty($tables)) {
+
       foreach ($this->tables() as $name=>$t) {
+      #foreach (array_merge(array_keys($this->tables()),[]) as $name) {
+      #foreach (array_merge(array_keys($this->tables()),array_keys($tables)) as $name) {
+
         if (empty($tables[$name])) continue;
         $this->table($name,$tables[$name]);
+
+      }
+
+      # Virtual - NB 04.07.16
+      foreach ($tables as $name => $t) {
+        if (empty($t['sql'])) continue;
+        $sql = $t['sql'];
+        unset($t['sql']);
+        #debug($name);
+        $t = $this->table($name,$t);
+        $t->sql = $sql;
+        $t->type = 'sql';
+        $this->tables[] = $t;
       }
+
     }
 
     # Extras should disapear - NB 29.03.16
@@ -271,14 +289,12 @@ class Db extends nb {
   }
 
   function table($name,$opt=array()) {
-# NB 29.03.16     if (empty($opt['db'])) $opt['db'] = $this;
     if ($this->tables() and array_key_exists($name,$this->tables)) {
       #if ($opt) bye($opt);
       if ($opt) $this->tables[$name]->__construct($name,$opt);
       return $this->tables[$name];
     }
     return new Table($name,$opt);
-    bye("Unknow table `$name`");
   }
 
   public function localFile() {
@@ -324,13 +340,21 @@ class Db extends nb {
     return $DB_TYPES[$type][$key];
   }
 
+# NB 04.07.16   public function all_tables() {
+# NB 04.07.16     $tables= $this->tables();
+# NB 04.07.16     return $tables;
+# NB 04.07.16   }
+
   public function tables() {
-    if (isset($this->tables)) return $this->tables;
-    $this->tables = array();
 
-    foreach ($this->conn->query($this->type('tables',true,$this->type),PDO::FETCH_ASSOC) as $row) {
-      $name = current($row);
-      $this->tables[$name] = $this->table($name,$row);
+    if (!isset($this->tables)) {
+      $this->tables = array();
+
+      foreach ($this->conn->query($this->type('tables',true,$this->type),PDO::FETCH_ASSOC) as $row) {
+        $name = current($row);
+        $this->tables[$name] = $this->table($name,$row);
+      }
+
     }
 
     return $this->tables;
index 72aab783b72323e8942cf8a0178de4289f3b608e..31e2fbc043dba75abb12cea24f01732f60468b2e 100644 (file)
@@ -244,6 +244,7 @@ Class Table extends nb {
    */
   public function fields($name=null) {
 
+    if (!empty($this->sql)) return []; # Virtual - NB 04.07.16
     if (!isset($this->fields)) {
 
       $this->fields = array();