blob: b1c54bc3da62859fb68e3258ea68fa20befb0bbe (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
|
<?php
/**
* @author Daniel Sampedro Bello <darthdaniel85@gmail.com>
* @link http://www.pradosoft.com/
* @copyright Copyright © 2005-2014 PradoSoft
* @license http://www.pradosoft.com/license/
* @version $Id$
* @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()
{
parent::__construct();
}
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);
}
// <editor-fold defaultstate="collapsed" desc="Page Generation">
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)
{
$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');
$env_user = getenv("username");
return <<<EOD
<?php
/**
* Auto generated by PRADO - WSAT on $date.
* @author $env_user
*/
class $classname extends TPage
{
}
EOD;
}
// </editor-fold>
}
?>
|