private function _getAllTableNames() {
$command = $this->_conn->createCommand("Show Tables");
$dataReader = $command->query();
$dataReader->bindColumn(1, $table);
$tables = array();
while ($dataReader->read()) {
$tables[] = $table;
}
return $tables;
}
private function _getProperClassName($tableName) {
$table_name_words = str_replace("_", " ", strtolower($tableName));
$final_conversion = str_replace(" ", "", ucwords($table_name_words));
return $this->_clas_prefix . $final_conversion;
}
public function renderAllTablesInformation() {
foreach ($this->_getAllTableNames() as $table_name) {
echo $table_name . "
";
$tableInfo = $this->_gateway->getTableInfo($this->_conn, $table_name);
echo "Table info:" . "
";
echo "";
var_dump($tableInfo);
echo "
";
}
}
//-----------------------------------------------------------------------------
protected function generateProperty($field, $column) {
$prop = '';
$name = '$' . $field;
/* TODO use in version 2.0 */
// $type = $column->getPHPType();
$prop .= "\tpublic $name;";
return $prop;
}
private function _renderRelations($tablename) {
if (!isset($this->_relations[$tablename])) {
return "";
}
$code = "\tpublic static \$RELATIONS = array (";
foreach ($this->_relations[$tablename] as $rel_data) {
$code .= "\n\t\t'" . $rel_data["prop_name"] . "' => array(" . $rel_data["rel_type"] . ", '" . $rel_data["ref_class_name"] . "', '" . $rel_data["prop_ref"] . "'),";
}
$code = substr($code, 0, -1);
$code .= "\n\t);";
return $code;
}
private function _buildSmartToString($tableInfo) {
$code = "\tpublic function __toString() {";
$property = "throw new THttpException(500, 'Not implemented yet.');";
try {
foreach ($tableInfo->getColumns() as $column) {
if (isset($column->IsPrimaryKey) && $column->IsPrimaryKey) {
$property = str_replace(array("`", "'", '"'), "", $column->ColumnName);
} elseif ($column->DbType == "varchar") {
$property = str_replace(array("`", "'", '"'), "", $column->ColumnName);
break;
}
}
} catch (Exception $ex) {
}
$code .= "\n\t\treturn \$this->$property;";
$code .= "\n\t}";
return $code;
}
protected function generateClass($properties, $tablename, $classname, $toString) {
$props = implode("\n", $properties);
$relations = $this->_renderRelations($tablename);
$date = date('Y-m-d h:i:s');
return <<
EOD;
}
//
}
?>