Documentation is available at RSDEngineDBControllerFileGetOne.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 RSDEngineDBControllerFileGetOne.
20 *
21 * @package RSDEngine
22 * @author Lukas Feiler <lukas.feiler@chello.at>
23 * @copyright Lukas Feiler 2003
24 * @filesource
25 */
26
27 /**RSDEngineDBControllerFileGetOne extends RSDEngineControllerFile.
28 */
29 require_once('RSDEngine/RSDEngineControllerFile.php');
30
31 /**Generates the controller file for selecting one 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 RSDEngineDBControllerFileGetOne 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 "getOne" . 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 "getOne" . ucfirst($this->config['table']->getTableNameWithoutPrefix()) . ".tpl";
59 }
60
61 /**Returns the code for the controller file for selecting one 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 $authors = RSArrayUtil::toString(split("\n",$authors),"\n",'* @author %val');
71 $records = ucfirst($this->config['table']->getTableNameWithoutPrefix());
72 $tableInstanceName = $table->getChildClassInstanceName();
73 $appInstanceName = $this->relatedClasses['dbApplicationClass']->getInstanceName();
74 if(($primaryKeyColumn = $table->getPrimaryKeyColumn()) === false){
75 return "No primary key was defined! Without a primary key the RSDEngine cannot generate code to view a single record!\n";
76 }
77
78 $public = $table->getFileOptionProperty('getOneController', 'public');
79 $selectMethodName = $table->getFileOptionProperty('getOneController', 'selectMethodName');
80 $write = $table->getFileOptionProperty('getOneController', 'write');
81
82 $this->setWrite($write);
83
84 $data = '';
85 $data .="<?php\n" .
86 '/' . '**This file is the controller for selecting a single record from the table ' . $table->name . ".\n" .
87 '*' . "\n" .
88 $authors . "\n" .
89 '* @copyright ' . $copyright . "\n" .
90 '* @package ' . $projectName . "\n" .
91 '* @filesource' . "\n" .
92 '*/' . "\n" .
93 "\n";
94 if ($this->config['auth'] || $this->config['liveUser']) {
95 if ($public) {
96 $data .='/' . '**This controller requires no authentication.' . "\n" .
97 "*/\n" .
98 "require_once('model/" . $this->relatedFiles['dbApplicationPublicInitFile']->getFilename() . "');\n";
99 } else {
100 $data .='/' . '**This controller requires authentication.' . "\n" .
101 "*/\n" .
102 "require_once('model/" . $this->relatedFiles['dbApplicationPrivateInitFile']->getFilename() . "');\n";
103 }
104 } else {
105 $data .='/' . '**Initializes the application.' . "\n" .
106 "*/\n" .
107 "require_once('model/" . $this->relatedFiles['dbApplicationInitFile']->getFilename() . "');\n";
108 }
109 $data .="\n" .
110 "if (isset(\$_REQUEST['" . $primaryKeyColumn->getColumnNameForVariableName() . "'])) {\n" .
111 ' $' . $primaryKeyColumn->getColumnNameForVariableName() . " = \$_REQUEST['" . $primaryKeyColumn->getColumnNameForVariableName() . "'];\n" .
112 "} else {\n" .
113 ' $' . $primaryKeyColumn->getColumnNameForVariableName() . " = '';\n" .
114 "}\n" .
115 "\n" .
116 "\$${tableInstanceName} =& \$${appInstanceName}->getTable('$table->name');\n" .
117 "\n";
118 $data .="\$record = \$${tableInstanceName}->" . $table->getGetByPrimaryKeyMethodName() . "(\$" . $primaryKeyColumn->getColumnNameForVariableName() . ", '$selectMethodName');\n";
119
120 $data .='if(PEAR::isError($record)){' . "\n" .
121 " \$${appInstanceName}->smarty->assign('error', true);\n" .
122 " \$${appInstanceName}->smarty->assign('errorMsg', \$record->getMessage());\n" .
123 '}else{' . "\n";
124
125 $columns = $table->getSelectMethodColumns($selectMethodName);
126 while (list($key, $column) = each($columns)) {
127 $columnName = $column->getColumnNameForVariableName();
128 $data .= " \$${appInstanceName}->smarty->assign('$columnName',\$record['$column->name']);\n";
129 }
130
131 $data .="}\n" .
132 "\$${appInstanceName}->smarty->display('" . $this->getTemplateFilename() . "');\n" .
133 "?>";
134 return $data;
135 }
136 }
137 ?>
Documentation generated on Mon, 8 Dec 2003 13:11:09 +0100 by phpDocumentor 1.2.3