diff options
author | Daniel <darthdaniel85@gmail.com> | 2014-10-22 18:03:30 -0500 |
---|---|---|
committer | Daniel <darthdaniel85@gmail.com> | 2014-10-22 18:03:30 -0500 |
commit | bd341e6469cbd49a35711b732386dc56a3c59ed0 (patch) | |
tree | 470dd452d5539e70c7d118587fd4b7701881097c /framework/Wsat/TWsatARGenerator.php | |
parent | 0cc7b59c95cb3bf5103450cf858f71fdb150458b (diff) |
Scaffolding 5%
Diffstat (limited to 'framework/Wsat/TWsatARGenerator.php')
-rw-r--r-- | framework/Wsat/TWsatARGenerator.php | 85 |
1 files changed, 21 insertions, 64 deletions
diff --git a/framework/Wsat/TWsatARGenerator.php b/framework/Wsat/TWsatARGenerator.php index c6cef1d5..b05a6d96 100644 --- a/framework/Wsat/TWsatARGenerator.php +++ b/framework/Wsat/TWsatARGenerator.php @@ -9,24 +9,12 @@ * @since 3.3 * @package Wsat */ +Prado::using("System.Wsat.TWsatBaseGenerator"); -Prado::using('System.Data.Common.TDbMetaData'); - -class TWsatARGenerator +class TWsatARGenerator extends TWsatBaseGenerator { /** - * @return TDbMetaData for retrieving metadata information, such as - * table and columns information, from a database connection. - */ - private $_dbMetaData; - - /** - * Output folder where AR classes will be saved. - */ - private $_opFile; - - /** * Class name prefix */ private $_clasPrefix; @@ -49,22 +37,7 @@ class TWsatARGenerator function __construct() { - if(!class_exists("TActiveRecordManager", false)) - throw new Exception("You need to enable the ActiveRecord module in your application configuration file."); - $ar_manager = TActiveRecordManager::getInstance(); - $_conn = $ar_manager->getDbConnection(); - $_conn->Active = true; - $this->_dbMetaData = TDbMetaData::getInstance($_conn); - } - - public function setOpFile($op_file_namespace) - { - $op_file = Prado::getPathOfNamespace($op_file_namespace); - if (empty($op_file)) - throw new Exception("You need to fix your output folder namespace."); - if (!is_dir($op_file)) - mkdir($op_file, 0777, true); - $this->_opFile = $op_file; + parent::__construct(); } public function setClasPrefix($_clas_prefix) @@ -87,10 +60,8 @@ class TWsatARGenerator public function generateAll() { - foreach ($this->_dbMetaData->findTableNames() as $tableName) + foreach ($this->getAllTableNames() as $tableName) { - if ($tableName == "pradocache") - continue; $tableInfo = $this->_dbMetaData->getTableInfo($tableName); if (!empty($this->_relations)) { @@ -105,7 +76,7 @@ class TWsatARGenerator public function buildRelations() { $this->_relations = array(); - foreach ($this->_dbMetaData->findTableNames() as $table_name) + foreach ($this->getAllTableNames() as $table_name) { $tableInfo = $this->_dbMetaData->getTableInfo($table_name); $pks = $tableInfo->getPrimaryKeys(); @@ -117,17 +88,17 @@ class TWsatARGenerator $table_name_mm2 = $fks[1]["table"]; $this->_relations[$table_name_mm][] = array( - "prop_name" => strtolower($table_name_mm2), - "rel_type" => "self::MANY_TO_MANY", - "ref_class_name" => $this->_getProperClassName($table_name_mm2), - "prop_ref" => $table_name + "prop_name" => strtolower($table_name_mm2), + "rel_type" => "self::MANY_TO_MANY", + "ref_class_name" => $this->_getProperClassName($table_name_mm2), + "prop_ref" => $table_name ); $this->_relations[$table_name_mm2][] = array( - "prop_name" => strtolower($table_name_mm), - "rel_type" => "self::MANY_TO_MANY", - "ref_class_name" => $this->_getProperClassName($table_name_mm), - "prop_ref" => $table_name + "prop_name" => strtolower($table_name_mm), + "rel_type" => "self::MANY_TO_MANY", + "ref_class_name" => $this->_getProperClassName($table_name_mm), + "prop_ref" => $table_name ); continue; } @@ -138,17 +109,17 @@ class TWsatARGenerator $fk_prop = key($fk_data["keys"]); $this->_relations[$owner_table][] = array( - "prop_name" => strtolower($slave_table), - "rel_type" => "self::HAS_MANY", - "ref_class_name" => $this->_getProperClassName($slave_table), - "prop_ref" => $fk_prop + "prop_name" => strtolower($slave_table), + "rel_type" => "self::HAS_MANY", + "ref_class_name" => $this->_getProperClassName($slave_table), + "prop_ref" => $fk_prop ); $this->_relations[$slave_table][] = array( - "prop_name" => strtolower($owner_table), - "rel_type" => "self::BELONGS_TO", - "ref_class_name" => $this->_getProperClassName($owner_table), - "prop_ref" => $fk_prop + "prop_name" => strtolower($owner_table), + "rel_type" => "self::BELONGS_TO", + "ref_class_name" => $this->_getProperClassName($owner_table), + "prop_ref" => $fk_prop ); } } @@ -183,20 +154,6 @@ class TWsatARGenerator return $this->_clasPrefix . $final_conversion . $this->_classSufix; } - public function renderAllTablesInformation() - { - foreach ($this->_dbMetaData->findTableNames() as $table_name) - { - echo $table_name . "<br>"; - - $tableInfo = $this->_dbMetaData->getTableInfo($table_name); - echo "Table info:" . "<br>"; - echo "<pre>"; - var_dump($tableInfo); - echo "</pre>"; - } - } - //----------------------------------------------------------------------------- protected function generateProperty($field, $column) |