SimpleExcel.php
[Pman.Core] / DatabaseColumns.php
index 9d805e4..fd674a3 100644 (file)
@@ -22,56 +22,65 @@ class Pman_Core_DatabaseColumns extends Pman {
         return true;
     }
     
-    function get($table) {
+    function get($table, $opts = Array()) {
         $d = DB_DAtaObject::Factory($table);
-        $re = $d->autoJoin();
-        //echo '<PRE>';print_r($re);
-        $ret = array ();
-        
-        foreach($re['join_names'] as $c=>$f) {
-            $re['cols'][$c] = $f;
+        if (method_exists($d, 'availableColumns')) {
+            $cols = $d->availableColumns();
+        } else {
+            
+            $re = $d->autoJoin();
+            //echo '<PRE>';print_r($re);
+            $cols = $re['cols'] ;
+            
+            
+            $types = array();
+            $tables = array();
+            $schemas = array($table => $d->table());
+            
+            foreach($cols as $name=>$table_col) {
+                list($tbl, $col) = explode('.', $table_col);
+                if (!isset($schemas[$tbl])) {
+                    $schemas[$tbl] = DB_DataObject::Factory($tbl)->table();
+                }
+                $types[$name] = $schemas[$tbl][$col];
+                $tables[$name] = $tbl;
+            }
+             
+            foreach($re['join_names'] as $c=>$f) {
+                $cols[$c] = $f;
+            }
+            
         }
         
         
-        foreach($re['cols'] as $c=>$f) {
+        
+        foreach($cols as $c=>$f) {
             $ret[]  = array(
                 'name' => $c,
-                'val' => $f
+                'val' => $f,
+                'type' => isset($types[$c]) ? $this->typeToName($types[$c]) : -1,
+                'table' => isset($tables[$c]) ? $tables[$c] : "",
             );
             
         }
         
-        
-        require_once 'Pman/Core/SimpleExcel.php';
-        $x = new Pman_Core_SimpleExcel(
-            array($bt,$et, $ut), array(
-            'formats' => array(
-                'vtop' => array('vAlign' => 'top'),
-                'vcenter' => array('vAlign' => 'vcenter'),
-                
-                'percent' => array('vAlign' => 'vcenter', 'numFormat' => '0%'),
-                'money' => array('vAlign' => 'vcenter', 'numFormat' => '$#,###'),
-                'date' => array('vAlign' => 'vcenter', 'numFormat' => 'd/M/Y'),
-            ),
-            'workbooks' => array(
-                array(
-                    'workbook' => 'Business',
-                    'cols' => explode('|', 'keyIdentity_taxId|description|type|countryIso3|countryRegion|addr1|addr2|addr3|city|zip')
-                ),
-                array(
-                    'workbook' => 'Employment',
-                    'cols' => explode('|', 'emailAddress|identity_taxId')
-                ),
-                array(
-                    'workbook' => 'Users',
-                    'cols' => explode('|', 'generateLogin|firstName|middleName|lastName|emailAddress|locale|countryIso3|countryRegion|addr1|addr2|addr3|city|zip|userStatus')
-                ),
-            )
-            
-        ));
-        $x->send('test_'. date('d_M_Y').'.xls');
         $this->jdata($ret);
-        
+    }
+    
+    function typeToName($t)
+    {
+        switch(true) {
+            case ($t & 64): return 'text';
+            case ($t & 32): return 'text';
+            case ($t & 4 && $t & 8): return 'datetime';
+            case ($t & 4): return 'date';
+            case ($t & 8): return 'time';
+            case ($t & 16): return 'bool';
+            case ($t & 2): return 'varchar';
+            case ($t & 1): return 'number';
+                
+        }
+        return '??';
         
     }
-}
\ No newline at end of file
+}