From bd341e6469cbd49a35711b732386dc56a3c59ed0 Mon Sep 17 00:00:00 2001 From: Daniel Date: Wed, 22 Oct 2014 18:03:30 -0500 Subject: Scaffolding 5% --- framework/Wsat/TWsatARGenerator.php | 85 +++++++--------------------- framework/Wsat/TWsatBaseGenerator.php | 71 +++++++++++++++++++++++ framework/Wsat/TWsatScaffoldingGenerator.php | 13 ++++- framework/Wsat/pages/TWsatGenerateAR.page | 2 +- framework/Wsat/pages/TWsatGenerateAR.php | 2 +- framework/Wsat/pages/TWsatScaffolding.page | 11 +++- framework/Wsat/pages/TWsatScaffolding.php | 34 ++++++++++- framework/Wsat/themes/PradoSoft/main.css | 6 ++ 8 files changed, 153 insertions(+), 71 deletions(-) create mode 100644 framework/Wsat/TWsatBaseGenerator.php (limited to 'framework/Wsat') 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,23 +9,11 @@ * @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 */ @@ -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 . "
"; - - $tableInfo = $this->_dbMetaData->getTableInfo($table_name); - echo "Table info:" . "
"; - echo "
";
-                        var_dump($tableInfo);
-                        echo "
"; - } - } - //----------------------------------------------------------------------------- protected function generateProperty($field, $column) diff --git a/framework/Wsat/TWsatBaseGenerator.php b/framework/Wsat/TWsatBaseGenerator.php new file mode 100644 index 00000000..7f81f503 --- /dev/null +++ b/framework/Wsat/TWsatBaseGenerator.php @@ -0,0 +1,71 @@ + + * @link http://www.pradosoft.com/ + * @copyright Copyright © 2005-2014 PradoSoft + * @license http://www.pradosoft.com/license/ + * @version $Id$ + * @since 3.3 + * @package Wsat + */ +Prado::using('System.Data.Common.TDbMetaData'); + +class TWsatBaseGenerator +{ + + /** + * @return TDbMetaData for retrieving metadata information, such as + * table and columns information, from a database connection. + */ + protected $_dbMetaData; + + /** + * Output folder where AR classes will be saved. + */ + protected $_opFile; + + 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; + } + + public function renderAllTablesInformation() + { + foreach ($this->getAllTableNames() as $table_name) + { + echo $table_name . "
"; + $tableInfo = $this->_dbMetaData->getTableInfo($table_name); + echo "Table info:" . "
"; + echo "
";
+                        print_r($tableInfo);
+                        echo "
"; + } + } + + public function getAllTableNames() + { + $tableNames = $this->_dbMetaData->findTableNames(); + $index = array_search('pradocache', $tableNames); + array_splice($tableNames, $index, 1); + return $tableNames; + } + +} + +?> diff --git a/framework/Wsat/TWsatScaffoldingGenerator.php b/framework/Wsat/TWsatScaffoldingGenerator.php index 2c49d735..37b8ae00 100644 --- a/framework/Wsat/TWsatScaffoldingGenerator.php +++ b/framework/Wsat/TWsatScaffoldingGenerator.php @@ -9,10 +9,17 @@ * @since 3.3 * @package Wsat */ - -class TWsatScaffoldingGenerator + +Prado::using("System.Wsat.TWsatBaseGenerator"); + +class TWsatScaffoldingGenerator extends TWsatBaseGenerator { - //put your code here + + function __construct() + { + parent::__construct(); + } + } ?> diff --git a/framework/Wsat/pages/TWsatGenerateAR.page b/framework/Wsat/pages/TWsatGenerateAR.page index 926d6b0f..c41d03a5 100644 --- a/framework/Wsat/pages/TWsatGenerateAR.page +++ b/framework/Wsat/pages/TWsatGenerateAR.page @@ -1,5 +1,5 @@ -
Active Record Classes Generator
+
Active Record Classes Generator

diff --git a/framework/Wsat/pages/TWsatGenerateAR.php b/framework/Wsat/pages/TWsatGenerateAR.php index 4a3714de..2e7bab06 100644 --- a/framework/Wsat/pages/TWsatGenerateAR.php +++ b/framework/Wsat/pages/TWsatGenerateAR.php @@ -51,7 +51,7 @@ class TWsatGenerateAR extends TPage public function preview($sender) { -// throw new THttpException(500, "Not implemented yet."); + throw new THttpException(500, "Not implemented yet."); } } \ No newline at end of file diff --git a/framework/Wsat/pages/TWsatScaffolding.page b/framework/Wsat/pages/TWsatScaffolding.page index 42f78d09..bcf4d276 100644 --- a/framework/Wsat/pages/TWsatScaffolding.page +++ b/framework/Wsat/pages/TWsatScaffolding.page @@ -1,3 +1,12 @@ - Scaffolding will be avaliable in Prado 3.4 +
Scaffolding Generator
+ +
+ +
+ +
+ + +
diff --git a/framework/Wsat/pages/TWsatScaffolding.php b/framework/Wsat/pages/TWsatScaffolding.php index fe691dd9..7352b2ae 100644 --- a/framework/Wsat/pages/TWsatScaffolding.php +++ b/framework/Wsat/pages/TWsatScaffolding.php @@ -9,9 +9,41 @@ * @since 3.3 * @package Wsat.pages */ -Prado::using("System.Wsat.TWsatARGenerator"); +Prado::using("System.Wsat.TWsatScaffoldingGenerator"); class TWsatScaffolding extends TPage { + public function onInit($param) + { + parent::onInit($param); + if (!$this->IsPostBack) + { + $this->startVisual(); + } + } + + private function startVisual() + { + $scf_generator = new TWsatScaffoldingGenerator(); + foreach ($scf_generator->getAllTableNames() as $tableName) + { + $dynChb = new TCheckBox(); + $dynChb->ID = $tableName; + $dynChb->Text = ucfirst($tableName); + $dynChb->Checked = true; + $this->tableNames->getControls()->add($dynChb); + + } + } + + public function generate($sender) + { + if ($this->IsValid) + { + $scf_generator = new TWsatScaffoldingGenerator(); + $scf_generator->renderAllTablesInformation(); + } + } + } \ No newline at end of file diff --git a/framework/Wsat/themes/PradoSoft/main.css b/framework/Wsat/themes/PradoSoft/main.css index 9970c88b..d525f96a 100644 --- a/framework/Wsat/themes/PradoSoft/main.css +++ b/framework/Wsat/themes/PradoSoft/main.css @@ -149,4 +149,10 @@ html, body{ text-align:center; margin-top:25px; padding:10px; +} + +.section_title { + margin: 10px; + font-size: 16px; + font-weight: bold } \ No newline at end of file -- cgit v1.2.3