Source for file RSDEngineDBTemplateFileSearchRecord.php

Documentation is available at RSDEngineDBTemplateFileSearchRecord.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 RSDEngineDBTemplateFileSearchRecord.
20 *
21 * @package RSDEngine
22 * @author Lukas Feiler <lukas.feiler@chello.at>
23 * @copyright Lukas Feiler 2003
24 * @filesource
25 */
26
27 /**RSDEngineDBTemplateFileSearchRecord extends RSDEngineTemplateFile.
28 */
29 require_once('RSDEngine/RSDEngineTemplateFile.php');
30
31 /**Generates the smarty template file to be included by the search-template to display the records.
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 RSDEngineDBTemplateFileSearchRecord 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 "search" . ucfirst($this->config['table']->getTableNameWithoutPrefix()) . "_record.tpl";
51 }
52
53 /**Returns the filename of the corresponding controller.
54 * @return String
55 */
56 function getControllerFilename()
57 {
58 return "search" . ucfirst($this->config['table']->getTableNameWithoutPrefix()) . ".php";
59 }
60
61 /**Returns the filename of the controller that displays just one record.
62 * @see RSDEngineDBControllerFileGetOne
63 * @return String
64 */
65 function getControllerGetOneFilename()
66 {
67 return "getOne" . ucfirst($this->config['table']->getTableNameWithoutPrefix()) . ".php";
68 }
69
70 /**Returns the filename of the controller that deletes a record.
71 * @see RSDEngineDBControllerFileDelete
72 * @return String
73 */
74 function getControllerDeleteFilename()
75 {
76 return "delete" . ucfirst($this->config['table']->getTableNameWithoutPrefix()) . ".php";
77 }
78
79 /**Returns the filename of the getStorage* controller for a specific record.
80 * @see RSDEngineDBControllerFileGetStored
81 * @return String
82 */
83 function getControllerGetStorageFilename(&$column)
84 {
85 return "getStored" . ucfirst($this->config['table']->getTableNameWithoutPrefix()) . ucfirst($column->getColumnNameForVariableName()) . ".php";
86 }
87
88 /**Returns the filename of the controller that creates a record.
89 * @see RSDEngineDBControllerFileCreate
90 * @return String
91 */
92 function getControllerCreateFilename()
93 {
94 return "create" . ucfirst($this->config['table']->getTableNameWithoutPrefix()) . ".php";
95 }
96
97 /**Returns the filename of the controller that updates a record.
98 * @see RSDEngineDBControllerFileUpdate
99 * @return String
100 */
101 function getControllerUpdateFilename()
102 {
103 return "update" . ucfirst($this->config['table']->getTableNameWithoutPrefix()) . ".php";
104 }
105
106 /**Returns the filename of the controller that updates a LiveUser right.
107 * @see RSDEngineDBControllerFileUpdateRight
108 * @return String
109 */
110 function getControllerUpdateRightFilename(&$column)
111 {
112 return "update" . ucfirst($this->config['table']->getTableNameWithoutPrefix()) . "Right" . ucfirst($column->getColumnNameForVariableName()) . ".php";
113 }
114
115 /**Returns the filename of the controller that updates a LiveUser area.
116 * @see RSDEngineDBControllerFileUpdateArea
117 * @return String
118 */
119 function getControllerUpdateAreaFilename(&$column)
120 {
121 return "update" . ucfirst($this->config['table']->getTableNameWithoutPrefix()) . "Area" . ucfirst($column->getColumnNameForVariableName()) . ".php";
122 }
123
124 /**Returns the filename of the controller that updates a LiveUser group.
125 * @see RSDEngineDBControllerFileUpdateArea
126 * @return String
127 */
128 function getControllerUpdateGroupFilename(&$column)
129 {
130 return "update" . ucfirst($this->config['table']->getTableNameWithoutPrefix()) . "Group" . ucfirst($column->getColumnNameForVariableName()) . ".php";
131 }
132
133 /**Returns the code for smarty template file to be included by the get-template to display the records.
134 *
135 * @access private
136 * @return String The code for the file.
137 */
138 function getCode()
139 {
140 extract($this->config);
141 $table =& $this->config['table'];
142 $OPEN = $smartyLeftDelimiter;
143 $CLOSE = $smartyRightDelimiter;
144 $authors = RSArrayUtil::toString(split("\n",$authors),"\n",'* @author %val');
145 $records = ucfirst($this->config['table']->getTableNameWithoutPrefix());
146 $tableInstanceName = $table->getChildClassInstanceName();
147 $appInstanceName = $this->relatedClasses['dbApplicationClass']->getInstanceName();
148
149
150 $allowUserOrderBy = $table->getFileOptionProperty('searchTemplate', 'allowUserOrderBy');
151 $orderBy = $table->getFileOptionProperty('searchTemplate', 'orderBy');
152 $selectMethodName = $table->getFileOptionProperty('searchTemplate', 'selectMethodName');
153 $paging = $table->getFileOptionProperty('searchTemplate', 'paging');
154 $recordsPerPage = $table->getFileOptionProperty('searchTemplate', 'recordsPerPage');
155 $header = $table->getFileOptionProperty('searchTemplate', 'header');
156 $footer = $table->getFileOptionProperty('searchTemplate', 'footer');
157 $showKeyColumns = $table->getFileOptionProperty('searchTemplate', 'showKeyColumns');
158 $separateRecordTemplate = $table->getFileOptionProperty('searchTemplate', 'separateRecordTemplate');
159 $write = $table->getFileOptionProperty('searchTemplateRecord', 'write');
160
161 if (!$separateRecordTemplate) {
162 $write = 'false';
163 }
164 $this->setWrite($write);
165
166 $nonFilteredColumns = $table->getSelectMethodColumns($selectMethodName);
167
168 $columns = array();
169 reset($nonFilteredColumns);
170 while (list($key, $column) = each($nonFilteredColumns)) {
171 if (!$showKeyColumns) {
172 if ($column->isPrimaryKey || $column->isForeignKey) {
173 continue;
174 }
175 }
176 if ($column->doNotSelect) {
177 continue;
178 }
179 $columns[] = $nonFilteredColumns[$key];
180 }
181
182 $data = '';
183
184 //end of first tr; begin of section
185 $data .= " <tr>\n";
186
187 //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.
188 if (($primaryKeyColumn =& $table->getPrimaryKeyColumn()) !== false) {
189
190 //view
191 $data .= ' <td><a href="' .
192 $this->getControllerGetOneFilename() . '?' .
193 $primaryKeyColumn->getColumnNameForVariableName() . '=' .
194 $OPEN . '$' . $table->getTableNameForVariableName() . "[list]." . $primaryKeyColumn->name . "|escape${CLOSE}" .
195 "\">view</a></td>\n";
196
197 //update
198 if ($liveUser) {
199 $data .= ' {{if $' . $table->getTableNameForVariableName() . "[list].__canUpdate}}\n";
200 }
201 $data .= ' <td><a href="' .
202 $this->getControllerUpdateFilename() . '?' .
203 $primaryKeyColumn->getColumnNameForVariableName() . '=' .
204 $OPEN . '$' . $table->getTableNameForVariableName() . "[list]." . $primaryKeyColumn->name . "|escape${CLOSE}" .
205 "\">update</a></td>\n";
206 if ($liveUser) {
207 $data .=" {{else}}\n" .
208 " <td>update</td>\n" .
209 " {{/if}}\n";
210 }
211
212 //delete
213 if ($liveUser) {
214 $data .= ' {{if $' . $table->getTableNameForVariableName() . "[list].__canDelete}}\n";
215 }
216 $data .= ' <td><a href="' .
217 $this->getControllerDeleteFilename() . '?' .
218 $primaryKeyColumn->getColumnNameForVariableName() . '=' .
219 $OPEN . '$' . $table->getTableNameForVariableName() . "[list]." . $primaryKeyColumn->name . "|escape${CLOSE}" .
220 "\">delete</a></td>\n";
221 if ($liveUser) {
222 $data .=" {{else}}\n" .
223 " <td>delete</td>\n" .
224 " {{/if}}\n";
225 }
226 }
227
228 //td for each column (will be repeated becuase it's inside the section
229 reset($columns);
230 while (list($key, $val) = each($columns)) {
231 $columnCaption = $columns[$key]->getColumnNameForVariableName();
232 $columnNameForPartialMethodName = $columns[$key]->getColumnNameForPartialMethodName();
233 $isValidFileOptions = $columns[$key]->getIsValidFileOptions();
234 $editLiveUserRightOption = count($columns[$key]->editLiveUserRightOptions) > 0;
235 $editLiveUserAreaOption = count($columns[$key]->editLiveUserAreaOptions) > 0;
236 $editLiveUserGroupOption = count($columns[$key]->editLiveUserGroupOptions) > 0;
237
238 if ($editLiveUserRightOption) {
239 $data .=' {{if $' . $table->getTableNameForVariableName() . "[list].__canUpdate$columnNameForPartialMethodName}}\n" .
240 " <td>\n" .
241 " <a href=\"" . $this->getControllerUpdateRightFilename($columns[$key]) . '?' .
242 $primaryKeyColumn->getColumnNameForVariableName() . '=' .
243 $OPEN . '$' . $table->getTableNameForVariableName() . "[list]." . $primaryKeyColumn->name . "|escape${CLOSE}" .
244 "\">\n" .
245 " ${OPEN}\$" . $table->getTableNameForVariableName() . "[list]." . $columns[$key]->name . "|escape${CLOSE}\n" .
246 " </a>\n" .
247 " </td>\n" .
248 " {{else}}\n" .
249 " <td>\n" .
250 " ${OPEN}\$" . $table->getTableNameForVariableName() . "[list]." . $columns[$key]->name . "|escape${CLOSE}\n" .
251 " </td>\n" .
252 " {{/if}}\n";
253 } elseif ($editLiveUserAreaOption) {
254 $data .=' {{if $' . $table->getTableNameForVariableName() . "[list].__canUpdate$columnNameForPartialMethodName}}\n" .
255 " <td>\n" .
256 " <a href=\"" . $this->getControllerUpdateAreaFilename($columns[$key]) . '?' .
257 $primaryKeyColumn->getColumnNameForVariableName() . '=' .
258 $OPEN . '$' . $table->getTableNameForVariableName() . "[list]." . $primaryKeyColumn->name . "|escape${CLOSE}" .
259 "\">\n" .
260 " ${OPEN}\$" . $table->getTableNameForVariableName() . "[list]." . $columns[$key]->name . "|escape${CLOSE}\n" .
261 " </a>\n" .
262 " </td>\n" .
263 " {{else}}\n" .
264 " <td>\n" .
265 " ${OPEN}\$" . $table->getTableNameForVariableName() . "[list]." . $columns[$key]->name . "|escape${CLOSE}\n" .
266 " </td>\n" .
267 " {{/if}}\n";
268 } elseif ($editLiveUserGroupOption) {
269 $data .=' {{if $' . $table->getTableNameForVariableName() . "[list].__canUpdate$columnNameForPartialMethodName}}\n" .
270 " <td>\n" .
271 " <a href=\"" . $this->getControllerUpdateGroupFilename($columns[$key]) . '?' .
272 $primaryKeyColumn->getColumnNameForVariableName() . '=' .
273 $OPEN . '$' . $table->getTableNameForVariableName() . "[list]." . $primaryKeyColumn->name . "|escape${CLOSE}" .
274 "\">\n" .
275 " ${OPEN}\$" . $table->getTableNameForVariableName() . "[list]." . $columns[$key]->name . "|escape${CLOSE}\n" .
276 " </a>\n" .
277 " </td>\n" .
278 " {{else}}\n" .
279 " <td>\n" .
280 " ${OPEN}\$" . $table->getTableNameForVariableName() . "[list]." . $columns[$key]->name . "|escape${CLOSE}\n" .
281 " </td>\n" .
282 " {{/if}}\n";
283 } elseif ($isValidFileOptions == null || $primaryKeyColumn === false) {
284 $data .= " <td>${OPEN}\$" . $table->getTableNameForVariableName() . "[list]." . $columns[$key]->name . "|escape${CLOSE}</td>\n";
285 } else {
286 $data .=" <td>\n" .
287 " <a href=\"" . $this->getControllerGetStorageFilename($columns[$key]) . '?' .
288 $primaryKeyColumn->getColumnNameForVariableName() . '=' .
289 $OPEN . '$' . $table->getTableNameForVariableName() . "[list]." . $primaryKeyColumn->name . "|escape${CLOSE}" .
290 "\">\n" .
291 " ${OPEN}\$" . $table->getTableNameForVariableName() . "[list]." . $columns[$key]->name . "|escape${CLOSE}\n" .
292 " </a>\n";
293 " </td>\n";
294 }
295 }
296
297 //end of section; end of table; end of body; end of html
298 $data .=" </tr>\n";
299
300 return $data;
301 }
302 }
303 ?>

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