_ar_manager = TActiveRecordManager::getInstance(); $this->_opnamespace = $_opnamespace; } // public function generate($tableName, $clasName = '') { $conn = $this->_ar_manager->getDbConnection(); $gateway = $this->_ar_manager->getRecordGateway(); $tableInfo = $gateway->getTableInfo($conn, $tableName); if (count($tableInfo->getColumns()) === 0) { throw new TIOException("Unable to find table or view $tableName in " . $conn->getConnectionString() . "."); } else { $properties = array(); foreach ($tableInfo->getColumns() as $field => $column) $properties[] = $this->generateProperty($field, $column); } $clasName = empty($clasName) ? $this->_getClassName($tableName) : $clasName; $class = $this->generateClass($properties, $tableName, $clasName); $op_file = Prado::getPathOfNamespace($this->_opnamespace); if (!is_dir($op_file)) { mkdir($op_file, 0777, true); } $output = $op_file . DIRECTORY_SEPARATOR . $clasName . ".php"; file_put_contents($output, $class); } public function generateAll() { foreach ($this->_getAllTableNames() as $tableName) { $this->generate($tableName); } } // //----------------------------------------------------------------------------- // private function getDbConnection() { $con = $this->_ar_manager->getDbConnection(); $con->Active = true; return $con; } private function _getAllTableNames() { $con = $this->getDbConnection(); $command = $con->createCommand("Show Tables"); $dataReader = $command->query(); $dataReader->bindColumn(1, $table); $tables = array(); while ($dataReader->read()) { $tables[] = $table; } $con->setActive(false); return $tables; } private function _getClassName($tableName) { return ucfirst($tableName); } public function renderAllTablesInformation() { $conn = $this->_ar_manager->getDbConnection(); $gateway = $this->_ar_manager->getRecordGateway(); foreach ($this->_getAllTableNames() as $table_name) { echo $table_name . "
"; $tableInfo = $gateway->getTableInfo($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; } protected function generateClass($properties, $tablename, $class) { $props = implode("\n", $properties); $date = date('Y-m-d h:i:s'); return << EOD; } //
} ?>