Source for file RSDEngineDBTemplateFileGetOne.php

Documentation is available at RSDEngineDBTemplateFileGetOne.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 RSDEngineDBTemplateFileGetOne.
20 *
21 * @package RSDEngine
22 * @author Lukas Feiler <lukas.feiler@chello.at>
23 * @copyright Lukas Feiler 2003
24 * @filesource
25 */
26
27 /**RSDEngineDBTemplateFileGetOne extends RSDEngineTemplateFile.
28 */
29 require_once('RSDEngine/RSDEngineTemplateFile.php');
30
31 /**Generates the smarty template file for selecting a single record 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 RSDEngineDBTemplateFileGetOne 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 "getOne" . ucfirst($this->config['table']->getTableNameWithoutPrefix()) . ".tpl";
51 }
52
53 /**Returns the filename of the corresponding controller.
54 * @return String
55 */
56 function getControllerFilename()
57 {
58 return "getOne" . ucfirst($this->config['table']->getTableNameWithoutPrefix()) . ".php";
59 }
60
61 /**Returns the code for the template file for selecting a single record from a table.
62 *
63 * @access private
64 * @return String The code for the file.
65 */
66 function getCode()
67 {
68 extract($this->config);
69 $table =& $this->config['table'];
70 $OPEN = $smartyLeftDelimiter;
71 $CLOSE = $smartyRightDelimiter;
72 $authors = RSArrayUtil::toString(split("\n",$authors),"\n",'* @author %val');
73 $records = ucfirst($this->config['table']->getTableNameWithoutPrefix());
74 $tableInstanceName = $table->getChildClassInstanceName();
75 $appInstanceName = $this->relatedClasses['dbApplicationClass']->getInstanceName();
76 if (($primaryKeyColumn = $table->getPrimaryKeyColumn()) === false) {
77 return "No primary key was defined! Without a primary key the RSDEngine cannot generate code to delete a single record!\n";
78 }
79
80 $allowUserOrderBy = $table->getFileOptionProperty('getOneTemplate', 'allowUserOrderBy');
81 $orderBy = $table->getFileOptionProperty('getOneTemplate', 'orderBy');
82 $selectMethodName = $table->getFileOptionProperty('getOneTemplate', 'selectMethodName');
83 $paging = $table->getFileOptionProperty('getOneTemplate', 'paging');
84 $recordsPerPage = $table->getFileOptionProperty('getOneTemplate', 'recordsPerPage');
85 $header = $table->getFileOptionProperty('getOneTemplate', 'header');
86 $footer = $table->getFileOptionProperty('getOneTemplate', 'footer');
87 $showKeyColumns = $table->getFileOptionProperty('getOneTemplate', 'showKeyColumns');
88 $write = $table->getFileOptionProperty('getOneTemplate', 'write');
89
90 $this->setWrite($write);
91
92
93 $nonFilteredColumns = $table->getSelectMethodColumns($selectMethodName);
94
95 $columns = array();
96 reset($nonFilteredColumns);
97 while (list($key, $column) = each($nonFilteredColumns)) {
98 if (!$showKeyColumns) {
99 if ($column->isPrimaryKey || $column->isForeignKey) {
100 continue;
101 }
102 }
103 if ($column->doNotSelect) {
104 continue;
105 }
106 $columns[] = $nonFilteredColumns[$key];
107 }
108
109 $data = '';
110 $data .="<html>\n" .
111 "<head>\n" .
112 " <title>getOne " . $table->getTableNameForVariableName() . "</title>\n" .
113 "</head>\n";
114 if ($header) {
115 $data .="{{include file=\"header.tpl\"}}\n";
116 }
117 $data .="<body>\n" .
118 " ${OPEN}if \$error${CLOSE}\n" .
119 ' <font color="red">An error occured!</font>' . "\n" .
120 " ${OPEN}/if${CLOSE}\n" .
121 " <table border=1>\n";
122
123 while (list($key, $column) = each($columns)) {
124 if ($column->isPrimaryKey || $column->isForeignKey) {
125 continue;
126 }
127 $columnName = $columns[$key]->getColumnNameForVariableName();
128 $data .=" <tr>\n" .
129 " <td>\n" .
130 " $columnName\n" .
131 " </td>\n" .
132 " <td>\n" .
133 " ${OPEN}\$" . $columns[$key]->getColumnNameForVariableName() . "|escape${CLOSE}\n" .
134 " </td>\n" .
135 " </tr>\n";
136 }
137 $data .=" </table>\n";
138 if ($footer) {
139 $data .="{{include file=\"footer.tpl\"}}\n";
140 }
141 $data .="</body>\n" .
142 "</html>";
143
144 return $data;
145 }
146 }
147 ?>

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