From 71f87188baad50c0adc56f8cae627869b4f5c30a Mon Sep 17 00:00:00 2001 From: Daniel Date: Fri, 24 Oct 2014 18:07:23 -0500 Subject: Scaffolding 15% --- framework/Wsat/TWsatARGenerator.php | 6 +- framework/Wsat/TWsatBaseGenerator.php | 7 +++ framework/Wsat/TWsatScaffoldingGenerator.php | 83 ++++++++++++++++++++++++++-- 3 files changed, 87 insertions(+), 9 deletions(-) diff --git a/framework/Wsat/TWsatARGenerator.php b/framework/Wsat/TWsatARGenerator.php index b05a6d96..da004b1f 100644 --- a/framework/Wsat/TWsatARGenerator.php +++ b/framework/Wsat/TWsatARGenerator.php @@ -136,8 +136,8 @@ class TWsatARGenerator extends TWsatBaseGenerator else { $properties = array(); - foreach ($tableInfo->getColumns() as $field => $column) - $properties[] = $this->generateProperty($field, $column); + foreach ($tableInfo->getColumns() as $field => $metadata) + $properties[] = $this->generateProperty($field, $metadata); $toString = $this->_buildSmartToString($tableInfo); } @@ -156,7 +156,7 @@ class TWsatARGenerator extends TWsatBaseGenerator //----------------------------------------------------------------------------- - protected function generateProperty($field, $column) + protected function generateProperty($field, $metadata) { $prop = ''; $name = '$' . $field; diff --git a/framework/Wsat/TWsatBaseGenerator.php b/framework/Wsat/TWsatBaseGenerator.php index 7f81f503..4898e635 100644 --- a/framework/Wsat/TWsatBaseGenerator.php +++ b/framework/Wsat/TWsatBaseGenerator.php @@ -66,6 +66,13 @@ class TWsatBaseGenerator return $tableNames; } + public static function pr($data) + { + echo "
";
+                print_r($data);
+                echo "
"; + } + } ?> diff --git a/framework/Wsat/TWsatScaffoldingGenerator.php b/framework/Wsat/TWsatScaffoldingGenerator.php index 7986793d..b1c54bc3 100644 --- a/framework/Wsat/TWsatScaffoldingGenerator.php +++ b/framework/Wsat/TWsatScaffoldingGenerator.php @@ -6,13 +6,25 @@ * @copyright Copyright © 2005-2014 PradoSoft * @license http://www.pradosoft.com/license/ * @version $Id$ - * @since 3.3 + * @since 4.0 * @package Wsat */ Prado::using("System.Wsat.TWsatBaseGenerator"); class TWsatScaffoldingGenerator extends TWsatBaseGenerator { + /** + * Const View Types for generation + */ + + const LIST_TYPE = 0; + const ADD_TYPE = 1; + const SHOW_TYPE = 2; + + /** + * Bootstrap option + */ + private $_bootstrap; function __construct() { @@ -27,20 +39,79 @@ class TWsatScaffoldingGenerator extends TWsatBaseGenerator file_put_contents($outputClass, $class); $outputPage = $this->_opFile . DIRECTORY_SEPARATOR . $unitName . ".page"; - $page = $this->generatePage($unitName); + $page = $this->generatePage("student", self::ADD_TYPE); file_put_contents($outputPage, $page); } - // - private function generatePage($fileName, $tContentId = "Content") + // + private function generatePage($tableName, $type, $tContentId = "Content") { + $pageContent = $this->getPageContent($tableName, $type); return << - + + + $pageContent + EOD; } + private function getPageContent($tableName, $type) + { + $code = ""; + $tableInfo = $this->_dbMetaData->getTableInfo($tableName); + switch ($type) + { + case self::LIST_TYPE: + break; + case self::ADD_TYPE: + foreach ($tableInfo->getColumns() as $colField => $colMetadata) + { + if (!$colMetadata->IsPrimaryKey && !$colMetadata->IsForeignKey) + { + $code .= $this->generateControl($colMetadata); + $code .= $this->generateValidators($colMetadata); + $code .= "\n"; + } + } + foreach ($tableInfo->getForeignKeys() as $colField => $colMetadata) + { + $colField = '"' . $colMetadata["table"] . '"'; + $code .= "\t\n"; + $code .= "\n"; + // TWsatBaseGenerator::pr($tableInfo); + } + + case self::SHOW_TYPE: + break; + } + return $code; + } + + private function generateControl($colMetadata) + { + $controlType = "TTextBox"; + switch ($colMetadata->DbType){ + + } + $controlId = $colMetadata->ColumnId; + return "\t\n"; + } + + private function generateValidators($colMetadata) + { + $controlId = $colMetadata->ColumnId; + $code = ""; + if (!$colMetadata->AllowNull) + { + $code .= "\t\n"; + } + return $code; + } + +// + //--------------------------------------------------------------------- + // private function generateClass($classname) { $date = date('Y-m-d h:i:s'); -- cgit v1.2.3