|
1
|
|
|
<?php |
|
|
|
|
|
|
2
|
|
|
|
|
3
|
|
|
/* |
|
4
|
|
|
You may not change or alter any portion of this comment or credits |
|
5
|
|
|
of supporting developers from this source code or any supporting source code |
|
6
|
|
|
which is considered copyrighted (c) material of the original comment or credit authors. |
|
7
|
|
|
|
|
8
|
|
|
This program is distributed in the hope that it will be useful, |
|
9
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
10
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
|
11
|
|
|
*/ |
|
12
|
|
|
/** |
|
13
|
|
|
* tdmcreate module. |
|
14
|
|
|
* |
|
15
|
|
|
* @copyright The XOOPS Project http://sourceforge.net/projects/xoops/ |
|
16
|
|
|
* @license GNU GPL 2 (http://www.gnu.org/licenses/old-licenses/gpl-2.0.html) |
|
17
|
|
|
* |
|
18
|
|
|
* @since 2.5.0 |
|
19
|
|
|
* |
|
20
|
|
|
* @author Txmod Xoops http://www.txmodxoops.org |
|
21
|
|
|
* |
|
22
|
|
|
* @version $Id: UserRate.php 12258 2014-01-02 09:33:29Z timgno $ |
|
23
|
|
|
*/ |
|
24
|
|
|
defined('XOOPS_ROOT_PATH') || die('Restricted access'); |
|
25
|
|
|
|
|
26
|
|
|
/** |
|
27
|
|
|
* Class UserRate. |
|
28
|
|
|
*/ |
|
29
|
|
|
class UserRate extends TDMCreateFile |
|
|
|
|
|
|
30
|
|
|
{ |
|
31
|
|
|
/* |
|
32
|
|
|
* @var mixed |
|
33
|
|
|
*/ |
|
34
|
|
|
private $usercode = null; |
|
35
|
|
|
|
|
36
|
|
|
/* |
|
37
|
|
|
* @var mixed |
|
38
|
|
|
*/ |
|
39
|
|
|
private $phpcode = null; |
|
40
|
|
|
|
|
41
|
|
|
/* |
|
42
|
|
|
* @var string |
|
43
|
|
|
*/ |
|
44
|
|
|
private $xoopscode; |
|
45
|
|
|
|
|
46
|
|
|
/* |
|
47
|
|
|
* @public function constructor |
|
48
|
|
|
* @param null |
|
49
|
|
|
*/ |
|
50
|
|
|
/** |
|
51
|
|
|
* |
|
52
|
|
|
*/ |
|
53
|
|
|
public function __construct() |
|
54
|
|
|
{ |
|
55
|
|
|
parent::__construct(); |
|
56
|
|
|
$this->xoopscode = TDMCreateXoopsCode::getInstance(); |
|
|
|
|
|
|
57
|
|
|
$this->phpcode = TDMCreatePhpCode::getInstance(); |
|
58
|
|
|
$this->usercode = UserXoopsCode::getInstance(); |
|
59
|
|
|
} |
|
60
|
|
|
|
|
61
|
|
|
/* |
|
62
|
|
|
* @static function &getInstance |
|
63
|
|
|
* @param null |
|
64
|
|
|
*/ |
|
65
|
|
|
/** |
|
66
|
|
|
* @return UserRate |
|
67
|
|
|
*/ |
|
68
|
|
|
public static function &getInstance() |
|
69
|
|
|
{ |
|
70
|
|
|
static $instance = false; |
|
71
|
|
|
if (!$instance) { |
|
72
|
|
|
$instance = new self(); |
|
73
|
|
|
} |
|
74
|
|
|
|
|
75
|
|
|
return $instance; |
|
76
|
|
|
} |
|
77
|
|
|
|
|
78
|
|
|
/* |
|
79
|
|
|
* @public function write |
|
80
|
|
|
* @param string $module |
|
81
|
|
|
* @param mixed $table |
|
82
|
|
|
* @param string $filename |
|
83
|
|
|
*/ |
|
84
|
|
|
/** |
|
85
|
|
|
* @param $module |
|
86
|
|
|
* @param $table |
|
87
|
|
|
* @param $filename |
|
88
|
|
|
*/ |
|
89
|
|
|
public function write($module, $table, $filename) |
|
90
|
|
|
{ |
|
91
|
|
|
$this->setModule($module); |
|
92
|
|
|
$this->setTable($table); |
|
93
|
|
|
$this->setFileName($filename); |
|
94
|
|
|
} |
|
95
|
|
|
|
|
96
|
|
|
/** |
|
97
|
|
|
* @private function getUserRateHeader |
|
98
|
|
|
* |
|
99
|
|
|
* @param $moduleDirname |
|
100
|
|
|
* @param $tableName |
|
101
|
|
|
* |
|
102
|
|
|
* @return string |
|
103
|
|
|
*/ |
|
104
|
|
|
public function getUserRateHeader($moduleDirname, $tableName) |
|
105
|
|
|
{ |
|
106
|
|
|
$ret = $this->getInclude(); |
|
107
|
|
|
$ret .= $this->xoopscode->getXoopsCodeXoopsRequest('op', 'op', 'form'); |
|
|
|
|
|
|
108
|
|
|
$ret .= $this->xoopscode->getXoopsCodeXoopsRequest('lid', 'lid', '', 'Int'); |
|
|
|
|
|
|
109
|
|
|
$ret .= $this->usercode->getUserTplMain($moduleDirname, $tableName); |
|
110
|
|
|
$ret .= $this->phpcode->getPhpCodeIncludeDir('XOOPS_ROOT_PATH', 'header', true); |
|
111
|
|
|
$ret .= $this->getCommentLine('Define Stylesheet'); |
|
112
|
|
|
$ret .= $this->xoopscode->getXoopsCodeAddStylesheet(); |
|
|
|
|
|
|
113
|
|
|
|
|
114
|
|
|
return $ret; |
|
115
|
|
|
} |
|
116
|
|
|
|
|
117
|
|
|
/* |
|
118
|
|
|
* @private function getUserRateSwitch |
|
119
|
|
|
* @param $moduleDirname |
|
120
|
|
|
* @param $tableId |
|
121
|
|
|
* @param $tableMid |
|
122
|
|
|
* @param $tableName |
|
123
|
|
|
* @param $tableSoleName |
|
124
|
|
|
* @param $language |
|
125
|
|
|
* |
|
126
|
|
|
* @return string |
|
127
|
|
|
*/ |
|
128
|
|
View Code Duplication |
private function getUserRateSwitch($moduleDirname, $tableId, $tableMid, $tableName, $tableSoleName, $language) |
|
|
|
|
|
|
129
|
|
|
{ |
|
130
|
|
|
$fields = $this->getTableFields($tableMid, $tableId); |
|
131
|
|
|
$cases = array('form' => array($this->getUserRateForm($tableName, $language)), |
|
132
|
|
|
'save' => array($this->getUserRateSave($moduleDirname, $fields, $tableName, $language)), ); |
|
133
|
|
|
|
|
134
|
|
|
return $this->xoopscode->getXoopsCodeSwitch('op', $cases, true); |
|
|
|
|
|
|
135
|
|
|
} |
|
136
|
|
|
|
|
137
|
|
|
/* |
|
138
|
|
|
* @public function getAdminPagesList |
|
139
|
|
|
* @param $tableName |
|
140
|
|
|
* @param $language |
|
141
|
|
|
* |
|
142
|
|
|
* @return string |
|
143
|
|
|
*/ |
|
144
|
|
View Code Duplication |
public function getUserRateForm($tableName, $language) |
|
|
|
|
|
|
145
|
|
|
{ |
|
146
|
|
|
$ret = $this->getCommentLine('Mavigation'); |
|
147
|
|
|
$ret .= $this->xoopscode->getXoopsCodeEqualsOperator('$navigation', "{$language}RATE"); |
|
|
|
|
|
|
148
|
|
|
$ret .= $this->xoopscode->getXoopsCodeTplAssign('navigation', '$navigation'); |
|
|
|
|
|
|
149
|
|
|
$ret .= $this->getCommentLine('Title of page'); |
|
150
|
|
|
$ret .= $this->xoopscode->getXoopsCodeEqualsOperator('$title', "{$language}RATE . ' - '"); |
|
|
|
|
|
|
151
|
|
|
$ret .= $this->xoopscode->getXoopsCodeEqualsOperator('$title.', "\$GLOBALS['xoopsModule']->name()"); |
|
|
|
|
|
|
152
|
|
|
$ret .= $this->xoopscode->getXoopsCodeTplAssign('xoops_pagetitle', '$title'); |
|
|
|
|
|
|
153
|
|
|
$ret .= $this->getCommentLine('Description'); |
|
154
|
|
|
$ret .= $this->usercode->getUserAddMeta('description', $language, 'RATE'); |
|
155
|
|
|
$ret .= $this->getCommentLine('Form Create'); |
|
156
|
|
|
$ret .= $this->xoopscode->getXoopsCodeObjHandlerCreate($tableName); |
|
|
|
|
|
|
157
|
|
|
$ret .= $this->xoopscode->getXoopsCodeGetForm('form', $tableName, 'Obj'); |
|
|
|
|
|
|
158
|
|
|
$ret .= $this->xoopscode->getXoopsCodeTplAssign('form', '$form->render()'); |
|
|
|
|
|
|
159
|
|
|
|
|
160
|
|
|
return $ret; |
|
161
|
|
|
} |
|
162
|
|
|
|
|
163
|
|
|
/* |
|
164
|
|
|
* @public function getUserRateSave |
|
165
|
|
|
* @param string $moduleDirname |
|
166
|
|
|
* @param string $tableName |
|
167
|
|
|
*/ |
|
168
|
|
|
/** |
|
169
|
|
|
* @param $moduleDirname |
|
170
|
|
|
* @param $table_id |
|
171
|
|
|
* @param $tableName |
|
172
|
|
|
* |
|
173
|
|
|
* @return string |
|
174
|
|
|
*/ |
|
175
|
|
View Code Duplication |
public function getUserRateSave($moduleDirname, $fields, $tableName, $language) |
|
|
|
|
|
|
176
|
|
|
{ |
|
177
|
|
|
$ucfTableName = ucfirst($tableName); |
|
|
|
|
|
|
178
|
|
|
$ret = $this->phpcode->getPhpCodeCommentLine('Security Check'); |
|
179
|
|
|
$xoopsSecurityCheck = $this->xoopscode->getXoopsCodeSecurityCheck(); |
|
|
|
|
|
|
180
|
|
|
$securityError = $this->xoopscode->getXoopsCodeSecurityErrors(); |
|
|
|
|
|
|
181
|
|
|
$implode = $this->phpcode->getPhpCodeImplode(',', $securityError); |
|
182
|
|
|
$redirectError = $this->xoopscode->getXoopsCodeRedirectHeader($tableName, '', '3', $implode); |
|
|
|
|
|
|
183
|
|
|
$ret .= $this->phpcode->getPhpCodeConditions($xoopsSecurityCheck, '', '', $redirectError, false, "\t"); |
|
184
|
|
|
$ret .= $this->xoopscode->getXoopsCodeObjHandlerCreate($tableName); |
|
|
|
|
|
|
185
|
|
|
|
|
186
|
|
|
$ret .= $this->xoopscode->getXoopsCodeSaveElements($moduleDirname, $tableName, $fields); |
|
|
|
|
|
|
187
|
|
|
|
|
188
|
|
|
$ret .= $this->getCommentLine('Insert Data'); |
|
189
|
|
|
$insert = $this->xoopscode->getXoopsCodeInsert($tableName, $tableName, 'Obj', true); |
|
|
|
|
|
|
190
|
|
|
$confirmOk = $this->xoopscode->getXoopsCodeRedirectHeader('index', '', '2', "{$language}FORM_OK"); |
|
|
|
|
|
|
191
|
|
|
$ret .= $this->phpcode->getPhpCodeConditions($insert, '', '', $confirmOk, false, "\t"); |
|
192
|
|
|
|
|
193
|
|
|
$ret .= $this->getCommentLine('Get Form Error'); |
|
194
|
|
|
$ret .= $this->xoopscode->getXoopsCodeTplAssign('error', "\${$tableName}Obj->getHtmlErrors()"); |
|
|
|
|
|
|
195
|
|
|
$ret .= $this->xoopscode->getXoopsCodeGetForm('form', $tableName, 'Obj'); |
|
|
|
|
|
|
196
|
|
|
$ret .= $this->xoopscode->getXoopsCodeTplAssign('form', '$form->display()'); |
|
|
|
|
|
|
197
|
|
|
|
|
198
|
|
|
return $ret; |
|
199
|
|
|
} |
|
200
|
|
|
|
|
201
|
|
|
/* |
|
202
|
|
|
* @public function getUserRateFooter |
|
203
|
|
|
* @param null |
|
204
|
|
|
*/ |
|
205
|
|
|
/** |
|
206
|
|
|
* @return string |
|
207
|
|
|
*/ |
|
208
|
|
View Code Duplication |
public function getUserRateFooter($moduleDirname, $language) |
|
|
|
|
|
|
209
|
|
|
{ |
|
210
|
|
|
$stuModuleDirname = strtoupper($moduleDirname); |
|
|
|
|
|
|
211
|
|
|
$ret = $this->getCommentLine('Breadcrumbs'); |
|
212
|
|
|
$ret .= $this->usercode->getUserBreadcrumbs('RATE', $language); |
|
213
|
|
|
$ret .= $this->getInclude('footer'); |
|
214
|
|
|
|
|
215
|
|
|
return $ret; |
|
216
|
|
|
} |
|
217
|
|
|
|
|
218
|
|
|
/* |
|
219
|
|
|
* @public function render |
|
220
|
|
|
* @param null |
|
221
|
|
|
*/ |
|
222
|
|
|
/** |
|
223
|
|
|
* @return bool|string |
|
224
|
|
|
*/ |
|
225
|
|
View Code Duplication |
public function render() |
|
|
|
|
|
|
226
|
|
|
{ |
|
227
|
|
|
$module = $this->getModule(); |
|
228
|
|
|
$table = $this->getTable(); |
|
229
|
|
|
$filename = $this->getFileName(); |
|
230
|
|
|
$moduleDirname = $module->getVar('mod_dirname'); |
|
231
|
|
|
$tableId = $table->getVar('table_id'); |
|
232
|
|
|
$tableMid = $table->getVar('table_mid'); |
|
233
|
|
|
$tableName = $table->getVar('table_name'); |
|
234
|
|
|
$tableSoleName = $table->getVar('table_solename'); |
|
235
|
|
|
$fields = $this->getTableFields($tableMid, $tableId); |
|
|
|
|
|
|
236
|
|
|
$language = $this->getLanguage($moduleDirname, 'MA'); |
|
237
|
|
|
$content = $this->getHeaderFilesComments($module, $filename); |
|
238
|
|
|
$content .= $this->getUserRateHeader($moduleDirname, $tableName); |
|
239
|
|
|
$content .= $this->getUserRateSwitch($moduleDirname, $tableId, $tableMid, $tableName, $tableSoleName, $language); |
|
240
|
|
|
$content .= $this->getUserRateFooter($moduleDirname, $language); |
|
241
|
|
|
|
|
242
|
|
|
$this->create($moduleDirname, '/', $filename, $content, _AM_TDMCREATE_FILE_CREATED, _AM_TDMCREATE_FILE_NOTCREATED); |
|
243
|
|
|
|
|
244
|
|
|
return $this->renderFile(); |
|
245
|
|
|
} |
|
246
|
|
|
} |
|
247
|
|
|
|
The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.
The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.
To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.