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;
20 function get($tbl, $opts = array())
25 global $_DB_DATAOBJECT;
26 // DB_DataObject::debugLevel(1);
27 $tq = DB_DataObject::factory('Person');
30 $tables = $_DB_DATAOBJECT['INI'][$tq->_database];
32 if (!isset($_GET['table'])) {
34 $t = array_keys($tables);
37 // for postgres we can get descriptions - this should just fail in Mysql..
39 // DB_DataObjecT::DebugLevel(1);
40 $tq = DB_DataObject::factory('Person');
42 select relname, obj_description( oid) as desc FROM pg_catalog.pg_class");
43 while ($tq->fetch()) {
44 $desc[$tq->relname] = $tq->desc;
53 if (preg_match('/__keys$/', $k)) {
56 $do = DB_DataObject::factory($k);
57 if (!is_a($do,'DB_DataObject')) {
62 'desc' => isset($desc[$k]) ? $desc[$k] : ''
67 // this part is to find the table definition...
69 $do = DB_DataObject::factory($_GET['table']);
70 $links = $do->links();
73 // echo '<PRE>';print_R($links);
74 foreach($links as $k=>$v) {
75 $kv = explode(':', $v);
77 $dos[$k]= DB_DataObject::factory($kv[0]);
78 if (!is_a($dos[$k], 'DB_DataObject')) {
79 echo '<PRE>'; print_r($dos[$k]);
84 $desc = $this->createRet($do);
85 // echo '<PRE>';print_R($desc);
87 foreach($cols as $c => $ty) {
89 if (!isset($links[$c])) {
93 // we need to add dependant information to column details so
94 // that combo box can determine how to use it..
98 // colname_{remotename}_{col}
99 $kv = explode(':', $links[$c]);
100 //$ar = $this->createRet($dos[$c], $c . '_' . $kv[1] . '_');
101 $ar = $this->createRet($dos[$c], $c . '_' , $kv[1]);
102 $desc[$c]['maps_to'] = $kv[1];
103 $desc[$c]['deps'] = array_values($ar);
106 foreach($ar as $cn => $r) {
112 // echo '<PRE>';print_R($ret);
120 function createRet($do, $pref='', $skip = '')
122 static $desc = array();
123 static $types= array();
124 $tn = $do->tableName();
130 // get a description if available..
131 if (!isset($desc[$tn])) {
138 $desc[$tn] = array();
141 // DB_DataObject::DebugLevel(1);
143 c.column_name as name,
144 pgd.description as desc
145 FROM pg_catalog.pg_statio_all_tables as st
146 inner join pg_catalog.pg_description pgd on (pgd.objoid=st.relid)
147 inner join information_schema.columns c on (pgd.objsubid=c.ordinal_position and c.table_schema=st.schemaname and c.table_name=st.relname)
149 c.table_schema = 'public' and c.table_name = '{$tn}'
151 while($dd->fetch()) {
152 $desc[$tn][$dd->name] = $dd->desc;
155 $defs = $dd->getDatabaseConnection()->tableInfo($tn);
156 $types[$tn] = array();
157 foreach($defs as $c) {
158 $types[$tn][$c['name']] = $c['type'];
160 //echo '<PRE>';print_r($defs);
167 foreach($do->table() as $k=>$ty) {
173 'column' => $pref . $k,
175 'ctype' => $types[$tn][$k], // should always work!
176 'desc' => isset($cache[$tn][$k]) ? $cache[$tn][$k] : '',