1: <?php
2:
3: abstract class QControlBase_CodeGenerator extends AbstractControl_CodeGenerator {
4:
5: /**
6: * @param QCodeGenBase $objCodeGen
7: * @param QSqlColumn|QReverseReference| QManyToManyReference $objColumn
8: * @return string
9: */
10: public function ConnectorVariableDeclaration(QCodeGenBase $objCodeGen, $objColumn) {
11: $strClassName = $this->GetControlClass();
12: $strControlVarName = $objCodeGen->ModelConnectorVariableName($objColumn);
13:
14: $strRet = <<<TMPL
15: /**
16: * @var {$strClassName} {$strControlVarName}
17:
18: * @access protected
19: */
20: protected \${$strControlVarName};
21:
22:
23: TMPL;
24: return $strRet;
25: }
26:
27: /**
28: * Reads the options from the special data file, and possibly the column
29: * @param QCodeGenBase $objCodeGen
30: * @param QSqlTable $objTable
31: * @param null|QSqlColumn|QReverseReference|QManyToManyReference $objColumn A null column means we want the table options
32: * @param string $strControlVarName
33: * @return string
34: */
35: public function ConnectorCreateOptions(QCodeGenBase $objCodeGen, QSqlTable $objTable, $objColumn, $strControlVarName) {
36: $strRet = '';
37:
38: if (!$objColumn) {
39: $strRet .= <<<TMPL
40: \$this->{$strControlVarName}->LinkedNode = QQN::{$objTable->ClassName}();
41:
42: TMPL;
43: $options = $objTable->Options;
44: }
45: else {
46: if ($objColumn instanceof QSqlColumn) {
47: $strPropName = ($objColumn->Reference && !$objColumn->Reference->IsType) ? $objColumn->Reference->PropertyName : $objColumn->PropertyName;
48: $strClass = $objTable->ClassName;
49: } elseif ($objColumn instanceof QManyToManyReference ||
50: $objColumn instanceof QReverseReference
51: ) {
52: $strPropName = $objColumn->ObjectDescription;
53: $strClass = $objTable->ClassName;
54: }
55:
56: $strRet .= <<<TMPL
57: \$this->{$strControlVarName}->LinkedNode = QQN::{$strClass}()->{$strPropName};
58:
59: TMPL;
60: $options = $objColumn->Options;
61: }
62: if (isset ($options['Overrides'])) {
63:
64: foreach ($options['Overrides'] as $name => $val) {
65: if (is_numeric($val)) {
66: // looks like a number
67: $strVal = $val;
68: } elseif (is_string($val)) {
69: if (strpos($val, '::') !== false &&
70: strpos($val, ' ') === false
71: ) {
72: // looks like a constant
73: $strVal = $val;
74: } else {
75: $strVal = var_export($val, true);
76: $strVal = 'QApplication::Translate(' . $strVal . ')';
77: }
78: } else {
79: $strVal = var_export($val, true);
80: }
81: $strRet .= <<<TMPL
82: \$this->{$strControlVarName}->{$name} = {$strVal};
83:
84: TMPL;
85: }
86: }
87: return $strRet;
88: }
89:
90: /**
91: * @param string $strPropName
92: * @throws QCallerException
93: * @return string
94: */
95: public function VarName($strPropName) {
96: throw new QCallerException('VarName() method not implemented');
97: }
98:
99: /**
100: * Generate code that will be inserted into the ModelConnector to connect a database object with this control.
101: * This is called during the codegen process.
102: *
103: * @param QCodeGenBase $objCodeGen
104: * @param QSqlTable $objTable
105: * @param QSqlColumn|QReverseReference|QManyToManyReference $objColumn
106: * @throws QCallerException
107: * @return string
108: */
109: public function ConnectorCreate(QCodeGenBase $objCodeGen, QSqlTable $objTable, $objColumn) {
110: throw new QCallerException('ConnectorCreate() method not implemented');
111: }
112:
113: /**
114: * Returns code to refresh the control from the saved object.
115: *
116: * @param QCodeGenBase $objCodeGen
117: * @param QSqlTable $objTable
118: * @param QSqlColumn $objColumn
119: * @param bool $blnInit
120: * @throws QCallerException
121: * @return string
122: */
123: public function ConnectorRefresh(QCodeGenBase $objCodeGen, QSqlTable $objTable, $objColumn, $blnInit = false) {
124: throw new QCallerException('ConnectorRefresh() method not implemented');
125: }
126:
127: /**
128: * @param QCodeGenBase $objCodeGen
129: * @param QSqlTable $objTable
130: * @param QSqlColumn|QReverseReference $objColumn
131: * @throws QCallerException
132: * @return string
133: */
134: public function ConnectorUpdate(QCodeGenBase $objCodeGen, QSqlTable $objTable, $objColumn) {
135: throw new QCallerException('ConnectorUpdate() method not implemented');
136: }
137:
138: /**
139: * Generate helper functions for the update process.
140: *
141: * @param QCodeGenBase $objCodeGen
142: * @param QSqlTable $objTable
143: * @param QSqlColumn|QReverseReference|QManyToManyReference $objColumn
144: *
145: * @throws QCallerException
146: * @return string
147: */
148: public function ConnectorUpdateMethod(QCodeGenBase $objCodeGen, QSqlTable $objTable, $objColumn) {
149: throw new QCallerException('ConnectorUpdateMethod() method not implemented');
150: }
151:
152: /**
153: * Generate extra set options for the connector.
154: *
155: * @param QCodeGenBase $objCodeGen
156: * @param QSqlTable $objTable
157: * @param QSqlColumn|QReverseReference|QManyToManyReference $objColumn
158: *
159: * @throws QCallerException
160: * @return string
161: */
162: public function ConnectorSet(QCodeGenBase $objCodeGen, QSqlTable $objTable, $objColumn) {
163: return "";
164: }
165:
166: /**
167: * Generate extra set options for the connector.
168: *
169: * @param QCodeGenBase $objCodeGen
170: * @param QSqlTable $objTable
171: * @param QSqlColumn|QReverseReference|QManyToManyReference $objColumn
172: *
173: * @throws QCallerException
174: * @return string
175: */
176: public function ConnectorGet(QCodeGenBase $objCodeGen, QSqlTable $objTable, $objColumn) {
177: return "";
178: }
179:
180: /**
181: * Generate extra property comments for the connector.
182: *
183: * @param QCodeGenBase $objCodeGen
184: * @param QSqlTable $objTable
185: * @param QSqlColumn|QReverseReference|QManyToManyReference $objColumn
186: *
187: * @throws QCallerException
188: * @return string
189: */
190: public function ConnectorPropertyComments(QCodeGenBase $objCodeGen, QSqlTable $objTable, $objColumn) {
191: return "";
192: }
193:
194:
195: }