php7 fixes
[Pman.Builder] / ERM.php
diff --git a/ERM.php b/ERM.php
index b5cff50..2f90bf6 100644 (file)
--- a/ERM.php
+++ b/ERM.php
@@ -17,7 +17,7 @@ class Pman_Builder_ERM extends Pman
         
        }
     
-    function get($tbl)
+    function get($tbl, $opts = array())
     {
         
         
@@ -53,6 +53,10 @@ class Pman_Builder_ERM extends Pman
                 if (preg_match('/__keys$/', $k)) {
                     continue;
                 }
+                $do = DB_DataObject::factory($k);
+                if (!is_a($do,'DB_DataObject')) {
+                    continue;
+                }
                 $ret[] = array(
                         'name' => $k,
                         'desc' => isset($desc[$k]) ? $desc[$k] : ''
@@ -81,20 +85,31 @@ class Pman_Builder_ERM extends Pman
        // echo '<PRE>';print_R($desc);
         $ret = array();
         foreach($cols as $c => $ty) {
-            $ret[] = $desc[$c];
-            if (!isset($links[$c])) {
+           
+            if (!isset($links[$c]))  {
+                 $ret[] = $desc[$c];
                 continue;
             }
+            // we need to add dependant information to column details so
+            // that combo box can determine how to use it..
+            
+            
+            
             // colname_{remotename}_{col}
             $kv = explode(':', $links[$c]);
-            $ar = $this->createRet($dos[$c], $c . '_' . $kv[1] . '_');
+            //$ar = $this->createRet($dos[$c], $c . '_' . $kv[1] . '_');
+            $ar = $this->createRet($dos[$c], $c . '_' , $kv[1]);
+            $desc[$c]['maps_to'] = $kv[1];
+            $desc[$c]['deps'] = array_values($ar);
+            
+            $ret[] = $desc[$c];
             foreach($ar as $cn => $r) {
                 $ret[] = $r;
             }
             
             
         }
-       // echo '<PRE>';print_R($ret);
+        // echo '<PRE>';print_R($ret);
         
         $this->jdata($ret); 
         
@@ -102,14 +117,24 @@ class Pman_Builder_ERM extends Pman
         
         
     }
-    function createRet($do, $pref='')
+    function createRet($do, $pref='', $skip = '')
     {
-        static  $cache = array();
+        static  $desc = array();
         static  $types= array();
         $tn = $do->tableName();
 
-        
+
+
+
+
+        // get a description if available..
         if (!isset($desc[$tn])) {
+            
+            
+            
+            
+            
+            
             $desc[$tn] = array();
             $dd = clone($do);
             
@@ -124,11 +149,15 @@ class Pman_Builder_ERM extends Pman
                     c.table_schema = 'public' and c.table_name = '{$tn}'
             ");
             while($dd->fetch()) {
-                $cache[$tn][$dd->name] = $dd->desc;
+                $desc[$tn][$dd->name] = $dd->desc;
             }
             
-            $defs =  $dd->databaseConnection()->tableInfo($quotedTable);
-            
+            $defs =  $dd->getDatabaseConnection()->tableInfo($tn);
+            $types[$tn] = array();
+            foreach($defs as $c) {
+                $types[$tn][$c['name']] = $c['type'];
+            }
+            //echo '<PRE>';print_r($defs);
             
         }
        
@@ -136,11 +165,14 @@ class Pman_Builder_ERM extends Pman
        
         $ret = array();
         foreach($do->table() as $k=>$ty) {
+            if ($k == $skip) {
+                continue;
+            }
             $ret[$k] = array(
                 'table' => $tn,
                 'column' => $pref . $k,
                 'columnshort' => $k,
-                'ctype' => $ty,
+                'ctype' => $types[$tn][$k], // should always work!
                 'desc' => isset($cache[$tn][$k]) ? $cache[$tn][$k] : '',
             );
         }