|
| 1 | +<?php |
| 2 | + |
| 3 | +namespace XoopsModules\Modulebuilder\Files; |
| 4 | + |
| 5 | +use XoopsModules\Modulebuilder; |
| 6 | + |
| 7 | +/* |
| 8 | + You may not change or alter any portion of this comment or credits |
| 9 | + of supporting developers from this source code or any supporting source code |
| 10 | + which is considered copyrighted (c) material of the original comment or credit authors. |
| 11 | +
|
| 12 | + This program is distributed in the hope that it will be useful, |
| 13 | + but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 | + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
| 15 | + */ |
| 16 | +/** |
| 17 | + * modulebuilder module. |
| 18 | + * |
| 19 | + * @copyright XOOPS Project (https://xoops.org) |
| 20 | + * @license GNU GPL 2 (http://www.gnu.org/licenses/old-licenses/gpl-2.0.html) |
| 21 | + * |
| 22 | + * @since 2.5.0 |
| 23 | + * |
| 24 | + * @author Txmod Xoops http://www.txmodxoops.org |
| 25 | + * |
| 26 | + */ |
| 27 | + |
| 28 | +//include dirname(__DIR__) . '/autoload.php'; |
| 29 | + |
| 30 | +/** |
| 31 | + * Class CheckData. |
| 32 | + */ |
| 33 | +class CheckData |
| 34 | +{ |
| 35 | + /** |
| 36 | + * @public function constructor class |
| 37 | + * |
| 38 | + * @param null |
| 39 | + */ |
| 40 | + public function __construct() |
| 41 | + { |
| 42 | + //parent::__construct(); |
| 43 | + } |
| 44 | + |
| 45 | + /** |
| 46 | + * @static function getInstance |
| 47 | + * |
| 48 | + * @param null |
| 49 | + * |
| 50 | + * @return Modulebuilder\Files\CreateArchitecture |
| 51 | + */ |
| 52 | + public static function getInstance() |
| 53 | + { |
| 54 | + static $instance = false; |
| 55 | + if (!$instance) { |
| 56 | + $instance = new self(); |
| 57 | + } |
| 58 | + |
| 59 | + return $instance; |
| 60 | + } |
| 61 | + |
| 62 | + /** |
| 63 | + * @public function getCheckResult |
| 64 | + * |
| 65 | + * @param $module |
| 66 | + */ |
| 67 | + public function getCheckPreBuilding($module) |
| 68 | + { |
| 69 | + $cf = Modulebuilder\Files\CreateFile::getInstance(); |
| 70 | + |
| 71 | + $modId = $module->getVar('mod_id'); |
| 72 | + $tables = $cf->getTableTables($modId); |
| 73 | + $errors = []; |
| 74 | + |
| 75 | + foreach (array_keys($tables) as $t) { |
| 76 | + if (1 == $tables[$t]->getVar('table_broken')) { |
| 77 | + $tableId = $tables[$t]->getVar('table_id'); |
| 78 | + $tableName = $tables[$t]->getVar('table_name'); |
| 79 | + $fields = $cf->getTableFields($modId, $tableId); |
| 80 | + $fieldSatus = ''; |
| 81 | + |
| 82 | + foreach (array_keys($fields) as $f) { |
| 83 | + $fieldName = $fields[$f]->getVar('field_name'); |
| 84 | + if (16 == $fields[$f]->getVar('field_element')) { |
| 85 | + $fieldSatus = $fieldName; |
| 86 | + } |
| 87 | + } |
| 88 | + // check whether each table with handling "broken" has also a field "status" |
| 89 | + if ('' == $fieldSatus) { |
| 90 | + $error = str_replace('%t', $tableName, _AM_MODULEBUILDER_CHECKPREBUILD_BROKEN1); |
| 91 | + $errors[] = ['tableName' => $tableName, 'icon' => 'error', 'info' => $error]; |
| 92 | + } |
| 93 | + } |
| 94 | + } |
| 95 | + foreach (array_keys($tables) as $t) { |
| 96 | + $tableId = $tables[$t]->getVar('table_id'); |
| 97 | + $tableName = $tables[$t]->getVar('table_name'); |
| 98 | + $fields = $cf->getTableFields($modId, $tableId); |
| 99 | + |
| 100 | + foreach (array_keys($fields) as $f) { |
| 101 | + $fieldName = $fields[$f]->getVar('field_name'); |
| 102 | + // check fields for parameters |
| 103 | + if ($f > 0) { |
| 104 | + $fieldParams = (int)$fields[$f]->getVar('field_parent') + (int)$fields[$f]->getVar('field_admin') + (int)$fields[$f]->getVar('field_inlist') + (int)$fields[$f]->getVar('field_inform') |
| 105 | + + (int)$fields[$f]->getVar('field_user') + (int)$fields[$f]->getVar('field_ihead') + (int)$fields[$f]->getVar('field_ibody') + (int)$fields[$f]->getVar('field_ifoot') |
| 106 | + + (int)$fields[$f]->getVar('field_thead') + (int)$fields[$f]->getVar('field_tbody') + (int)$fields[$f]->getVar('field_tfoot') + (int)$fields[$f]->getVar('field_block') |
| 107 | + + (int)$fields[$f]->getVar('field_main') + (int)$fields[$f]->getVar('field_search') + (int)$fields[$f]->getVar('field_required'); |
| 108 | + if (0 == $fieldParams) { |
| 109 | + $error = str_replace(['%f', '%t'], [$fieldName, $tableName], _AM_MODULEBUILDER_CHECKPREBUILD_FIELDS1); |
| 110 | + $errors[] = ['tableName' => $tableName, 'icon' => 'error', 'info' => $error]; |
| 111 | + } |
| 112 | + } |
| 113 | + } |
| 114 | + } |
| 115 | + |
| 116 | + //check user file no usage in index or item |
| 117 | + foreach (array_keys($tables) as $t) { |
| 118 | + $tableId = $tables[$t]->getVar('table_id'); |
| 119 | + $tableName = $tables[$t]->getVar('table_name'); |
| 120 | + $fields = $cf->getTableFields($modId, $tableId); |
| 121 | + |
| 122 | + foreach (array_keys($fields) as $f) { |
| 123 | + $fieldName = $fields[$f]->getVar('field_name'); |
| 124 | + if (1 == $fields[$f]->getVar('field_user')) { |
| 125 | + // check fields for parameters |
| 126 | + if ($f > 0) { |
| 127 | + $fieldParams = (int)$fields[$f]->getVar('field_ihead') + (int)$fields[$f]->getVar('field_ibody') + (int)$fields[$f]->getVar('field_ifoot') |
| 128 | + + (int)$fields[$f]->getVar('field_thead') + (int)$fields[$f]->getVar('field_tbody') + (int)$fields[$f]->getVar('field_tfoot'); |
| 129 | + if (0 == $fieldParams) { |
| 130 | + $error = str_replace(['%f', '%t'], [$fieldName, $tableName], _AM_MODULEBUILDER_CHECKPREBUILD_FIELDS2); |
| 131 | + $errors[] = ['tableName' => $tableName, 'icon' => 'warning', 'info' => $error]; |
| 132 | + } |
| 133 | + } |
| 134 | + } |
| 135 | + } |
| 136 | + } |
| 137 | + //check user file index multiple usage |
| 138 | + //check user file item multiple usage |
| 139 | + foreach (array_keys($tables) as $t) { |
| 140 | + $tableId = $tables[$t]->getVar('table_id'); |
| 141 | + $tableName = $tables[$t]->getVar('table_name'); |
| 142 | + $fields = $cf->getTableFields($modId, $tableId); |
| 143 | + |
| 144 | + foreach (array_keys($fields) as $f) { |
| 145 | + $fieldName = $fields[$f]->getVar('field_name'); |
| 146 | + if (1 == $fields[$f]->getVar('field_user')) { |
| 147 | + // check fields for parameters |
| 148 | + if ($f > 0) { |
| 149 | + $fieldParams = (int)$fields[$f]->getVar('field_ihead') + (int)$fields[$f]->getVar('field_ibody') + (int)$fields[$f]->getVar('field_ifoot'); |
| 150 | + if ($fieldParams > 1) { |
| 151 | + $error = str_replace(['%f', '%t'], [$fieldName, $tableName], _AM_MODULEBUILDER_CHECKPREBUILD_FIELDS3); |
| 152 | + $errors[] = ['tableName' => $tableName, 'icon' => 'warning', 'info' => $error]; |
| 153 | + } |
| 154 | + $fieldParams = (int)$fields[$f]->getVar('field_thead') + (int)$fields[$f]->getVar('field_tbody') + (int)$fields[$f]->getVar('field_tfoot'); |
| 155 | + if ($fieldParams > 1) { |
| 156 | + $error = str_replace(['%f', '%t'], [$fieldName, $tableName], _AM_MODULEBUILDER_CHECKPREBUILD_FIELDS3); |
| 157 | + $errors[] = ['tableName' => $tableName, 'icon' => 'warning', 'info' => $error]; |
| 158 | + } |
| 159 | + } |
| 160 | + } |
| 161 | + } |
| 162 | + } |
| 163 | + |
| 164 | + //use in block but not field selected |
| 165 | + foreach (array_keys($tables) as $t) { |
| 166 | + $tableId = $tables[$t]->getVar('table_id'); |
| 167 | + $tableName = $tables[$t]->getVar('table_name'); |
| 168 | + $fields = $cf->getTableFields($modId, $tableId); |
| 169 | + $count = 0; |
| 170 | + if (1 == $tables[$t]->getVar('table_blocks')) { |
| 171 | + foreach (array_keys($fields) as $f) { |
| 172 | + $fieldName = $fields[$f]->getVar('field_name'); |
| 173 | + if (1 == $fields[$f]->getVar('field_block')) { |
| 174 | + $count++; |
| 175 | + } |
| 176 | + } |
| 177 | + if (0 == $count) { |
| 178 | + $error = str_replace(['%f', '%t'], [$fieldName, $tableName], _AM_MODULEBUILDER_CHECKPREBUILD_BLOCK1); |
| 179 | + $errors[] = ['tableName' => $tableName, 'icon' => 'warning', 'info' => $error]; |
| 180 | + } |
| 181 | + } |
| 182 | + } |
| 183 | + //use in block but not field date |
| 184 | + foreach (array_keys($tables) as $t) { |
| 185 | + $tableId = $tables[$t]->getVar('table_id'); |
| 186 | + $tableName = $tables[$t]->getVar('table_name'); |
| 187 | + $fields = $cf->getTableFields($modId, $tableId); |
| 188 | + $count = 0; |
| 189 | + if (1 == $tables[$t]->getVar('table_blocks')) { |
| 190 | + foreach (array_keys($fields) as $f) { |
| 191 | + $fieldName = $fields[$f]->getVar('field_name'); |
| 192 | + if (15 == $fields[$f]->getVar('field_element') || 21 == $fields[$f]->getVar('field_element')) { |
| 193 | + $count++; |
| 194 | + } |
| 195 | + } |
| 196 | + if (0 == $count) { |
| 197 | + $error = str_replace(['%f', '%t'], [$fieldName, $tableName], _AM_MODULEBUILDER_CHECKPREBUILD_BLOCK2); |
| 198 | + $errors[] = ['tableName' => $tableName, 'icon' => 'warning', 'info' => $error]; |
| 199 | + } |
| 200 | + } |
| 201 | + } |
| 202 | + |
| 203 | + return $errors; |
| 204 | + } |
| 205 | +} |
0 commit comments