Source for file RSDEngineDBControllerFileGetStored.php

Documentation is available at RSDEngineDBControllerFileGetStored.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 RSDEngineDBControllerFileGetStored.
20 *
21 * @package RSDEngine
22 * @author Lukas Feiler <lukas.feiler@chello.at>
23 * @copyright Lukas Feiler 2003
24 * @filesource
25 */
26
27 /**RSDEngineDBControllerFileGetStored 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 RSDEngineDBControllerFileGetStored 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 "getStored" . ucfirst($this->config['table']->getTableNameWithoutPrefix()) . ucfirst($this->config['column']->getColumnNameForVariableName()) . ".php";
51 }
52
53 /**Returns the code for the controller file for viewing the contents of the one column of a singel record of a table.
54 *
55 * @access private
56 * @return String The code for the file.
57 */
58 function getCode()
59 {
60 extract($this->config);
61 $table =& $this->config['table'];
62 $authors = RSArrayUtil::toString(split("\n",$authors),"\n",'* @author %val');
63 $records = ucfirst($this->config['table']->getTableNameWithoutPrefix());
64 $tableInstanceName = $table->getChildClassInstanceName();
65 $appInstanceName = $this->relatedClasses['dbApplicationClass']->getInstanceName();
66 if (($primaryKeyColumn = $table->getPrimaryKeyColumn()) === false){
67 return "No primary key was defined! Without a primary key the RSDEngine cannot generate code to view a single record!\n";
68 }
69 if (($isValidFileOptions = $column->getIsValidFileOptions()) == null) {
70 return '$config["column"] was not defined as isValid:file; $config["column"]->getIsValidFileOptions() returned null!\n';
71 }
72
73 $public = $table->getFileOptionProperty('getOneController', 'public');
74 $write = $table->getFileOptionProperty('getOneController', 'write');
75
76 $this->setWrite($write);
77
78 $data = '';
79 $data .="<?php\n" .
80 '/' . "**This file is the controller for viewing the contents of the column $column->name of a single record of the table $table->name.\n" .
81 '*' . "\n" .
82 '* There is no corresponding template file.' . "\n" .
83 '*' . "\n" .
84 $authors . "\n" .
85 '* @copyright ' . $copyright . "\n" .
86 '* @package ' . $projectName . "\n" .
87 '* @filesource' . "\n" .
88 '*/' . "\n" .
89 "\n";
90 if ($this->config['auth'] || $this->config['liveUser']) {
91 if ($public) {
92 $data .='/' . '**This controller requires no authentication.' . "\n" .
93 "*/\n" .
94 "require_once('model/" . $this->relatedFiles['dbApplicationPublicInitFile']->getFilename() . "');\n";
95 } else {
96 $data .='/' . '**This controller requires authentication.' . "\n" .
97 "*/\n" .
98 "require_once('model/" . $this->relatedFiles['dbApplicationPrivateInitFile']->getFilename() . "');\n";
99 }
100 } else {
101 $data .='/' . '**Initializes the application.' . "\n" .
102 "*/\n" .
103 "require_once('model/" . $this->relatedFiles['dbApplicationInitFile']->getFilename() . "');\n";
104 }
105 $data .="\n" .
106 '$' . $primaryKeyColumn->getColumnNameForVariableName() . " = \$_REQUEST['" . $primaryKeyColumn->getColumnNameForVariableName() . "'];\n" .
107 "\n" .
108 "\$${tableInstanceName} =& \$${appInstanceName}->getTable('$table->name');\n" .
109 "\n";
110 $data .="\$record = \$${tableInstanceName}->" . $table->getGetByPrimaryKeyMethodName() . "(\$" . $primaryKeyColumn->getColumnNameForVariableName() . ");\n";
111
112 $data .='if(!PEAR::isError($record)){' . "\n" .
113 " \$contents = \$${tableInstanceName}->" . $column->generateGetStoredMethodName() . "(\$record['$column->name']);\n" .
114 " if (!PEAR::isError(\$contents)) {\n" .
115 " echo \$contents;\n" .
116 " exit;\n" .
117 " }\n" .
118 "}\n";
119
120 $data .="if (file_exists(" . $isValidFileOptions['defaultFileConstant'] . ")) {\n" .
121 " require_once('RSIO/RSIO.php');\n" .
122 " echo RSIO::getFileContents(" . $isValidFileOptions['defaultFileConstant'] . ");\n" .
123 "} else {\n" .
124 " echo 'The requested resource is not available.';\n" .
125 "}\n" .
126 "\n?>";
127 return $data;
128 }
129 }
130 ?>

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