3 require_once 'Pman.php';
6 class Pman_Builder_ERM extends Pman
10 parent::getAuth(); // load company!
11 $au = $this->getAuthUser();
13 $this->jerr("Not authenticated", array('authFailure' => true));
15 $this->authUser = $au;
25 global $_DB_DATAOBJECT;
26 // DB_DataObject::debugLevel(1);
27 $tq = DB_DataObject::factory('Person');
31 $tables = $_DB_DATAOBJECT['INI'][$tq->_database];
32 print_r($_DB_DATAOBJECT);exit;
33 if (!isset($_GET['table'])) {
35 $t = array_keys($tables);
38 // for postgres we can get descriptions - this should just fail in Mysql..
40 // DB_DataObjecT::DebugLevel(1);
41 $tq = DB_DataObject::factory('Person');
43 select relname, obj_description( oid) as desc FROM pg_catalog.pg_class");
44 while ($tq->fetch()) {
45 $desc[$tq->relname] = $tq->desc;
54 if (preg_match('/__keys$/', $k)) {
57 $do = DB_DataObject::factory($k);
58 if (!is_a($do,'DB_DataObject')) {
63 'desc' => isset($desc[$k]) ? $desc[$k] : ''
68 // this part is to find the table definition...
70 $do = DB_DataObject::factory($_GET['table']);
71 $links = $do->links();
74 // echo '<PRE>';print_R($links);
75 foreach($links as $k=>$v) {
76 $kv = explode(':', $v);
78 $dos[$k]= DB_DataObject::factory($kv[0]);
79 if (!is_a($dos[$k], 'DB_DataObject')) {
80 echo '<PRE>'; print_r($dos[$k]);
85 $desc = $this->createRet($do);
86 // echo '<PRE>';print_R($desc);
88 foreach($cols as $c => $ty) {
90 if (!isset($links[$c])) {
94 // we need to add dependant information to column details so
95 // that combo box can determine how to use it..
99 // colname_{remotename}_{col}
100 $kv = explode(':', $links[$c]);
101 //$ar = $this->createRet($dos[$c], $c . '_' . $kv[1] . '_');
102 $ar = $this->createRet($dos[$c], $c . '_' , $kv[1]);
103 $desc[$c]['maps_to'] = $kv[1];
104 $desc[$c]['deps'] = array_values($ar);
107 foreach($ar as $cn => $r) {
113 // echo '<PRE>';print_R($ret);
121 function createRet($do, $pref='', $skip = '')
123 static $desc = array();
124 static $types= array();
125 $tn = $do->tableName();
131 // get a description if available..
132 if (!isset($desc[$tn])) {
139 $desc[$tn] = array();
142 // DB_DataObject::DebugLevel(1);
144 c.column_name as name,
145 pgd.description as desc
146 FROM pg_catalog.pg_statio_all_tables as st
147 inner join pg_catalog.pg_description pgd on (pgd.objoid=st.relid)
148 inner join information_schema.columns c on (pgd.objsubid=c.ordinal_position and c.table_schema=st.schemaname and c.table_name=st.relname)
150 c.table_schema = 'public' and c.table_name = '{$tn}'
152 while($dd->fetch()) {
153 $desc[$tn][$dd->name] = $dd->desc;
156 $defs = $dd->getDatabaseConnection()->tableInfo($tn);
157 $types[$tn] = array();
158 foreach($defs as $c) {
159 $types[$tn][$c['name']] = $c['type'];
161 //echo '<PRE>';print_r($defs);
168 foreach($do->table() as $k=>$ty) {
174 'column' => $pref . $k,
176 'ctype' => $types[$tn][$k], // should always work!
177 'desc' => isset($cache[$tn][$k]) ? $cache[$tn][$k] : '',