Skip to content

Commit 54e2440

Browse files
committed
added handling broken to admin area
1 parent b7c25b9 commit 54e2440

13 files changed

Lines changed: 499 additions & 8 deletions

File tree

class/Files/Admin/AdminBroken.php

Lines changed: 195 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,195 @@
1+
<?php
2+
3+
namespace XoopsModules\Tdmcreate\Files\Admin;
4+
5+
use XoopsModules\Tdmcreate;
6+
use XoopsModules\Tdmcreate\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+
* tdmcreate 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 AdminBroken.
31+
*/
32+
class AdminBroken extends Files\CreateFile
33+
{
34+
/**
35+
* @public function constructor
36+
* @param null
37+
*/
38+
public function __construct()
39+
{
40+
parent::__construct();
41+
}
42+
43+
/**
44+
* @static function getInstance
45+
* @param null
46+
*
47+
* @return AdminBroken
48+
*/
49+
public static function getInstance()
50+
{
51+
static $instance = false;
52+
if (!$instance) {
53+
$instance = new self();
54+
}
55+
56+
return $instance;
57+
}
58+
59+
/**
60+
* @public function write
61+
* @param $module
62+
* @param $tables
63+
* @param $filename
64+
*/
65+
public function write($module, $tables, $filename)
66+
{
67+
$this->setModule($module);
68+
$this->setTables($tables);
69+
$this->setFileName($filename);
70+
}
71+
72+
/**
73+
* @private function getAdminBrokenHeader
74+
* @param $moduleDirname
75+
* @param $fieldId
76+
* @return string
77+
*/
78+
private function getAdminBrokenHeader($moduleDirname, $tableName, $t = '')
79+
{
80+
$pc = Tdmcreate\Files\CreatePhpCode::getInstance();
81+
$xc = Tdmcreate\Files\CreateXoopsCode::getInstance();
82+
$axc = Tdmcreate\Files\Admin\AdminXoopsCode::getInstance();
83+
$ret = $pc->getPhpCodeUseNamespace(['Xmf', 'Request'], '', '');
84+
$ret .= $pc->getPhpCodeUseNamespace(['XoopsModules', $moduleDirname], '', '');
85+
$ret .= $pc->getPhpCodeUseNamespace(['XoopsModules', $moduleDirname, 'Constants']);
86+
$ret .= $this->getInclude();
87+
$ret .= $pc->getPhpCodeBlankLine();
88+
$ret .= $pc->getPhpCodeCommentLine('Define Stylesheet', '', $t);
89+
$ret .= $xc->getXcXoThemeAddStylesheet('style', $t);
90+
$ret .= $axc->getAdminTemplateMain($moduleDirname, $tableName, $t);
91+
$navigation = $axc->getAdminDisplayNavigation($tableName);
92+
$ret .= $xc->getXcXoopsTplAssign('navigation', $navigation, true, $t);
93+
94+
return $ret;
95+
}
96+
97+
/**
98+
* @private function getAdminBrokenList
99+
* @param $table
100+
* @param $language
101+
* @param string $t
102+
* @return string
103+
*/
104+
private function getAdminBrokenList($tables, $language, $t = '')
105+
{
106+
$pc = Tdmcreate\Files\CreatePhpCode::getInstance();
107+
$xc = Tdmcreate\Files\CreateXoopsCode::getInstance();
108+
109+
$ret = '';
110+
foreach (array_keys($tables) as $i) {
111+
if (1 === (int)$tables[$i]->getVar('table_broken')) {
112+
$tableName = $tables[$i]->getVar('table_name');
113+
$tableSoleName = $tables[$i]->getVar('table_solename');
114+
$ucfTableName = ucfirst($tableName);
115+
$ret .= $pc->getPhpCodeBlankLine();
116+
$ret .= $pc->getPhpCodeCommentLine('Check table', $tableName, $t);
117+
$ret .= $xc->getXcXoopsRequest('start', 'start' . $ucfTableName, '0', 'Int', false, $t);
118+
$adminpager = $xc->getXcGetConfig('adminpager');
119+
$ret .= $xc->getXcXoopsRequest('limit', 'limit' . $ucfTableName, $adminpager, 'Int', false, $t);
120+
$critName = 'cr' . $ucfTableName;
121+
122+
$fields = $this->getTableFields($tables[$i]->getVar('table_mid'), $tables[$i]->getVar('table_id'));
123+
$fieldId = '';
124+
$fieldMain = '';
125+
$fieldSatus = '';
126+
foreach (array_keys($fields) as $f) {
127+
$fieldName = $fields[$f]->getVar('field_name');
128+
if (0 == $f) {
129+
$fieldId = $fieldName;
130+
}
131+
if (1 == $fields[$f]->getVar('field_main')) {
132+
$fieldMain = $fieldName;
133+
}
134+
if (16 == $fields[$f]->getVar('field_element')) {
135+
$fieldSatus = $fieldName;
136+
}
137+
}
138+
139+
$ret .= $xc->getXcCriteriaCompo($critName, $t);
140+
$crit = $xc->getXcCriteria('', "'{$fieldSatus}'", 'Constants::STATUS_BROKEN', '', true);
141+
$ret .= $xc->getXcCriteriaAdd($critName, $crit, $t, "\n");
142+
$ret .= $xc->getXcHandlerCountClear($tableName . 'Count', $tableName, '$' . $critName, $t);
143+
$ret .= $xc->getXcXoopsTplAssign($tableName . '_count', "\${$tableName}Count", true, $t);
144+
$sprintf = $pc->getPhpCodeSprintf($language . 'BROKEN_RESULT', "'{$ucfTableName}'");
145+
$ret .= $xc->getXcXoopsTplAssign($tableName . '_result', $sprintf, true, $t);
146+
147+
$ret .= $xc->getXcCriteriaSetStart($critName,'$start', $t);
148+
$ret .= $xc->getXcCriteriaSetLimit($critName,'$limit', $t);
149+
$contIf = $xc->getXcHandlerAllClear("{$tableName}All", $tableName, "\${$critName}", $t . "\t");
150+
$foreach = $xc->getXcEqualsOperator("\${$tableSoleName}['table']", "'{$ucfTableName}'", '', $t . "\t\t");
151+
$foreach .= $xc->getXcEqualsOperator("\${$tableSoleName}['key']", "'{$fieldId}'", '', $t . "\t\t");
152+
$foreach .= $xc->getXcGetVar("{$tableSoleName}['keyval']", "{$tableName}All[\$i]", "{$fieldId}", false, $t . "\t\t");
153+
$foreach .= $xc->getXcGetVar("{$tableSoleName}['main']", "{$tableName}All[\$i]", "{$fieldMain}", false, $t . "\t\t");
154+
$foreach .= $xc->getXcXoopsTplAppend("{$tableName}_list", "\${$tableSoleName}", $t . "\t\t");
155+
$contIf .= $pc->getPhpCodeForeach("{$tableName}All", true, false, 'i', $foreach, $t . "\t");
156+
$contIf .= $xc->getXcPageNav($tableName, $t . "\t", 'start' . $ucfTableName, "'op=list&limit{$ucfTableName}=' . \$limit");
157+
$sprintf = $pc->getPhpCodeSprintf($language . 'BROKEN_NODATA', "'{$ucfTableName}'");
158+
$contElse = $xc->getXcXoopsTplAssign('nodata' . $ucfTableName, $sprintf, true, $t . "\t");
159+
160+
$ret .= $pc->getPhpCodeConditions("\${$tableName}Count", ' > ', '0', $contIf, $contElse, $t);
161+
$ret .= $pc->getPhpCodeUnset($critName, $t);
162+
}
163+
}
164+
165+
$ret .= $pc->getPhpCodeBlankLine();
166+
167+
return $ret;
168+
}
169+
170+
/**
171+
* @public function render
172+
* @param null
173+
*
174+
* @return bool|string
175+
*/
176+
public function render()
177+
{
178+
$tf = Tdmcreate\Files\CreateFile::getInstance();
179+
180+
$module = $this->getModule();
181+
$tables = $this->getTables();
182+
$filename = $this->getFileName();
183+
$moduleDirname = $module->getVar('mod_dirname');
184+
$language = $this->getLanguage($moduleDirname, 'AM');
185+
186+
$content = $this->getHeaderFilesComments($module);
187+
$content .= $this->getAdminBrokenHeader($moduleDirname, 'broken');
188+
$content .= $this->getAdminBrokenList($tables, $language);
189+
$content .= $this->getInclude('footer');
190+
191+
$tf->create($moduleDirname, 'admin', $filename, $content, _AM_TDMCREATE_FILE_CREATED, _AM_TDMCREATE_FILE_NOTCREATED);
192+
193+
return $tf->renderFile();
194+
}
195+
}

