X-Git-Url: http://git.roojs.org/?p=Pman.Core;a=blobdiff_plain;f=DatabaseColumns.php;h=fd674a3082a9ec51abda4197ca25a4504c698110;hp=f2f4acfcce08a6009a7649e43ea88b3ad2f8f901;hb=refs%2Fheads%2Fwip_alan_T5884_add_photo_to_report;hpb=3a0c977f5eaa9f5ef33d95a04fc0b7c6d03b04a4 diff --git a/DatabaseColumns.php b/DatabaseColumns.php index f2f4acfc..fd674a30 100644 --- a/DatabaseColumns.php +++ b/DatabaseColumns.php @@ -22,25 +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 '
';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 '';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] : "", ); } + $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 +}