Readers.php
[Pman.Builder] / FormToSQL.php
index bf72ae5..a0d451a 100644 (file)
@@ -14,7 +14,7 @@ class Pman_Builder_FormToSQL extends Pman {
         return true;
     }
     
-    function get()
+    function get($base, $opts = array())
     {
         //print_R($_SERVER['argv']);exit;
         $file  = $_SERVER['argv'][2];
@@ -29,9 +29,24 @@ class Pman_Builder_FormToSQL extends Pman {
         array_pop($b);
         $tn = strtolower(preg_replace('/([A-Z])/','_$1', array_pop($b)));
         $tn = preg_replace('/^_+/', '', $tn);
+        if (!empty($_SERVER['argv'][3])) {
+            $tn= $_SERVER['argv'][3];
+        }
+        
+        
         $this->toSQL($tn);
         $b= basename(dirname($file));
-        $this->toDO($b, $tn);
+        
+        $do = $this->toDO($b, $tn);
+        
+        $dofile = dirname($file).'/DataObjects/'. ucfirst($tn).'.php';
+        if (!file_exists($dofile)) {
+            echo "WRITING  $dofile\n";
+            file_put_contents($dofile, $do);
+        } else {
+            // should support AUTOCODE...
+            echo "DELETE $dofile IF YOU WANT TO RECREATED IT..\n";
+        }
         
         die("DONE");
     }
@@ -218,7 +233,7 @@ class Pman_Builder_FormToSQL extends Pman {
 require_once \'DB/DataObject.php\';
 
 ';
-        $out.="class Pman_$b_DataObjects_$utn extends DB_DataObject 
+        $out.="class Pman_{$b}_DataObjects_$utn extends DB_DataObject 
 {
     ###START_AUTOCODE
     /* the code below is auto generated do not remove the above tag */
@@ -226,7 +241,7 @@ require_once \'DB/DataObject.php\';
     public \$__table = '$tn';                         // table name
 ";
         foreach($this->cols as $f) {
-            $out .= '    public $' . str_pad($f->name,30 ). '// ' . $f->def;
+            $out .= '    public $' . str_pad($f->name.';',30 ). '// ' . $f->def . "\n";
                 
        }
        $out.="
@@ -236,7 +251,9 @@ require_once \'DB/DataObject.php\';
         
         
 }";
-    
+        echo "\n\n";
         echo $out;
+         echo "\n\n";
+         return $out;
     }
 }
\ No newline at end of file