1: <?php
2:
3: class QDateTimePickerBase_CodeGenerator extends QControl_CodeGenerator {
4: public function __construct($strControlClassName = 'QDateTimePicker') {
5: parent::__construct($strControlClassName);
6: }
7:
8: 9: 10: 11:
12: public function VarName($strPropName) {
13: return 'cal' . $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: $strControlVarName = $objCodeGen->ModelConnectorVariableName($objColumn);
29: $strLabelName = addslashes(QCodeGen::ModelConnectorControlName($objColumn));
30:
31:
32: $strControlType = $objCodeGen->GetControlCodeGenerator($objColumn)->GetControlClass();
33:
34: $strRet = <<<TMPL
35: /**
36: * Create and setup a $strControlType $strControlVarName
37: * @param string \$strControlId optional ControlId to use
38: * @return $strControlType
39: */
40: public function {$strControlVarName}_Create(\$strControlId = null) {
41:
42: TMPL;
43: $strControlIdOverride = $objCodeGen->GenerateControlId($objTable, $objColumn);
44:
45: if ($strControlIdOverride) {
46: $strRet .= <<<TMPL
47: if (!\$strControlId) {
48: \$strControlId = '$strControlIdOverride';
49: }
50:
51: TMPL;
52: }
53: $strRet .= <<<TMPL
54: \$this->{$strControlVarName} = new $strControlType(\$this->objParentObject, \$strControlId);
55: \$this->{$strControlVarName}->Name = QApplication::Translate('$strLabelName');
56: \$this->{$strControlVarName}->DateTime = \$this->{$strObjectName}->{$objColumn->PropertyName};
57:
58: TMPL;
59: switch ($objColumn->DbType) {
60: case QDatabaseFieldType::DateTime:
61: $strRet .= "\t\t\t\$this->{$strControlVarName}->DateTimePickerType = QDateTimePickerType::DateTime;\n";
62: break;
63:
64: case QDatabaseFieldType::Time:
65: $strRet .= "\t\t\t\$this->{$strControlVarName}->DateTimePickerType = QDateTimePickerType::Time;\n";
66: break;
67:
68: default:
69: $strRet .= "\t\t\t\$this->{$strControlVarName}->DateTimePickerType = QDateTimePickerType::Date;\n";
70: }
71:
72: if ($strMethod = QCodeGen::$PreferredRenderMethod) {
73: $strRet .= <<<TMPL
74: \$this->{$strControlVarName}->PreferredRenderMethod = '$strMethod';
75:
76: TMPL;
77: }
78:
79: $strRet .= $this->ConnectorCreateOptions($objCodeGen, $objTable, $objColumn, $strControlVarName);
80:
81: $strRet .= <<<TMPL
82: return \$this->{$strControlVarName};
83: }
84:
85:
86: TMPL;
87:
88: return $strRet;
89: }
90:
91: 92: 93: 94: 95: 96: 97: 98: 99:
100: public function ConnectorRefresh(QCodeGenBase $objCodeGen, QSqlTable $objTable, $objColumn, $blnInit = false) {
101: $strObjectName = $objCodeGen->ModelVariableName($objTable->Name);
102: $strPropName = $objColumn->Reference ? $objColumn->Reference->PropertyName : $objColumn->PropertyName;
103: $strControlVarName = $this->VarName($strPropName);
104:
105: if ($blnInit) {
106: $strRet = "\t\t\t\$this->{$strControlVarName}->DateTime = \$this->{$strObjectName}->{$strPropName};";
107: } else {
108: $strRet = "\t\t\tif (\$this->{$strControlVarName}) \$this->{$strControlVarName}->DateTime = \$this->{$strObjectName}->{$strPropName};";
109: }
110: return $strRet . "\n";
111: }
112:
113: 114: 115: 116: 117: 118:
119: public function ConnectorUpdate(QCodeGenBase $objCodeGen, QSqlTable $objTable, $objColumn) {
120: $strObjectName = $objCodeGen->ModelVariableName($objTable->Name);
121: $strPropName = $objColumn->Reference ? $objColumn->Reference->PropertyName : $objColumn->PropertyName;
122: $strControlVarName = $this->VarName($strPropName);
123: $strRet = <<<TMPL
124: if (\$this->{$strControlVarName}) \$this->{$strObjectName}->{$objColumn->PropertyName} = \$this->{$strControlVarName}->DateTime;
125:
126: TMPL;
127: return $strRet;
128: }
129: }