Source for file RSDEngineDBControllerFileDelete.php

Documentation is available at RSDEngineDBControllerFileDelete.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 RSDEngineDBControllerFileDelete.
20 *
21 * @package RSDEngine
22 * @author Lukas Feiler <lukas.feiler@chello.at>
23 * @copyright Lukas Feiler 2003
24 * @filesource
25 */
26
27 /**RSDEngineDBControllerFileDelete extends RSDEngineControllerFile.
28 */
29 require_once('RSDEngine/RSDEngineControllerFile.php');
30
31 /**Generates the controller file for deleting 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 RSDEngineDBControllerFileDelete extends RSDEngineControllerFile {
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 "delete" . ucfirst($this->config['table']->getTableNameWithoutPrefix()) . ".php";
51 }
52
53 /**Returns the filename of the corresponding template.
54 * @return String
55 */
56 function getTemplateFilename()
57 {
58 return "delete" . ucfirst($this->config['table']->getTableNameWithoutPrefix()) . ".tpl";
59 }
60
61 /**Returns the filename of the controller that displays multiple records.
62 * @see RSDEngineDBControllerFileGet
63 * @return String
64 */
65 function getControllerGetFilename()
66 {
67 return "get" . ucfirst($this->config['table']->getTableNameWithoutPrefix()) . ".php";
68 }
69
70 /**Returns the code for the controller file for deleting records from a table.
71 *
72 * @access private
73 * @return String The code for the file.
74 */
75 function getCode()
76 {
77 extract($this->config);
78 $table =& $this->config['table'];
79 $authors = RSArrayUtil::toString(split("\n",$authors),"\n",'* @author %val');
80 $records = ucfirst($this->config['table']->getTableNameWithoutPrefix());
81 $tableInstanceName = $table->getChildClassInstanceName();
82 $appInstanceName = $this->relatedClasses['dbApplicationClass']->getInstanceName();
83
84 $public = $table->getFileOptionProperty('deleteController', 'public');
85 $write = $table->getFileOptionProperty('deleteController', 'write');
86
87 $this->setWrite($write);
88
89 $data = '';
90 $data .="<?php\n" .
91 '/' . '**This file is the controller for deleting records from ' . $table->name . ".\n" .
92 '*' . "\n" .
93 $authors . "\n" .
94 '* @copyright ' . $copyright . "\n" .
95 '* @package ' . $projectName . "\n" .
96 '* @filesource' . "\n" .
97 '*/' . "\n" .
98 "\n";
99 if ($this->config['auth'] || $this->config['liveUser']) {
100 if ($public) {
101 $data .='/' . '**This controller requires no authentication.' . "\n" .
102 "*/\n" .
103 "require_once('model/" . $this->relatedFiles['dbApplicationPublicInitFile']->getFilename() . "');\n";
104 } else {
105 $data .='/' . '**This controller requires authentication.' . "\n" .
106 "*/\n" .
107 "require_once('model/" . $this->relatedFiles['dbApplicationPrivateInitFile']->getFilename() . "');\n";
108 }
109 } else {
110 $data .='/' . '**Initializes the application.' . "\n" .
111 "*/\n" .
112 "require_once('model/" . $this->relatedFiles['dbApplicationInitFile']->getFilename() . "');\n";
113 }
114
115 if (($primaryKeyColumn = $table->getPrimaryKeyColumn()) === false) {
116 $data .="/" . "*\n" .
117 "No primary key was defined!\n" .
118 "Without a primary key the RSDEngine cannot generate code to delete a single record!\n" .
119 "*/";
120 return "$data?>";
121 }
122
123 $data .="\n" .
124 "//to make sure the array fields are initialized\n" .
125 "if (!isset(\$_REQUEST['action'])) {\n" .
126 " \$_REQUEST['action'] = '';\n" .
127 "}\n" .
128 "if (!isset(\$_REQUEST['" . $primaryKeyColumn->getColumnNameForVariableName() . "'])) {\n" .
129 " \$_REQUEST['" . $primaryKeyColumn->getColumnNameForVariableName() . "'] = '';\n" .
130 "}\n" .
131 "\$error = null;\n" .
132 "\$${tableInstanceName} =& \$${appInstanceName}->getTable('$table->name');\n" .
133 "\n";
134
135 $data .="\$record = \$${tableInstanceName}->" . $table->getGetByPrimaryKeyMethodName() .
136 "(\$_REQUEST['" . $primaryKeyColumn->getColumnNameForVariableName() . "']);\n";
137
138 $data .="\n" .
139 "if(\$_REQUEST['action'] == 1){\n";
140 $data .=" \$error = \$${tableInstanceName}->" . $table->getDeleteByPrimaryKeyMethodName() .
141 "(\$_REQUEST['" . $primaryKeyColumn->getColumnNameForVariableName() . "']);\n";
142
143 $unsetStoredFiles = "";
144 reset($table->columns);
145 while (list($key, $column) = each($table->columns)) {
146 $columnName = $column->getColumnNameForVariableName();
147 $isValidFileOptions = $column->getIsValidFileOptions();
148 if ($isValidFileOptions != null) {
149 $unsetStoredFiles .= " \$${tableInstanceName}->" . $column->generateRemoveStoredMethodName() . "(\$record['$column->name']);\n";
150 }
151 }
152
153 $data .=' if (!PEAR::isError($error)) {' . "\n" .
154 "$unsetStoredFiles\n" .
155 " header('Location: " . $this->getControllerGetFilename() . "');\n" .
156 " exit;\n" .
157 " }\n" .
158 "}\n".
159 "\n";
160 $data .="\n" .
161 "if (!PEAR::isError(\$record)) {\n";
162
163 reset($table->columns);
164 while (list($key, $column) = each($table->columns)) {
165 $columnName = $column->getColumnNameForVariableName();
166 $data .= " \$${appInstanceName}->smarty->assign('$columnName',\$record['$column->name']);\n";
167 }
168 $data .="}\n" .
169 "\n";
170 $data .='$' . $appInstanceName . '->smarty->assign("error",PEAR::isError($error) || PEAR::isError($record) || $' . $appInstanceName . '->errorManager->errorsOccurred());' . "\n" .
171 "\n";
172
173 $data .="\$${appInstanceName}->smarty->display('" . $this->getTemplateFilename() . "');\n" .
174 "?>";
175 return $data;
176 }
177 }
178 ?>

Documentation generated on Mon, 8 Dec 2003 13:11:08 +0100 by phpDocumentor 1.2.3