|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace XoopsModules\Modulebuilder\Files\User; |
|
4
|
|
|
|
|
5
|
|
|
use XoopsModules\Modulebuilder; |
|
6
|
|
|
use XoopsModules\Modulebuilder\Files; |
|
7
|
|
|
|
|
8
|
|
|
/* |
|
9
|
|
|
You may not change or alter any portion of this comment or credits |
|
10
|
|
|
of supporting developers from this source code or any supporting source code |
|
11
|
|
|
which is considered copyrighted (c) material of the original comment or credit authors. |
|
12
|
|
|
|
|
13
|
|
|
This program is distributed in the hope that it will be useful, |
|
14
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
15
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
|
16
|
|
|
*/ |
|
17
|
|
|
/** |
|
18
|
|
|
* modulebuilder module. |
|
19
|
|
|
* |
|
20
|
|
|
* @copyright XOOPS Project (https://xoops.org) |
|
21
|
|
|
* @license GNU GPL 2 (http://www.gnu.org/licenses/old-licenses/gpl-2.0.html) |
|
22
|
|
|
* |
|
23
|
|
|
* @since 2.5.0 |
|
24
|
|
|
* |
|
25
|
|
|
* @author Txmod Xoops http://www.txmodxoops.org |
|
26
|
|
|
* |
|
27
|
|
|
*/ |
|
28
|
|
|
|
|
29
|
|
|
/** |
|
30
|
|
|
* Class UserIndex. |
|
31
|
|
|
*/ |
|
32
|
|
|
class UserIndex extends Files\CreateFile |
|
33
|
|
|
{ |
|
34
|
|
|
/** |
|
35
|
|
|
* @var mixed |
|
36
|
|
|
*/ |
|
37
|
|
|
private $uxc = null; |
|
38
|
|
|
|
|
39
|
|
|
/** |
|
40
|
|
|
* @var mixed |
|
41
|
|
|
*/ |
|
42
|
|
|
private $xc = null; |
|
43
|
|
|
|
|
44
|
|
|
/** |
|
45
|
|
|
* @var mixed |
|
46
|
|
|
*/ |
|
47
|
|
|
private $pc = null; |
|
48
|
|
|
|
|
49
|
|
|
/** |
|
50
|
|
|
* @public function constructor |
|
51
|
|
|
* @param null |
|
52
|
|
|
*/ |
|
53
|
|
|
public function __construct() |
|
54
|
|
|
{ |
|
55
|
|
|
parent::__construct(); |
|
56
|
|
|
$this->xc = Modulebuilder\Files\CreateXoopsCode::getInstance(); |
|
57
|
|
|
$this->pc = Modulebuilder\Files\CreatePhpCode::getInstance(); |
|
58
|
|
|
$this->uxc = Modulebuilder\Files\User\UserXoopsCode::getInstance(); |
|
59
|
|
|
} |
|
60
|
|
|
|
|
61
|
|
|
/** |
|
62
|
|
|
* @static function getInstance |
|
63
|
|
|
* @param null |
|
64
|
|
|
* @return UserIndex |
|
65
|
|
|
*/ |
|
66
|
|
|
public static function getInstance() |
|
67
|
|
|
{ |
|
68
|
|
|
static $instance = false; |
|
69
|
|
|
if (!$instance) { |
|
70
|
|
|
$instance = new self(); |
|
71
|
|
|
} |
|
72
|
|
|
|
|
73
|
|
|
return $instance; |
|
74
|
|
|
} |
|
75
|
|
|
|
|
76
|
|
|
/** |
|
77
|
|
|
* @public function write |
|
78
|
|
|
* @param string $module |
|
79
|
|
|
* @param $table |
|
80
|
|
|
* @param string $filename |
|
81
|
|
|
*/ |
|
82
|
|
|
public function write($module, $table, $filename) |
|
83
|
|
|
{ |
|
84
|
|
|
$this->setModule($module); |
|
85
|
|
|
$this->setTable($table); |
|
86
|
|
|
$this->setFileName($filename); |
|
87
|
|
|
} |
|
88
|
|
|
|
|
89
|
|
|
/** |
|
90
|
|
|
* @private function getUserIndexHeader |
|
91
|
|
|
* @param $language |
|
92
|
|
|
* @param $moduleDirname |
|
93
|
|
|
* |
|
94
|
|
|
* @return string |
|
95
|
|
|
*/ |
|
96
|
|
|
private function getUserIndexHeader($language, $moduleDirname) |
|
97
|
|
|
{ |
|
98
|
|
|
$stuModuleDirname = \mb_strtoupper($moduleDirname); |
|
99
|
|
|
|
|
100
|
|
|
$ret = $this->getInclude(); |
|
101
|
|
|
$ret .= $this->uxc->getUserTplMain($moduleDirname); |
|
102
|
|
|
$ret .= $this->pc->getPhpCodeIncludeDir('XOOPS_ROOT_PATH', 'header', true); |
|
103
|
|
|
$ret .= $this->pc->getPhpCodeCommentLine('Define Stylesheet'); |
|
104
|
|
|
$ret .= $this->xc->getXcXoThemeAddStylesheet(); |
|
105
|
|
|
$ret .= $this->pc->getPhpCodeCommentLine('Keywords'); |
|
106
|
|
|
$ret .= $this->pc->getPhpCodeArray('keywords', null, false, ''); |
|
107
|
|
|
$ret .= $this->uxc->getUserBreadcrumbs($language); |
|
108
|
|
|
$ret .= $this->pc->getPhpCodeCommentLine('Paths'); |
|
109
|
|
|
$ret .= $this->xc->getXcXoopsTplAssign('xoops_icons32_url', 'XOOPS_ICONS32_URL'); |
|
110
|
|
|
$ret .= $this->xc->getXcXoopsTplAssign("{$moduleDirname}_url", "{$stuModuleDirname}_URL"); |
|
111
|
|
|
|
|
112
|
|
|
return $ret; |
|
113
|
|
|
} |
|
114
|
|
|
|
|
115
|
|
|
/** |
|
116
|
|
|
* @private function getBodyCategoriesIndex |
|
117
|
|
|
* @param $tableMid |
|
118
|
|
|
* @param $tableId |
|
119
|
|
|
* @param $tableName |
|
120
|
|
|
* @param $tableSoleName |
|
121
|
|
|
* @param $tableFieldname |
|
122
|
|
|
* @return string |
|
123
|
|
|
*/ |
|
124
|
|
|
private function getBodyCategoriesIndex($tableMid, $tableId, $tableName, $tableSoleName, $tableFieldname) |
|
125
|
|
|
{ |
|
126
|
|
|
// Fields |
|
127
|
|
|
$fields = $this->getTableFields($tableMid, $tableId); |
|
128
|
|
|
$fieldParentId = []; |
|
129
|
|
|
foreach (\array_keys($fields) as $f) { |
|
130
|
|
|
$fieldParentId[] = $fields[$f]->getVar('field_parent'); |
|
131
|
|
|
} |
|
132
|
|
|
$ret = ''; |
|
133
|
|
|
if (\in_array(1, $fieldParentId)) { |
|
134
|
|
|
$ret .= $this->xc->getXcHandlerCountObj($tableName); |
|
135
|
|
|
$ret .= $this->pc->getPhpCodeCommentLine('If there are ', $tableName); |
|
136
|
|
|
$ret .= $this->getSimpleString('$count = 1;'); |
|
137
|
|
|
|
|
138
|
|
|
$contentIf = $this->xc->getXcHandlerAllObj($tableName, '', 0, 0, "\t"); |
|
139
|
|
|
$contentIf .= $this->pc->getPhpCodeIncludeDir('XOOPS_ROOT_PATH', 'class/tree', true, false, 'include', "\t"); |
|
140
|
|
|
//$contentIf .= $cc->getClassXoopsObjectTree('mytree', $tableName, $fieldId, $fieldParent, "\t"); |
|
141
|
|
|
$contentIf .= $this->pc->getPhpCodeArray($tableName, "\t"); |
|
142
|
|
|
$foreach = $this->xc->getXcGetValues($tableName, $tableSoleName . 'Values', $tableFieldname, false, "\t\t"); |
|
143
|
|
|
$foreach .= $this->pc->getPhpCodeArray('acount', ["'count'", '$count']); |
|
144
|
|
|
$foreach .= $this->pc->getPhpCodeArrayType($tableName, 'merge', $tableSoleName . 'Values', '$acount'); |
|
145
|
|
|
$foreach .= $this->getSimpleString('++$count;', "\t\t"); |
|
146
|
|
|
$contentIf .= $this->pc->getPhpCodeForeach("{$tableName}All", true, false, $tableFieldname, $foreach, "\t"); |
|
147
|
|
|
$contentIf .= $this->xc->getXcXoopsTplAssign($tableName, '$' . $tableName, true, "\t"); |
|
148
|
|
|
$contentIf .= $this->pc->getPhpCodeUnset($tableName, "\t"); |
|
149
|
|
|
$getConfig = $this->xc->getXcGetConfig('numb_col'); |
|
150
|
|
|
$contentIf .= $this->xc->getXcXoopsTplAssign('numb_col', $getConfig, true, "\t"); |
|
151
|
|
|
$ret .= $this->pc->getPhpCodeConditions("\${$tableName}Count", ' > ', '0', $contentIf, false); |
|
152
|
|
|
$ret .= $this->pc->getPhpCodeUnset('count'); |
|
153
|
|
|
} |
|
154
|
|
|
unset($fieldParentId); |
|
155
|
|
|
|
|
156
|
|
|
return $ret; |
|
157
|
|
|
} |
|
158
|
|
|
|
|
159
|
|
|
/** |
|
160
|
|
|
* @private function getBodyPagesIndex |
|
161
|
|
|
* @param $moduleDirname |
|
162
|
|
|
* @param $tableName |
|
163
|
|
|
* @param $tableSoleName |
|
164
|
|
|
* @param $language |
|
165
|
|
|
* @return string |
|
166
|
|
|
*/ |
|
167
|
|
|
private function getBodyPagesIndex($moduleDirname, $tableName, $tableSoleName, $language) |
|
|
|
|
|
|
168
|
|
|
{ |
|
169
|
|
|
$ucfTableName = \ucfirst($tableName); |
|
170
|
|
|
$table = $this->getTable(); |
|
171
|
|
|
$fields = $this->getTableFields($table->getVar('table_mid'), $table->getVar('table_id')); |
|
172
|
|
|
|
|
173
|
|
|
$ret = $this->pc->getPhpCodeCommentLine('Tables'); |
|
174
|
|
|
$ret .= $this->xc->getXcHandlerCountObj($tableName); |
|
175
|
|
|
$ret .= $this->xc->getXcXoopsTplAssign($tableName . 'Count', "\${$tableName}Count"); |
|
176
|
|
|
$ret .= $this->getSimpleString('$count = 1;'); |
|
177
|
|
|
$condIf = $this->xc->getXcXoopsRequest('start', 'start', '0', 'Int', false, "\t"); |
|
178
|
|
|
$userpager = $this->xc->getXcGetConfig('userpager'); |
|
179
|
|
|
$condIf .= $this->xc->getXcXoopsRequest('limit', 'limit', $userpager, 'Int', false, "\t"); |
|
180
|
|
|
$condIf .= $this->xc->getXcHandlerAllObj($tableName, '', '$start', '$limit', "\t"); |
|
181
|
|
|
$condIf .= $this->pc->getPhpCodeCommentLine('Get All', $ucfTableName, "\t"); |
|
182
|
|
|
$condIf .= $this->pc->getPhpCodeArray($tableName, null, false, "\t"); |
|
183
|
|
|
$foreach = $this->xc->getXcGetValues($tableName, $tableSoleName, 'i', false, "\t\t"); |
|
184
|
|
|
$foreach .= $this->pc->getPhpCodeArray('acount', ["'count'", '$count']); |
|
185
|
|
|
$foreach .= $this->pc->getPhpCodeArrayType($tableName, 'merge', $tableSoleName, '$acount'); |
|
186
|
|
|
// Fields |
|
187
|
|
|
$fieldMain = ''; |
|
188
|
|
|
foreach (\array_keys($fields) as $f) { |
|
189
|
|
|
$fieldName = $fields[$f]->getVar('field_name'); |
|
190
|
|
|
if (1 == $fields[$f]->getVar('field_main')) { |
|
191
|
|
|
$fieldMain = $fieldName; // fieldMain = fields parameters main field |
|
192
|
|
|
} |
|
193
|
|
|
} |
|
194
|
|
|
$foreach .= $this->xc->getXcGetVar('keywords[]', "{$tableName}All[\$i]", $fieldMain, false, "\t\t"); |
|
195
|
|
|
$foreach .= $this->getSimpleString('++$count;', "\t\t"); |
|
196
|
|
|
$condIf .= $this->pc->getPhpCodeForeach("{$tableName}All", true, false, 'i', $foreach, "\t"); |
|
197
|
|
|
$condIf .= $this->xc->getXcXoopsTplAssign($tableName, '$' . $tableName, true, "\t"); |
|
198
|
|
|
$condIf .= $this->pc->getPhpCodeUnset($tableName, "\t"); |
|
199
|
|
|
$condIf .= $this->xc->getXcPageNav($tableName, "\t"); |
|
200
|
|
|
$thereare = $this->pc->getPhpCodeSprintf("{$language}INDEX_THEREARE", "\${$tableName}Count"); |
|
201
|
|
|
$condIf .= $this->xc->getXcXoopsTplAssign('lang_thereare', $thereare, true, "\t"); |
|
202
|
|
|
$divideby = $this->xc->getXcGetConfig('divideby'); |
|
203
|
|
|
$condIf .= $this->xc->getXcXoopsTplAssign('divideby', $divideby, true, "\t"); |
|
204
|
|
|
$numb_col = $this->xc->getXcGetConfig('numb_col'); |
|
205
|
|
|
$condIf .= $this->xc->getXcXoopsTplAssign('numb_col', $numb_col, true, "\t"); |
|
206
|
|
|
$ret .= $this->pc->getPhpCodeConditions("\${$tableName}Count", ' > ', '0', $condIf); |
|
207
|
|
|
$ret .= $this->pc->getPhpCodeUnset('count'); |
|
208
|
|
|
$tableType = $this->xc->getXcGetConfig('table_type'); |
|
209
|
|
|
$ret .= $this->xc->getXcXoopsTplAssign('table_type', $tableType); |
|
210
|
|
|
|
|
211
|
|
|
return $ret; |
|
212
|
|
|
} |
|
213
|
|
|
|
|
214
|
|
|
/** |
|
215
|
|
|
* @private function getUserPagesFooter |
|
216
|
|
|
* @param $moduleDirname |
|
217
|
|
|
* @param $language |
|
218
|
|
|
* @return string |
|
219
|
|
|
*/ |
|
220
|
|
|
private function getUserIndexFooter($moduleDirname, $language) |
|
221
|
|
|
{ |
|
222
|
|
|
$stuModuleDirname = \mb_strtoupper($moduleDirname); |
|
223
|
|
|
$ret = $this->pc->getPhpCodeCommentLine('Keywords'); |
|
224
|
|
|
$ret .= $this->uxc->getUserMetaKeywords($moduleDirname); |
|
225
|
|
|
$ret .= $this->pc->getPhpCodeUnset('keywords'); |
|
226
|
|
|
$ret .= $this->pc->getPhpCodeCommentLine('Description'); |
|
227
|
|
|
$ret .= $this->uxc->getUserMetaDesc($moduleDirname, $language); |
|
228
|
|
|
$ret .= $this->xc->getXcXoopsTplAssign('xoops_mpageurl', "{$stuModuleDirname}_URL.'/index.php'"); |
|
229
|
|
|
$ret .= $this->xc->getXcXoopsTplAssign('xoops_icons32_url', 'XOOPS_ICONS32_URL'); |
|
230
|
|
|
$ret .= $this->xc->getXcXoopsTplAssign("{$moduleDirname}_upload_url", "{$stuModuleDirname}_UPLOAD_URL"); |
|
231
|
|
|
$ret .= $this->getInclude('footer'); |
|
232
|
|
|
|
|
233
|
|
|
return $ret; |
|
234
|
|
|
} |
|
235
|
|
|
|
|
236
|
|
|
/** |
|
237
|
|
|
* @public function render |
|
238
|
|
|
* @param null |
|
239
|
|
|
* @return bool|string |
|
240
|
|
|
*/ |
|
241
|
|
|
public function render() |
|
242
|
|
|
{ |
|
243
|
|
|
$module = $this->getModule(); |
|
244
|
|
|
$tables = $this->getTableTables($module->getVar('mod_id'), 'table_order'); |
|
245
|
|
|
$filename = $this->getFileName(); |
|
246
|
|
|
$moduleDirname = $module->getVar('mod_dirname'); |
|
247
|
|
|
$language = $this->getLanguage($moduleDirname, 'MA'); |
|
248
|
|
|
|
|
249
|
|
|
$content = $this->getHeaderFilesComments($module, null); |
|
250
|
|
|
$content .= $this->pc->getPhpCodeUseNamespace(['Xmf', 'Request'], '', ''); |
|
251
|
|
|
$content .= $this->pc->getPhpCodeUseNamespace(['XoopsModules', $moduleDirname], '', ''); |
|
252
|
|
|
$content .= $this->pc->getPhpCodeUseNamespace(['XoopsModules', $moduleDirname, 'Constants']); |
|
253
|
|
|
$content .= $this->getUserIndexHeader($language, $moduleDirname); |
|
254
|
|
|
|
|
255
|
|
|
foreach (\array_keys($tables) as $t) { |
|
256
|
|
|
$tableId = $tables[$t]->getVar('table_id'); |
|
257
|
|
|
$tableMid = $tables[$t]->getVar('table_mid'); |
|
258
|
|
|
$tableName = $tables[$t]->getVar('table_name'); |
|
259
|
|
|
$tableSoleName = $tables[$t]->getVar('table_solename'); |
|
260
|
|
|
$tableCategory = $tables[$t]->getVar('table_category'); |
|
261
|
|
|
$tableFieldname = $tables[$t]->getVar('table_fieldname'); |
|
262
|
|
|
$tableIndex = $tables[$t]->getVar('table_index'); |
|
263
|
|
|
if (1 == $tableCategory && 1 == $tableIndex) { |
|
264
|
|
|
$content .= $this->getBodyCategoriesIndex($tableMid, $tableId, $tableName, $tableSoleName, $tableFieldname); |
|
265
|
|
|
} |
|
266
|
|
|
if (0 == $tableCategory && 1 == $tableIndex) { |
|
267
|
|
|
$content .= $this->getBodyPagesIndex($moduleDirname, $tableName, $tableSoleName, $language); |
|
268
|
|
|
} |
|
269
|
|
|
} |
|
270
|
|
|
$content .= $this->getUserIndexFooter($moduleDirname, $language); |
|
271
|
|
|
|
|
272
|
|
|
$this->create($moduleDirname, '/', $filename, $content, _AM_MODULEBUILDER_FILE_CREATED, _AM_MODULEBUILDER_FILE_NOTCREATED); |
|
273
|
|
|
|
|
274
|
|
|
return $this->renderFile(); |
|
275
|
|
|
} |
|
276
|
|
|
} |
|
277
|
|
|
|
This check looks for parameters that have been defined for a function or method, but which are not used in the method body.