|
| 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 | +} |
0 commit comments