*/ include '../configuration.inc'; $zend_db = Database::getConnection(); foreach ($zend_db->listTables() as $tableName) { $fields = array(); $primary_keys = array(); foreach ($zend_db->describeTable($tableName) as $row) { $type = preg_replace("/[^a-z]/","",strtolower($row['DATA_TYPE'])); // Translate database datatypes into PHP datatypes if (preg_match('/int/',$type)) { $type = 'int'; } if (preg_match('/enum/',$type) || preg_match('/varchar/',$type)) { $type = 'string'; } $fields[] = array('field'=>$row['COLUMN_NAME'],'type'=>$type); if ($row['PRIMARY']) { $primary_keys[] = $row['COLUMN_NAME']; } } // Only generate code for tables that have a single-column primary key // Code for other tables will need to be created by hand if (count($primary_keys) != 1) { continue; } $key = $primary_keys[0]; $tableName = strtolower($tableName); $className = Inflector::classify($tableName); $variableName = Inflector::singularize($tableName); $acl_resource = ucfirst($tableName); /** * Generate the list block */ $getId = "get".ucwords($key); $HTML = "

Add \"; } ?> {$className}s

"; $contents = " $HTML"; $dir = APPLICATION_HOME."/scripts/stubs/blocks/$tableName"; if (!is_dir($dir)) { mkdir($dir,0770,true); } file_put_contents("$dir/{$variableName}List.inc",$contents); /** * Generate the addForm */ $HTML = "

Add $className

\">
$className Info "; foreach ($fields as $field) { if ($field['field'] != $key) { $fieldFunctionName = ucwords($field['field']); switch ($field['type']) { case 'date': $HTML.=" "; break; case 'datetime': case 'timestamp': $HTML.=" "; break; case 'text': $HTML.= " "; break; default: $HTML.= " "; } } } $HTML.= "
\" />
\" />
"; $contents = " $HTML"; file_put_contents("$dir/add{$className}Form.inc",$contents); /** * Generate the Update Form */ $HTML = "

Update $className

\">
$className Info {$variableName}->{$getId}(); ?>\" /> "; foreach ($fields as $field) { if ($field['field'] != $key) { $fieldFunctionName = ucwords($field['field']); switch ($field['type']) { case 'date': $HTML.=" "; break; case 'datetime': case 'timestamp': $HTML.=" "; break; case 'text': $HTML.= " "; break; default: $HTML.= " "; } } } $HTML.= "
\" />
\" />
{$variableName}->get$fieldFunctionName(); ?>\" />
"; $contents = " $HTML"; file_put_contents("$dir/update{$className}Form.inc",$contents); echo "$className\n"; }