HTML/FlexyFramework/Generator.php
[pear] / HTML / FlexyFramework / Generator.php
1 <?php
2
3
4 require_once 'DB/DataObject/Generator.php';
5
6
7 class HTML_FlexyFramework_Generator extends DB_DataObject_Generator 
8 {
9     // block class generation.
10     var $generateClasses = false;
11     
12     function generateClasses()
13     {
14         if (!$this->generateClasses) {
15             return;
16         }
17         parent::generateClasses();
18     }
19     
20     
21     function generateReaders()
22     {
23         $options = &PEAR::getStaticProperty('DB_DataObject','options');
24         
25         $out = array();
26         foreach($this->tables as $this->table) {
27             $this->table        = trim($this->table);
28             
29             $out = array_merge($out, $this->_generateReader($this->table));
30             
31             
32         }
33         //echo '<PRE>';print_r($out);exit;
34          
35         file_put_contents($options["ini_{$this->_database}"] . '.reader', serialize($out));
36          
37     }
38     function _generateReader($table)
39     {
40         $DB = $this->getDatabaseConnection();
41         $dbtype = $DB->phptype;
42         $def = $this->_definitions[$table] ;
43         $ret = array();
44         foreach($def as $t) {
45              switch (strtoupper($t->type)) {
46
47                 case 'INT':
48                 case 'INT2':    // postgres
49                 case 'INT4':    // postgres
50                 case 'INT8':    // postgres
51                 case 'SERIAL4': // postgres
52                 case 'SERIAL8': // postgres
53                 case 'INTEGER':
54                 case 'TINYINT':
55                 case 'SMALLINT':
56                 case 'MEDIUMINT':
57                 case 'BIGINT':
58                 // wierd ones..
59                 case 'YEAR':
60                 
61                     $ret[$table.'.'.$t->name] = array('type' => 'int');
62                     continue;
63                
64                 case 'REAL':
65                 case 'DOUBLE':
66                 case 'DOUBLE PRECISION': // double precision (firebird)
67                 case 'FLOAT':
68                 case 'FLOAT4': // real (postgres)
69                 case 'FLOAT8': // double precision (postgres)
70                 case 'DECIMAL':
71                 case 'MONEY':  // mssql and maybe others
72                 case 'NUMERIC':
73                 case 'NUMBER': // oci8 
74                     $ret[$table.'.'.$t->name] = array('type' => 'float'); //???
75                     break;
76                     
77                 case 'BIT':
78                 case 'BOOL':   
79                 case 'BOOLEAN':   
80                     $ret[$table.'.'.$t->name] = array('type' => 'boolean'); //???
81                     // postgres needs to quote '0'
82                     if ($dbtype == 'pgsql') {
83                         ///$type +=  DB_DATAOBJECT_STR;
84                     }
85                     break;
86                     
87                 case 'STRING':
88                 case 'CHAR':
89                 case 'VARCHAR':
90                 case 'VARCHAR2':
91                 case 'TINYTEXT':
92                 
93                 case 'ENUM':
94                 case 'SET':         // not really but oh well
95                 
96                 case 'POINT':       // mysql geometry stuff - not really string - but will do..
97                 
98                 case 'TIMESTAMPTZ': // postgres
99                 case 'BPCHAR':      // postgres
100                 case 'INTERVAL':    // postgres (eg. '12 days')
101                 
102                 case 'CIDR':        // postgres IP net spec
103                 case 'INET':        // postgres IP
104                 case 'MACADDR':     // postgress network Mac address.
105                 
106                 case 'INTEGER[]':   // postgres type
107                 case 'BOOLEAN[]':   // postgres type
108                 
109                 
110                 case 'TEXT':
111                 case 'MEDIUMTEXT':
112                 case 'LONGTEXT':
113                 case 'BLOB':       /// these should really be ignored!!!???
114                 case 'TINYBLOB':
115                 case 'MEDIUMBLOB':
116                 case 'LONGBLOB':
117                 
118                 case 'CLOB': // oracle character lob support
119                 
120                 case 'BYTEA':   // postgres blob support..
121                     $ret[$table.'.'.$t->name] =  $t->name; // strings are not sent as arrays..
122                    // $type = DB_DATAOBJECT_STR;
123                     break;
124                 
125                 
126                 
127                 
128                 case 'DATE':    
129                     $ret[$table.'.'.$t->name] = array('type' => 'date', 'dateFormat' => 'Y-m-d'); //???
130                     break;
131                     
132                 case 'TIME':    
133                     $ret[$table.'.'.$t->name] = $t->name; // technically not...
134                     break;    
135                     
136                 
137                 case 'DATETIME': 
138                     $ret[$table.'.'.$t->name] = array('type' => 'date', 'dateFormat' => 'Y-m-d H:i:s'); //???
139                     break;    
140                     
141                 case 'TIMESTAMP': // do other databases use this???
142                     
143                     $ret[$table.'.'.$t->name] =   ($dbtype == 'mysql') ?
144                          array('type' => 'float') : 
145                         array('type' => 'date', 'dateFormat' => 'Y-m-d H:i:s');
146                     break;    
147                     
148                 
149                 
150                     
151                     
152                 default:     
153                     $ret[$table.'.'.$t->name] = $t->name;
154                     break;
155             }
156         }
157         
158         return $ret;
159         
160         
161     }
162 }