Source for file RSDEngineDBTemplateFileGet.php

Documentation is available at RSDEngineDBTemplateFileGet.php


1 <?php
2 // RSDEngine: The Rapid and Secure Development Engine
3 // Copyright (C) 2003 Lukas Feiler
4 //
5 // This library is free software; you can redistribute it and/or
6 // modify it under the terms of the GNU Lesser General Public
7 // License as published by the Free Software Foundation; either
8 // version 2.1 of the License, or (at your option) any later version.
9 //
10 // This library is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 // Lesser General Public License for more details.
14 //
15 // You should have received a copy of the GNU Lesser General Public
16 // License along with this library; if not, write to the Free Software
17 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18
19 /**Contains just the class RSDEngineDBTemplateFileGet.
20 *
21 * @package RSDEngine
22 * @author Lukas Feiler <lukas.feiler@chello.at>
23 * @copyright Lukas Feiler 2003
24 * @filesource
25 */
26
27 /**RSDEngineDBTemplateFileGet extends RSDEngineTemplateFile.
28 */
29 require_once('RSDEngine/RSDEngineTemplateFile.php');
30
31 /**Generates the smarty template file for selecting all records from a table.
32 *
33 * @author Lukas Feiler <lukas.feiler@chello.at>
34 * @version 0.1.9
35 * @copyright Lukas Feiler 2003
36 * @package RSDEngine
37 */
38 class RSDEngineDBTemplateFileGet extends RSDEngineTemplateFile {
39
40 /**Whether to overwrite an existing file.
41 * @var boolean
42 */
43 var $overwriteExisting = false;
44
45 /**Returns the filename.
46 * @return String
47 */
48 function getFilename()
49 {
50 return "get" . ucfirst($this->config['table']->getTableNameWithoutPrefix()) . ".tpl";
51 }
52
53 /**Returns the name of the file for displaying the records.
54 * @return String
55 */
56 function getRecordFilename()
57 {
58 return "get" . ucfirst($this->config['table']->getTableNameWithoutPrefix()) . "_record.tpl";
59 }
60
61 /**Returns the filename of the corresponding controller.
62 * @return String
63 */
64 function getControllerFilename()
65 {
66 return "get" . ucfirst($this->config['table']->getTableNameWithoutPrefix()) . ".php";
67 }
68
69 /**Returns the filename of the controller that displays just one record.
70 * @see RSDEngineDBControllerFileGetOne
71 * @return String
72 */
73 function getControllerGetOneFilename()
74 {
75 return "getOne" . ucfirst($this->config['table']->getTableNameWithoutPrefix()) . ".php";
76 }
77
78 /**Returns the filename of the controller that deletes a record.
79 * @see RSDEngineDBControllerFileDelete
80 * @return String
81 */
82 function getControllerDeleteFilename()
83 {
84 return "delete" . ucfirst($this->config['table']->getTableNameWithoutPrefix()) . ".php";
85 }
86
87 /**Returns the filename of the getStorage* controller for a specific record.
88 * @see RSDEngineDBControllerFileGetStored
89 * @return String
90 */
91 function getControllerGetStorageFilename(&$column)
92 {
93 return "getStored" . ucfirst($this->config['table']->getTableNameWithoutPrefix()) . ucfirst($column->getColumnNameForVariableName()) . ".php";
94 }
95
96 /**Returns the filename of the controller that creates a record.
97 * @see RSDEngineDBControllerFileCreate
98 * @return String
99 */
100 function getControllerCreateFilename()
101 {
102 return "create" . ucfirst($this->config['table']->getTableNameWithoutPrefix()) . ".php";
103 }
104
105 /**Returns the filename of the controller that updates a record.
106 * @see RSDEngineDBControllerFileUpdate
107 * @return String
108 */
109 function getControllerUpdateFilename()
110 {
111 return "update" . ucfirst($this->config['table']->getTableNameWithoutPrefix()) . ".php";
112 }
113
114 /**Returns the filename of the controller that updates a LiveUser right.
115 * @see RSDEngineDBControllerFileUpdateRight
116 * @return String
117 */
118 function getControllerUpdateRightFilename(&$column)
119 {
120 return "update" . ucfirst($this->config['table']->getTableNameWithoutPrefix()) . "Right" . ucfirst($column->getColumnNameForVariableName()) . ".php";
121 }
122
123 /**Returns the filename of the controller that updates a LiveUser area.
124 * @see RSDEngineDBControllerFileUpdateArea
125 * @return String
126 */
127 function getControllerUpdateAreaFilename(&$column)
128 {
129 return "update" . ucfirst($this->config['table']->getTableNameWithoutPrefix()) . "Area" . ucfirst($column->getColumnNameForVariableName()) . ".php";
130 }
131
132 /**Returns the filename of the controller that updates a LiveUser group.
133 * @see RSDEngineDBControllerFileUpdateArea
134 * @return String
135 */
136 function getControllerUpdateGroupFilename(&$column)
137 {
138 return "update" . ucfirst($this->config['table']->getTableNameWithoutPrefix()) . "Group" . ucfirst($column->getColumnNameForVariableName()) . ".php";
139 }
140
141 /**Returns the code for the template file for selecting all records from a table.
142 *
143 * @access private
144 * @return String The code for the file.
145 */
146 function getCode()
147 {
148 extract($this->config);
149 $table =& $this->config['table'];
150 $OPEN = $smartyLeftDelimiter;
151 $CLOSE = $smartyRightDelimiter;
152 $authors = RSArrayUtil::toString(split("\n",$authors),"\n",'* @author %val');
153 $records = ucfirst($this->config['table']->getTableNameWithoutPrefix());
154 $tableInstanceName = $table->getChildClassInstanceName();
155 $appInstanceName = $this->relatedClasses['dbApplicationClass']->getInstanceName();
156
157
158 $allowUserOrderBy = $table->getFileOptionProperty('getTemplate', 'allowUserOrderBy');
159 $orderBy = $table->getFileOptionProperty('getTemplate', 'orderBy');
160 $selectMethodName = $table->getFileOptionProperty('getTemplate', 'selectMethodName');
161 $paging = $table->getFileOptionProperty('getTemplate', 'paging');
162 $recordsPerPage = $table->getFileOptionProperty('getTemplate', 'recordsPerPage');
163 $header = $table->getFileOptionProperty('getTemplate', 'header');
164 $footer = $table->getFileOptionProperty('getTemplate', 'footer');
165 $showKeyColumns = $table->getFileOptionProperty('getTemplate', 'showKeyColumns');
166 $separateRecordTemplate = $table->getFileOptionProperty('getTemplate', 'separateRecordTemplate');
167 $write = $table->getFileOptionProperty('getTemplate', 'write');
168
169 $this->setWrite($write);
170
171
172 $nonFilteredColumns = $table->getSelectMethodColumns($selectMethodName);
173
174 $columns = array();
175 reset($nonFilteredColumns);
176 while (list($key, $column) = each($nonFilteredColumns)) {
177 if (!$showKeyColumns) {
178 if ($column->isPrimaryKey || $column->isForeignKey) {
179 continue;
180 }
181 }
182 if ($column->doNotSelect) {
183 continue;
184 }
185 $columns[] = $nonFilteredColumns[$key];
186 }
187
188 $data = '';
189 $data .="<html>\n" .
190 "<head>\n" .
191 " <title>select " . $table->getTableNameForVariableName() . "</title>\n" .
192 "</head>\n" .
193 "<body>\n";
194 if ($header) {
195 $data .="{{include file=\"header.tpl\"}}\n";
196 }
197 $data .= " ${OPEN}\$errorMsg${CLOSE}\n";
198
199 $data.= '' .
200 " <table border=1>\n" .
201 " <tr>\n";
202
203 //if we have a view, a update & a delete link (see below) we need one more column!
204 if (($primaryKeyColumn =& $table->getPrimaryKeyColumn()) !== false) {
205 $data .= " <td>view</td>\n";
206 $data .= " <td>update</td>\n";
207 $data .= " <td>delete</td>\n";
208 }
209
210 //column captions (first tr in the table)
211 reset($columns);
212 while (list($key, $val) = each($columns)) {
213 $columnCaption = $columns[$key]->getColumnNameForVariableName();
214 if ($allowUserOrderBy) {
215 $data .=" <td>\n" .
216 " {{if \$orderBy == '$columnCaption'}}\n" .
217 " {{if \$orderDescending}}\n" .
218 " <a href=\"{{\$URI}}&orderBy=$columnCaption&orderDescending=0\">$columnCaption /</a>\n" .
219 " {{else}}\n" .
220 " <a href=\"{{\$URI}}&orderBy=$columnCaption&orderDescending=1\">$columnCaption \</a>\n" .
221 " {{/if}}\n" .
222 " {{else}}\n" .
223 " <a href=\"{{\$URI}}&orderBy=$columnCaption&orderDescending=0\">$columnCaption</a>\n" .
224 " {{/if}}\n" .
225 " </td>\n";
226 } else {
227 $data .=" <td>\n" .
228 " $columnCaption\n" .
229 " </td>\n";
230 }
231 }
232
233
234 //end of first tr; begin of section
235 $data .= '' .
236 " </tr>\n" .
237 " ${OPEN}section name=list loop=\$" . $table->getTableNameForVariableName() . "${CLOSE}\n";
238
239 if (!$separateRecordTemplate) {
240 $data .= " <tr>\n";
241
242 //if this table has defined one column as primary key we have a 'view'-link in the first td & a 'delete'-link in the 2ed; if we do one more column is needed that would be added obove.
243 if (($primaryKeyColumn =& $table->getPrimaryKeyColumn()) !== false) {
244
245 //view
246 $data .= ' <td><a href="' .
247 $this->getControllerGetOneFilename() . '?' .
248 $primaryKeyColumn->getColumnNameForVariableName() . '=' .
249 $OPEN . '$' . $table->getTableNameForVariableName() . "[list]." . $primaryKeyColumn->name . "|escape${CLOSE}" .
250 "\">view</a></td>\n";
251
252 //update
253 if ($liveUser) {
254 $data .= ' {{if $' . $table->getTableNameForVariableName() . "[list].__canUpdate}}\n";
255 }
256 $data .= ' <td><a href="' .
257 $this->getControllerUpdateFilename() . '?' .
258 $primaryKeyColumn->getColumnNameForVariableName() . '=' .
259 $OPEN . '$' . $table->getTableNameForVariableName() . "[list]." . $primaryKeyColumn->name . "|escape${CLOSE}" .
260 "\">update</a></td>\n";
261 if ($liveUser) {
262 $data .=" {{else}}\n" .
263 " <td>update</td>\n" .
264 " {{/if}}\n";
265 }
266
267 //delete
268 if ($liveUser) {
269 $data .= ' {{if $' . $table->getTableNameForVariableName() . "[list].__canDelete}}\n";
270 }
271 $data .= ' <td><a href="' .
272 $this->getControllerDeleteFilename() . '?' .
273 $primaryKeyColumn->getColumnNameForVariableName() . '=' .
274 $OPEN . '$' . $table->getTableNameForVariableName() . "[list]." . $primaryKeyColumn->name . "|escape${CLOSE}" .
275 "\">delete</a></td>\n";
276 if ($liveUser) {
277 $data .=" {{else}}\n" .
278 " <td>delete</td>\n" .
279 " {{/if}}\n";
280 }
281 }
282
283 //td for each column (will be repeated becuase it's inside the section
284 reset($columns);
285 while (list($key, $val) = each($columns)) {
286 $columnCaption = $columns[$key]->getColumnNameForVariableName();
287 $columnNameForPartialMethodName = $columns[$key]->getColumnNameForPartialMethodName();
288 $isValidFileOptions = $columns[$key]->getIsValidFileOptions();
289 $editLiveUserRightOption = count($columns[$key]->editLiveUserRightOptions) > 0;
290 $editLiveUserAreaOption = count($columns[$key]->editLiveUserAreaOptions) > 0;
291 $editLiveUserGroupOption = count($columns[$key]->editLiveUserGroupOptions) > 0;
292
293 if ($editLiveUserRightOption) {
294 $data .=' {{if $' . $table->getTableNameForVariableName() . "[list].__canUpdate$columnNameForPartialMethodName}}\n" .
295 " <td>\n" .
296 " <a href=\"" . $this->getControllerUpdateRightFilename($columns[$key]) . '?' .
297 $primaryKeyColumn->getColumnNameForVariableName() . '=' .
298 $OPEN . '$' . $table->getTableNameForVariableName() . "[list]." . $primaryKeyColumn->name . "|escape${CLOSE}" .
299 "\">\n" .
300 " ${OPEN}\$" . $table->getTableNameForVariableName() . "[list]." . $columns[$key]->name . "|escape${CLOSE}\n" .
301 " </a>\n" .
302 " </td>\n" .
303 " {{else}}\n" .
304 " <td>\n" .
305 " ${OPEN}\$" . $table->getTableNameForVariableName() . "[list]." . $columns[$key]->name . "|escape${CLOSE}\n" .
306 " </td>\n" .
307 " {{/if}}\n";
308 } elseif ($editLiveUserAreaOption) {
309 $data .=' {{if $' . $table->getTableNameForVariableName() . "[list].__canUpdate$columnNameForPartialMethodName}}\n" .
310 " <td>\n" .
311 " <a href=\"" . $this->getControllerUpdateAreaFilename($columns[$key]) . '?' .
312 $primaryKeyColumn->getColumnNameForVariableName() . '=' .
313 $OPEN . '$' . $table->getTableNameForVariableName() . "[list]." . $primaryKeyColumn->name . "|escape${CLOSE}" .
314 "\">\n" .
315 " ${OPEN}\$" . $table->getTableNameForVariableName() . "[list]." . $columns[$key]->name . "|escape${CLOSE}\n" .
316 " </a>\n" .
317 " </td>\n" .
318 " {{else}}\n" .
319 " <td>\n" .
320 " ${OPEN}\$" . $table->getTableNameForVariableName() . "[list]." . $columns[$key]->name . "|escape${CLOSE}\n" .
321 " </td>\n" .
322 " {{/if}}\n";
323 } elseif ($editLiveUserGroupOption) {
324 $data .=' {{if $' . $table->getTableNameForVariableName() . "[list].__canUpdate$columnNameForPartialMethodName}}\n" .
325 " <td>\n" .
326 " <a href=\"" . $this->getControllerUpdateGroupFilename($columns[$key]) . '?' .
327 $primaryKeyColumn->getColumnNameForVariableName() . '=' .
328 $OPEN . '$' . $table->getTableNameForVariableName() . "[list]." . $primaryKeyColumn->name . "|escape${CLOSE}" .
329 "\">\n" .
330 " ${OPEN}\$" . $table->getTableNameForVariableName() . "[list]." . $columns[$key]->name . "|escape${CLOSE}\n" .
331 " </a>\n" .
332 " </td>\n" .
333 " {{else}}\n" .
334 " <td>\n" .
335 " ${OPEN}\$" . $table->getTableNameForVariableName() . "[list]." . $columns[$key]->name . "|escape${CLOSE}\n" .
336 " </td>\n" .
337 " {{/if}}\n";
338 } elseif ($isValidFileOptions == null || $primaryKeyColumn === false) {
339 $data .= " <td>${OPEN}\$" . $table->getTableNameForVariableName() . "[list]." . $columns[$key]->name . "|escape${CLOSE}</td>\n";
340 } else {
341 $data .=" <td>\n" .
342 " <a href=\"" . $this->getControllerGetStorageFilename($columns[$key]) . '?' .
343 $primaryKeyColumn->getColumnNameForVariableName() . '=' .
344 $OPEN . '$' . $table->getTableNameForVariableName() . "[list]." . $primaryKeyColumn->name . "|escape${CLOSE}" .
345 "\">\n" .
346 " ${OPEN}\$" . $table->getTableNameForVariableName() . "[list]." . $columns[$key]->name . "|escape${CLOSE}\n" .
347 " </a>\n";
348 " </td>\n";
349 }
350 }
351 $data .= " </tr>\n";
352
353 } else {
354 $data .= " ${OPEN}include file=\"" . $this->getRecordFilename() . "\"${CLOSE}\n";
355 }
356
357 //end of section; end of table; end of body; end of html
358 $data .=" ${OPEN}/section${CLOSE}\n" .
359 " </table>\n";
360 if ($paging) {
361 $data .="<br>\n" .
362 "\n" .
363 "${OPEN}include file=\"paging.tpl\"${CLOSE}\n" .
364 "\n" .
365 "<br>\n";
366 }
367
368 $data .=" {{if \$canInsertInto" . ucfirst($table->getTableNameForVariableName()) . "}}\n" .
369 " <a href=\"" . $this->getControllerCreateFilename() . "\">create</a>\n" .
370 " {{/if}}\n";
371 if ($footer) {
372 $data .="{{include file=\"footer.tpl\"}}\n";
373 }
374 $data .="</body>\n" .
375 "</html>";
376
377 return $data;
378 }
379 }
380 ?>

Documentation generated on Mon, 8 Dec 2003 13:12:28 +0100 by phpDocumentor 1.2.3