1: <?php
2:
3: class QLabelBase_CodeGenerator extends QControl_CodeGenerator {
4: private static $instance = null;
5:
6: public function __construct($strControlClassName = 'QLabel') {
7: parent::__construct($strControlClassName);
8: }
9:
10: 11: 12:
13: public static function Instance() {
14: if (!self::$instance) {
15: self::$instance = new QLabel_CodeGenerator();
16: }
17: return self::$instance;
18: }
19:
20: 21: 22: 23:
24: public function VarName($strPropName) {
25: return 'lbl' . $strPropName;
26: }
27:
28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38:
39: public function ConnectorCreate(QCodeGenBase $objCodeGen, QSqlTable $objTable, $objColumn) {
40: $strLabelName = addslashes(QCodeGen::ModelConnectorControlName($objColumn));
41: $strControlType = 'QLabel';
42:
43: $strPropName = QCodeGen::ModelConnectorPropertyName($objColumn);
44: $strControlVarName = $this->VarName($strPropName);
45:
46: $strDateTimeExtra = '';
47: $strDateTimeParamExtra = '';
48: if ($objColumn->VariableType == 'QDateTime') {
49: $strDateTimeExtra = ', $strDateTimeFormat = null';
50: $strDateTimeParamExtra = "\n\t\t * @param string \$strDateTimeFormat";
51: }
52:
53: $strRet = <<<TMPL
54: /**
55: * Create and setup $strControlType $strControlVarName
56: *
57: * @param string \$strControlId optional ControlId to use{$strDateTimeParamExtra}
58: * @return $strControlType
59: */
60: public function {$strControlVarName}_Create(\$strControlId = null{$strDateTimeExtra}) {
61:
62: TMPL;
63: $strControlIdOverride = $objCodeGen->GenerateControlId($objTable, $objColumn);
64:
65: if ($strControlIdOverride) {
66: $strRet .= <<<TMPL
67: if (!\$strControlId) {
68: \$strControlId = '$strControlIdOverride';
69: }
70:
71: TMPL;
72: }
73: $strRet .= <<<TMPL
74: \$this->{$strControlVarName} = new {$strControlType}(\$this->objParentObject, \$strControlId);
75: \$this->{$strControlVarName}->Name = QApplication::Translate('{$strLabelName}');
76:
77: TMPL;
78: if ($objColumn->VariableType == 'QDateTime') {
79: $strRet .= <<<TMPL
80: \$this->str{$strPropName}DateTimeFormat = \$strDateTimeFormat;
81:
82: TMPL;
83: }
84: if ($strMethod = QCodeGen::$PreferredRenderMethod) {
85: $strRet .= <<<TMPL
86: \$this->{$strControlVarName}->PreferredRenderMethod = '$strMethod';
87:
88: TMPL;
89: }
90:
91:
92: $strRet .= $this->ConnectorCreateOptions($objCodeGen, $objTable, $objColumn, $strControlVarName);
93:
94: $strRet .= $this->ConnectorRefresh($objCodeGen, $objTable, $objColumn, true);
95:
96: $strRet .= <<<TMPL
97: return \$this->{$strControlVarName};
98: }
99:
100:
101: TMPL;
102: return $strRet;
103: }
104:
105: 106: 107: 108: 109: 110:
111: public function ConnectorVariableDeclaration(QCodeGenBase $objCodeGen, $objColumn) {
112: $strPropName = $objCodeGen->ModelConnectorPropertyName($objColumn);
113: $strControlVarName = $this->VarName($strPropName);
114:
115: $strRet = <<<TMPL
116: /**
117: * @var QLabel {$strControlVarName}
118: * @access protected
119: */
120: protected \${$strControlVarName};
121:
122:
123: TMPL;
124:
125: if ($objColumn->VariableType == 'QDateTime') {
126: $strRet .= <<<TMPL
127: /**
128: * @var str{$strPropName}DateTimeFormat
129: * @access protected
130: */
131: protected \$str{$strPropName}DateTimeFormat;
132:
133: TMPL;
134: }
135: return $strRet;
136: }
137:
138: 139: 140: 141: 142: 143: 144: 145: 146: 147:
148: public function ConnectorRefresh(QCodeGenBase $objCodeGen, QSqlTable $objTable, $objColumn, $blnInit = false) {
149: $strObjectName = $objCodeGen->ModelVariableName($objTable->Name);
150: $strPropName = QCodeGen::ModelConnectorPropertyName($objColumn);
151: $strControlVarName = $this->VarName($strPropName);
152:
153:
154: $strRet = '';
155: if ($objColumn instanceof QSqlColumn) {
156: if ($objColumn->Identity ||
157: $objColumn->Timestamp
158: ) {
159: $strRet = "\$this->{$strControlVarName}->Text = \$this->blnEditMode ? \$this->{$strObjectName}->{$strPropName} : QApplication::Translate('N\\A');";
160: } else if ($objColumn->Reference) {
161: if ($objColumn->Reference->IsType) {
162: $strRet = "\$this->{$strControlVarName}->Text = \$this->{$strObjectName}->{$objColumn->PropertyName} ? {$objColumn->Reference->VariableType}::\$NameArray[\$this->{$strObjectName}->{$objColumn->PropertyName}] : null;";
163: } else {
164: $strRet = "\$this->{$strControlVarName}->Text = \$this->{$strObjectName}->{$strPropName} ? \$this->{$strObjectName}->{$strPropName}->__toString() : null;";
165: }
166: } else {
167: switch ($objColumn->VariableType) {
168: case "boolean":
169: $strRet = "\$this->{$strControlVarName}->Text = \$this->{$strObjectName}->{$strPropName} ? QApplication::Translate('Yes') : QApplication::Translate('No');";
170: break;
171:
172: case "QDateTime":
173: $strRet = "\$this->{$strControlVarName}->Text = \$this->{$strObjectName}->{$strPropName} ? \$this->{$strObjectName}->{$strPropName}->qFormat(\$this->str{$strPropName}DateTimeFormat) : null;";
174: break;
175:
176: default:
177: $strRet = "\$this->{$strControlVarName}->Text = \$this->{$strObjectName}->{$strPropName};";
178: }
179: }
180: } elseif ($objColumn instanceof QReverseReference) {
181: if ($objColumn->Unique) {
182: $strRet = "\$this->{$strControlVarName}->Text = \$this->{$strObjectName}->{$objColumn->ObjectPropertyName} ? \$this->{$strObjectName}->{$objColumn->ObjectPropertyName}->__toString() : null;";
183: }
184: } elseif ($objColumn instanceof QManyToManyReference) {
185: $strRet = "\$this->{$strControlVarName}->Text = implode(\$this->str{$objColumn->ObjectDescription}Glue, \$this->{$strObjectName}->Get{$objColumn->ObjectDescription}Array());";
186: } else {
187: throw new Exception ('Unknown column type.');
188: }
189:
190: if (!$blnInit) {
191: $strRet = "\t\t\tif (\$this->{$strControlVarName}) " . $strRet;
192: } else {
193: $strRet = "\t\t\t" . $strRet;
194: }
195:
196: return $strRet . "\n";
197: }
198:
199: 200: 201: 202: 203: 204:
205: public function ConnectorUpdate(QCodeGenBase $objCodeGen, QSqlTable $objTable, $objColumn) {
206: return '';
207: }
208: }