looking for wrong seperator
[Pman.Core] / DatabaseColumns.php
1 <?php
2
3 require_once 'Pman.php';
4
5 class Pman_Core_DatabaseColumns extends Pman {
6     
7     
8     function getAuth()
9     {
10         parent::getAuth(); // load company!
11         $au = $this->getAuthUser();
12        
13         if (!$au) {  
14             $this->jerr("Not authenticated", array('authFailure' => true));
15         }
16         if (!$au->pid()   ) { // not set up yet..
17             $this->jerr("Not authenticated", array('authFailure' => true));
18         }
19         
20         
21         $this->authUser = $au;
22         return true;
23     }
24     
25     function get($table, $opts = Array()) {
26         $d = DB_DAtaObject::Factory($table);
27         if (method_exists($d, 'availableColumns')) {
28             $cols = $d->availableColumns();
29         } else {
30             
31             $re = $d->autoJoin();
32             //echo '<PRE>';print_r($re);
33             $cols = $re['cols'] ;
34             
35             
36             $types = array();
37             $tables = array();
38             $schemas = array($table => $d->table());
39             
40             foreach($cols as $name=>$table_col) {
41                 list($tbl, $col) = explode('.', $table_col);
42                 if (!isset($schemas[$tbl])) {
43                     $schemas[$tbl] = DB_DataObject::Factory($tbl)->table();
44                 }
45                 $types[$name] = $schemas[$tbl][$col];
46                 $tables[$name] = $tbl;
47             }
48              
49             foreach($re['join_names'] as $c=>$f) {
50                 $cols[$c] = $f;
51             }
52             
53         }
54         
55         
56         
57         foreach($cols as $c=>$f) {
58             $ret[]  = array(
59                 'name' => $c,
60                 'val' => $f,
61                 'type' => isset($types[$c]) ? $this->typeToName($types[$c]) : -1,
62                 'table' => isset($tables[$c]) ? $tables[$c] : "",
63             );
64             
65         }
66         
67         $this->jdata($ret);
68     }
69     
70     function typeToName($t)
71     {
72         switch(true) {
73             case ($t & 64): return 'text';
74             case ($t & 32): return 'text';
75             case ($t & 4 && $t & 8): return 'datetime';
76             case ($t & 4): return 'date';
77             case ($t & 8): return 'time';
78             case ($t & 16): return 'bool';
79             case ($t & 2): return 'varchar';
80             case ($t & 1): return 'number';
81                 
82         }
83         return '??';
84         
85     }
86 }