class/Files/Admin/AdminMenu.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,14 +168,21 @@ private function getAdminMenuList($module, $language, $langAbout, $menu)
168168
$ret = '';
169169
$tables = $this->getTableTables($module->getVar('mod_id'), 'table_order');
170170
$tablePermissions = [];
171+
$tableBroken = [];
171172
foreach (array_keys($tables) as $t) {
172173
$tablePermissions[] = $tables[$t]->getVar('table_permissions');
174+
$tableBroken[] = $tables[$t]->getVar('table_broken');
173175
if (1 == $tables[$t]->getVar('table_admin')) {
174176
++$menu;
175177
$param1 = ['title' => "{$language}{$menu}", 'link' => "'admin/{$tables[$t]->getVar('table_name')}.php'", 'icon' => "'assets/icons/32/{$tables[$t]->getVar('table_image')}'"];
176178
$ret .= $this->getAdminMenuArray($param1, true);
177179
}
178180
}
181+
if (in_array(1, $tableBroken)) {
182+
++$menu;
183+
$param2 = ['title' => "{$language}{$menu}", 'link' => "'admin/broken.php'", 'icon' => "\$sysPathIcon32.'/brokenlink.png'"];
184+
$ret .= $this->getAdminMenuArray($param2, true);
185+
}
179186
if (in_array(1, $tablePermissions)) {
180187
++$menu;
181188
$param2 = ['title' => "{$language}{$menu}", 'link' => "'admin/permissions.php'", 'icon' => "\$sysPathIcon32.'/permissions.png'"];

class/Files/CreateArchitecture.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -423,6 +423,17 @@ public function setFilesToBuilding($module)
423423
$languageBlocks->write($module, $tables, 'blocks.php');
424424
$ret[] = $languageBlocks->render();
425425
}
426+
// Creation of admin broken files
427+
if (in_array(1, $tableBroken)) {
428+
// Admin broken File
429+
$adminPermissions = Tdmcreate\Files\Admin\AdminBroken::getInstance();
430+
$adminPermissions->write($module, $tables, 'broken.php');
431+
$ret[] = $adminPermissions->render();
432+
// Templates Admin broken File
433+
$adminTemplatesPermissions = Tdmcreate\Files\Templates\Admin\TemplatesAdminBroken::getInstance();
434+
$adminTemplatesPermissions->write($module, $tables, $moduleDirname . '_admin_broken.tpl');
435+
$ret[] = $adminTemplatesPermissions->render();
436+
}
426437
// Creation of admin permission files
427438
if (in_array(1, $tablePermissions)) {
428439
// Admin Permissions File

class/Files/CreateSmartyCode.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -132,11 +132,12 @@ public function getSmartyNoSimbol($noSimbol = '', $t = '')
132132
* @param string $language
133133
* @param mixed $const
134134
* @param string $t
135+
* @param string $n
135136
* @return string
136137
*/
137-
public function getSmartyConst($language, $const, $t = '')
138+
public function getSmartyConst($language, $const, $t = '', $n = '')
138139
{
139-
return "{$t}<{\$smarty.const.{$language}{$const}}>";
140+
return "{$t}<{\$smarty.const.{$language}{$const}}>{$n}";
140141
}
141142

142143
/**

class/Files/CreateXoopsCode.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1209,13 +1209,13 @@ public function getXcSaveElements($moduleDirname, $tableName, $tableSoleName, $f
12091209
* @param string $t
12101210
* @return string
12111211
*/
1212-
public function getXcPageNav($tableName, $t = '')
1212+
public function getXcPageNav($tableName, $t = '', $paramStart = 'start', $paramOp = "'op=list&limit=' . \$limit")
12131213
{
12141214
$pc = Tdmcreate\Files\CreatePhpCode::getInstance();
12151215
$cxc = Tdmcreate\Files\Classes\ClassXoopsCode::getInstance();
12161216
$ret = $pc->getPhpCodeCommentLine('Display Navigation', null, $t);
12171217
$condition = $pc->getPhpCodeIncludeDir('XOOPS_ROOT_PATH', 'class/pagenav', true, false, 'include', $t . "\t");
1218-
$condition .= $cxc->getClassXoopsPageNav('pagenav', $tableName . 'Count', 'limit', 'start', 'start', "'op=list&limit=' . \$limit", false, $t . "\t");
1218+
$condition .= $cxc->getClassXoopsPageNav('pagenav', $tableName . 'Count', 'limit', 'start', $paramStart, $paramOp, false, $t . "\t");
12191219
$condition .= $this->getXcXoopsTplAssign('pagenav', '$pagenav->renderNav(4)', true, $t . "\t");
12201220
$ret .= $pc->getPhpCodeConditions("\${$tableName}Count", ' > ', '$limit', $condition, false, $t);
12211221

class/Files/Language/LanguageAdmin.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,7 @@ public function getLanguageAdminClass($language, $tables)
157157
$tableId = $tables[$t]->getVar('table_id');
158158
$tableMid = $tables[$t]->getVar('table_mid');
159159
$tableSoleName = $tables[$t]->getVar('table_solename');
160+
$tableBroken = $tables[$t]->getVar('table_broken');
160161
$ucfTableSoleName = ucfirst($tableSoleName);
161162

162163
$fields = $this->getTableFields($tableMid, $tableId);
@@ -240,6 +241,16 @@ public function getLanguageAdminClass($language, $tables)
240241
$ret .= $this->defines->getDefine($language, 'STATUS_APPROVED', 'Approved');
241242
$ret .= $this->defines->getDefine($language, 'STATUS_BROKEN', 'Broken');
242243
}
244+
if ($tableBroken > 0) {
245+
$ret .= $this->defines->getAboveDefines('Broken');
246+
$ret .= $this->defines->getDefine($language, 'BROKEN_RESULT', 'Broken items in table %s');
247+
$ret .= $this->defines->getDefine($language, 'BROKEN_NODATA', 'No broken items in table %s');
248+
$ret .= $this->defines->getDefine($language, 'BROKEN_TABLE', 'Table');
249+
$ret .= $this->defines->getDefine($language, 'BROKEN_KEY', 'Key field');
250+
$ret .= $this->defines->getDefine($language, 'BROKEN_KEYVAL', 'Key value');
251+
$ret .= $this->defines->getDefine($language, 'BROKEN_MAIN', 'Info main');
252+
}
253+
243254
if ($fieldSampleListValue > 0) {
244255
$ret .= $this->defines->getAboveDefines('Sample List Values');
245256
$ret .= $this->defines->getDefine($language, 'LIST_1', 'Sample List Value 1');

class/Files/Language/LanguageModinfo.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,12 +111,18 @@ private function getLanguageMenu($module, $language)
111111
$ret = $df->getAboveHeadDefines('Admin Menu');
112112
$ret .= $df->getDefine($language, "ADMENU{$menu}", 'Dashboard');
113113
$tablePermissions = [];
114+
$tableBroken = [];
114115
foreach (array_keys($tables) as $i) {
115116
++$menu;
116117
$tablePermissions[] = $tables[$i]->getVar('table_permissions');
118+
$tableBroken[] = $tables[$i]->getVar('table_broken');
117119
$ucfTableName = ucfirst($tables[$i]->getVar('table_name'));
118120
$ret .= $df->getDefine($language, "ADMENU{$menu}", $ucfTableName);
119121
}
122+
if (in_array(1, $tableBroken)) {
123+
++$menu;
124+
$ret .= $df->getDefine($language, "ADMENU{$menu}", 'Broken items');
125+
}
120126
if (in_array(1, $tablePermissions)) {
121127
++$menu;
122128
$ret .= $df->getDefine($language, "ADMENU{$menu}", 'Permissions');

0 commit comments

Comments
 (0)