diff options
Diffstat (limited to 'framework')
-rw-r--r-- | framework/Wsat/TWsatARGenerator.php | 6 | ||||
-rw-r--r-- | framework/Wsat/TWsatBaseGenerator.php | 7 | ||||
-rw-r--r-- | 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 "<pre>"; + print_r($data); + echo "</pre>"; + } + } ?> 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); } - // <editor-fold defaultstate="collapsed" desc="Generate Sigle Page"> - private function generatePage($fileName, $tContentId = "Content") + // <editor-fold defaultstate="collapsed" desc="Page Generation"> + private function generatePage($tableName, $type, $tContentId = "Content") { + $pageContent = $this->getPageContent($tableName, $type); return <<<EOD -<com:TContent ID="Content"> - +<com:TContent ID="$tContentId"> + + $pageContent + </com:TContent> 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<com:TTextBox ID=$colField />\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<com:$controlType ID=\"$controlId\" />\n"; + } + + private function generateValidators($colMetadata) + { + $controlId = $colMetadata->ColumnId; + $code = ""; + if (!$colMetadata->AllowNull) + { + $code .= "\t<com:TRequiredFieldValidator ControlToValidate=$controlId ValidationGroup=\"addGroup\" Text=\"Field $controlId is required.\" Display=\"Dynamic\" />\n"; + } + return $code; + } + +// </editor-fold> + //--------------------------------------------------------------------- + // <editor-fold defaultstate="collapsed" desc="Code Behind Generation"> private function generateClass($classname) { $date = date('Y-m-d h:i:s'); |