1: <?php
2:
3: class QTextBoxBase_CodeGenerator extends QControl_CodeGenerator {
4: public function __construct($strControlClassName = 'QTextBox') {
5: parent::__construct($strControlClassName);
6: }
7:
8: 9: 10: 11:
12: public function VarName($strPropName) {
13: return 'txt' . $strPropName;
14: }
15:
16: 17: 18: 19: 20: 21: 22: 23: 24: 25:
26: public function ConnectorCreate(QCodeGenBase $objCodeGen, QSqlTable $objTable, $objColumn) {
27: $strObjectName = $objCodeGen->ModelVariableName($objTable->Name);
28: $strClassName = $objTable->ClassName;
29: $strControlVarName = $objCodeGen->ModelConnectorVariableName($objColumn);
30: $strLabelName = addslashes(QCodeGen::ModelConnectorControlName($objColumn));
31:
32:
33: $strControlType = $objCodeGen->GetControlCodeGenerator($objColumn)->GetControlClass();
34:
35: $strRet = <<<TMPL
36: /**
37: * Create and setup a $strControlType $strControlVarName
38: * @param string \$strControlId optional ControlId to use
39: * @return $strControlType
40: */
41: public function {$strControlVarName}_Create(\$strControlId = null) {
42:
43: TMPL;
44: $strControlIdOverride = $objCodeGen->GenerateControlId($objTable, $objColumn);
45:
46: if ($strControlIdOverride) {
47: $strRet .= <<<TMPL
48: if (!\$strControlId) {
49: \$strControlId = '$strControlIdOverride';
50: }
51:
52: TMPL;
53: }
54: $strRet .= <<<TMPL
55: \$this->{$strControlVarName} = new $strControlType(\$this->objParentObject, \$strControlId);
56: \$this->{$strControlVarName}->Name = QApplication::Translate('$strLabelName');
57:
58: TMPL;
59:
60: if ($objColumn->NotNull) {
61: $strRet .= <<<TMPL
62: \$this->{$strControlVarName}->Required = true;
63:
64: TMPL;
65: }
66:
67: if ($objColumn->DbType == QDatabaseFieldType::Blob) {
68: $strRet .= <<<TMPL
69: \$this->{$strControlVarName}->TextMode = QTextMode::MultiLine;
70:
71: TMPL;
72: }
73:
74: if (($objColumn->VariableType == QType::String) && (is_numeric($objColumn->Length))) {
75: $strRet .= <<<TMPL
76: \$this->{$strControlVarName}->MaxLength = {$strClassName}::{$objColumn->PropertyName}MaxLength;
77:
78: TMPL;
79: }
80:
81: if ($strMethod = QCodeGen::$PreferredRenderMethod) {
82: $strRet .= <<<TMPL
83: \$this->{$strControlVarName}->PreferredRenderMethod = '$strMethod';
84:
85: TMPL;
86: }
87:
88: $strRet .= $this->ConnectorCreateOptions($objCodeGen, $objTable, $objColumn, $strControlVarName);
89: $strRet .= $this->ConnectorRefresh($objCodeGen, $objTable, $objColumn, true);
90:
91: $strRet .= <<<TMPL
92: return \$this->{$strControlVarName};
93: }
94:
95:
96: TMPL;
97:
98: return $strRet;
99: }
100:
101: 102: 103: 104: 105: 106: 107: 108: 109:
110: public function ConnectorRefresh(QCodeGenBase $objCodeGen, QSqlTable $objTable, $objColumn, $blnInit = false) {
111: $strObjectName = $objCodeGen->ModelVariableName($objTable->Name);
112: $strPropName = $objColumn->Reference ? $objColumn->Reference->PropertyName : $objColumn->PropertyName;
113: $strControlVarName = $this->VarName($strPropName);
114:
115: if ($blnInit) {
116: $strRet = "\t\t\t\$this->{$strControlVarName}->Text = \$this->{$strObjectName}->{$strPropName};";
117: } else {
118: $strRet = "\t\t\tif (\$this->{$strControlVarName}) \$this->{$strControlVarName}->Text = \$this->{$strObjectName}->{$strPropName};";
119: }
120: return $strRet . "\n";
121: }
122:
123: 124: 125: 126: 127: 128:
129: public function ConnectorUpdate(QCodeGenBase $objCodeGen, QSqlTable $objTable, $objColumn) {
130: $strObjectName = $objCodeGen->ModelVariableName($objTable->Name);
131: $strPropName = $objColumn->Reference ? $objColumn->Reference->PropertyName : $objColumn->PropertyName;
132: $strControlVarName = $this->VarName($strPropName);
133: $strRet = <<<TMPL
134: if (\$this->{$strControlVarName}) \$this->{$strObjectName}->{$strPropName} = \$this->{$strControlVarName}->Text;
135:
136: TMPL;
137: return $strRet;
138: }
139: }