summaryrefslogtreecommitdiff
path: root/framework/Wsat/TWsatScaffoldingGenerator.php
diff options
context:
space:
mode:
Diffstat (limited to 'framework/Wsat/TWsatScaffoldingGenerator.php')
-rw-r--r--framework/Wsat/TWsatScaffoldingGenerator.php195
1 files changed, 111 insertions, 84 deletions
diff --git a/framework/Wsat/TWsatScaffoldingGenerator.php b/framework/Wsat/TWsatScaffoldingGenerator.php
index b1c54bc3..9e1e17ad 100644
--- a/framework/Wsat/TWsatScaffoldingGenerator.php
+++ b/framework/Wsat/TWsatScaffoldingGenerator.php
@@ -13,110 +13,139 @@ 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()
+ /**
+ * Const View Types for generation
+ */
+ const LIST_TYPE = 0;
+ const ADD_TYPE = 1;
+ const SHOW_TYPE = 2;
+
+ /**
+ * Bootstrap option
+ */
+ private $_bootstrap;
+
+ function __construct()
+ {
+ parent::__construct();
+ }
+
+ /**
+ * Generates CRUD Operations for a single DB table
+ * @param type $tableName
+ */
+ public function generateCRUD($tableName)
+ {
+ $this->generate($tableName, self::ADD_TYPE);
+ $this->generate($tableName, self::LIST_TYPE);
+ $this->generate($tableName, self::SHOW_TYPE);
+ }
+
+ //---------------------------------------------------------------------
+ // <editor-fold defaultstate="collapsed" desc="Page Generation">
+ public function generate($tableName, $viewType)
+ {
+ switch ($viewType)
{
- parent::__construct();
+ default:
+ case self::LIST_TYPE:
+ $unitName = "list" . ucfirst($tableName);
+ break;
+
+ case self::ADD_TYPE:
+ $unitName = "add" . ucfirst($tableName);
+ break;
+
+ case self::SHOW_TYPE:
+ $unitName = "show" . ucfirst($tableName);
+ break;
}
- public function generate()
- {
- $unitName = "Example";
- $class = $this->generateClass($unitName);
- $outputClass = $this->_opFile . DIRECTORY_SEPARATOR . $unitName . ".php";
- file_put_contents($outputClass, $class);
-
- $outputPage = $this->_opFile . DIRECTORY_SEPARATOR . $unitName . ".page";
- $page = $this->generatePage("student", self::ADD_TYPE);
- file_put_contents($outputPage, $page);
- }
+ $class = $this->generateClass($unitName);
+ $outputClass = $this->_opFile . DIRECTORY_SEPARATOR . $unitName . ".php";
+ file_put_contents($outputClass, $class);
- // <editor-fold defaultstate="collapsed" desc="Page Generation">
- private function generatePage($tableName, $type, $tContentId = "Content")
- {
- $pageContent = $this->getPageContent($tableName, $type);
- return <<<EOD
+ $outputPage = $this->_opFile . DIRECTORY_SEPARATOR . $unitName . ".page";
+ $page = $this->generatePage($tableName, $viewType);
+ file_put_contents($outputPage, $page);
+ }
+
+ private function generatePage($tableName, $type, $tContentId = "Content")
+ {
+ $pageContent = $this->getPageContent($tableName, $type);
+ return <<<EOD
<com:TContent ID="$tContentId">
$pageContent
</com:TContent>
EOD;
- }
+ }
- private function getPageContent($tableName, $type)
+ private function getPageContent($tableName, $type)
+ {
+ $code = "";
+ $tableInfo = $this->_dbMetaData->getTableInfo($tableName);
+ switch ($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)
{
- 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;
+ $colField = $this->eq($colMetadata["table"]);
+ $code .= "\t<com:TTextBox ID=$colField />\n";
+ $code .= "\n";
+ // TWsatBaseGenerator::pr($tableInfo);
}
- return $code;
+ $code .= "\t<com:TButton Text=\"Accept\" />\n";
+
+ case self::SHOW_TYPE:
+ break;
}
+ return $code;
+ }
- private function generateControl($colMetadata)
+ private function generateControl($colMetadata)
+ {
+ $controlType = "TTextBox";
+ switch ($colMetadata->DbType)
{
- $controlType = "TTextBox";
- switch ($colMetadata->DbType){
-
- }
- $controlId = $colMetadata->ColumnId;
- return "\t<com:$controlType ID=\"$controlId\" />\n";
+
}
-
- private function generateValidators($colMetadata)
+ $controlId = $colMetadata->ColumnId;
+ return "\t<com:$controlType ID=\"$controlId\" />\n";
+ }
+
+ private function generateValidators($colMetadata)
+ {
+ $controlId = $colMetadata->ColumnId;
+ $code = "";
+ if (!$colMetadata->AllowNull)
{
- $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;
+ $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');
- $env_user = getenv("username");
- return <<<EOD
+ //---------------------------------------------------------------------
+ // <editor-fold defaultstate="collapsed" desc="Code Behind Generation">
+ private function generateClass($classname)
+ {
+ $date = date('Y-m-d h:i:s');
+ $env_user = getenv("username");
+ return <<<EOD
<?php
/**
* Auto generated by PRADO - WSAT on $date.
@@ -127,9 +156,7 @@ class $classname extends TPage
}
EOD;
- }
+ }
// </editor-fold>
}
-
-?>