| Conditions | 7 |
| Paths | 36 |
| Total Lines | 152 |
| Code Lines | 70 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | <?php declare(strict_types=1); |
||
| 82 | function editcat($showmenu = false, $categoryid = 0): void |
||
| 83 | { |
||
| 84 | //$moderators = []; // just to define the variable |
||
| 85 | //$allmods = []; |
||
| 86 | $startfaq = Request::getInt('startfaq', 0, 'GET'); |
||
| 87 | global $categoryHandler, $xoopsUser, $myts, $xoopsConfig, $xoopsDB, $modify, $xoopsModule, $_GET; |
||
| 88 | /** @var Smartfaq\Helper $helper */ |
||
| 89 | $helper = Helper::getInstance(); |
||
| 90 | require_once XOOPS_ROOT_PATH . '/class/xoopsformloader.php'; |
||
| 91 | |||
| 92 | // Creating the faq handler object |
||
| 93 | /** @var \XoopsModules\Smartfaq\FaqHandler $faqHandler */ |
||
| 94 | $faqHandler = Helper::getInstance()->getHandler('Faq'); |
||
| 95 | |||
| 96 | echo '<script type="text/javascript" src="funcs.js"></script>'; |
||
| 97 | echo '<style>'; |
||
| 98 | echo '<!-- '; |
||
| 99 | echo 'select { width: 130px; }'; |
||
| 100 | echo '-->'; |
||
| 101 | echo '</style>'; |
||
| 102 | // If there is a parameter, and the id exists, retrieve data: we're editing a category |
||
| 103 | if (0 != $categoryid) { |
||
| 104 | // Creating the category object for the selected category |
||
| 105 | $categoryObj = new Category($categoryid); |
||
| 106 | |||
| 107 | echo "<br>\n"; |
||
| 108 | if ($categoryObj->notLoaded()) { |
||
| 109 | redirect_header('category.php', 1, _AM_SF_NOCOLTOEDIT); |
||
| 110 | } |
||
| 111 | Smartfaq\Utility::collapsableBar('bottomtable', 'bottomtableicon'); |
||
| 112 | echo "<img id='bottomtableicon' src=" . XOOPS_URL . '/modules/' . $xoopsModule->dirname() . "/assets/images/icon/close12.gif alt=''></a> " . _AM_SF_EDITCOL . '</h3>'; |
||
| 113 | echo "<div id='bottomtable'>"; |
||
| 114 | } else { |
||
| 115 | $categoryObj = $categoryHandler->create(); |
||
| 116 | echo "<br>\n"; |
||
| 117 | Smartfaq\Utility::collapsableBar('bottomtable', 'bottomtableicon'); |
||
| 118 | echo "<img id='bottomtableicon' src=" . XOOPS_URL . '/modules/' . $xoopsModule->dirname() . "/assets/images/icon/close12.gif alt=''></a> " . _AM_SF_CATEGORY_CREATE . '</h3>'; |
||
| 119 | echo "<div id='bottomtable'>"; |
||
| 120 | } |
||
| 121 | // Start category form |
||
| 122 | $sform = new \XoopsThemeForm(_AM_SF_CATEGORY, 'op', xoops_getenv('SCRIPT_NAME'), 'post', true); |
||
| 123 | $sform->setExtra('enctype="multipart/form-data"'); |
||
| 124 | |||
| 125 | // Name |
||
| 126 | $sform->addElement(new \XoopsFormText(_AM_SF_CATEGORY, 'name', 50, 255, $categoryObj->name('e')), true); |
||
| 127 | |||
| 128 | // Parent Category |
||
| 129 | $mytree = new Smartfaq\Tree($xoopsDB->prefix('smartfaq_categories'), 'categoryid', 'parentid'); |
||
| 130 | ob_start(); |
||
| 131 | $mytree->makeMySelBox('name', 'weight', $categoryObj->parentid(), 1, 'parentid'); |
||
| 132 | |||
| 133 | //makeMySelBox($title,$order="",$preset_id=0, $none=0, $sel_name="", $onchange="") |
||
| 134 | $sform->addElement(new \XoopsFormLabel(_AM_SF_PARENT_CATEGORY_EXP, ob_get_clean())); |
||
| 135 | |||
| 136 | /* $mytree = new Smartfaq\Tree($xoopsDB->prefix("smartfaq_categories"), "categoryid" , "parentid"); |
||
| 137 | ob_start(); |
||
| 138 | $sform->addElement(new \XoopsFormHidden('categoryid', $categoryObj->categoryid())); |
||
| 139 | $mytree->makeMySelBox("name", "weight", $categoryObj->categoryid()); |
||
| 140 | $sform->addElement(new \XoopsFormLabel(_AM_SF_CATEGORY_FAQ, ob_get_contents())); |
||
| 141 | ob_end_clean(); |
||
| 142 | */ |
||
| 143 | |||
| 144 | // Decsription |
||
| 145 | $sform->addElement(new \XoopsFormTextArea(_AM_SF_COLDESCRIPT, 'description', $categoryObj->description('e'), 7, 60)); |
||
| 146 | |||
| 147 | // Weight |
||
| 148 | $sform->addElement(new \XoopsFormText(_AM_SF_COLPOSIT, 'weight', 4, 4, $categoryObj->weight())); |
||
| 149 | |||
| 150 | // READ PERMISSIONS |
||
| 151 | /** @var \XoopsMemberHandler $memberHandler */ |
||
| 152 | $memberHandler = xoops_getHandler('member'); |
||
| 153 | $group_list = $memberHandler->getGroupList(); |
||
| 154 | |||
| 155 | $groups_read_checkbox = new \XoopsFormCheckBox(_AM_SF_PERMISSIONS_CAT_READ, 'groups_read[]', $categoryObj->getGroups_read()); |
||
| 156 | foreach ($group_list as $group_id => $group_name) { |
||
| 157 | if (XOOPS_GROUP_ADMIN != $group_id) { |
||
| 158 | $groups_read_checkbox->addOption($group_id, $group_name); |
||
| 159 | } |
||
| 160 | } |
||
| 161 | $sform->addElement($groups_read_checkbox); |
||
| 162 | // Apply permissions on all faqs |
||
| 163 | $addapplyall_radio = new \XoopsFormRadioYN(_AM_SF_PERMISSIONS_APPLY_ON_FAQS, 'applyall', 0, ' ' . _AM_SF_YES, ' ' . _AM_SF_NO); |
||
| 164 | $sform->addElement($addapplyall_radio); |
||
| 165 | // MODERATORS |
||
| 166 | //$moderators_tray = new \XoopsFormElementTray(_AM_SF_MODERATORS_DEF, ''); |
||
| 167 | |||
| 168 | $module_id = $xoopsModule->getVar('mid'); |
||
| 169 | |||
| 170 | /** @var \XoopsGroupPermHandler $grouppermHandler */ |
||
| 171 | /* |
||
| 172 | $grouppermHandler = xoops_getHandler('groupperm'); |
||
| 173 | $mod_perms = $grouppermHandler->getGroupIds('category_moderation', $categoryid, $module_id); |
||
| 174 | |||
| 175 | $moderators_select = new \XoopsFormSelect('', 'moderators', $moderators, 5, true); |
||
| 176 | $moderators_tray->addElement($moderators_select); |
||
| 177 | |||
| 178 | $butt_mngmods = new \XoopsFormButton('', '', 'Manage mods', 'button'); |
||
| 179 | $butt_mngmods->setExtra('onclick="javascript:small_window(\'pop.php\', 370, 350);"'); |
||
| 180 | $moderators_tray->addElement($butt_mngmods); |
||
| 181 | |||
| 182 | $butt_delmod = new \XoopsFormButton('', '', 'Delete mod', 'button'); |
||
| 183 | $butt_delmod->setExtra('onclick="javascript:deleteSelectedItemsFromList(this.form.elements[\'moderators[]\']);"'); |
||
| 184 | $moderators_tray->addElement($butt_delmod); |
||
| 185 | |||
| 186 | $sform->addElement($moderators_tray); |
||
| 187 | */ |
||
| 188 | $sform->addElement(new \XoopsFormHidden('categoryid', $categoryid)); |
||
| 189 | |||
| 190 | // Action buttons tray |
||
| 191 | $buttonTray = new \XoopsFormElementTray('', ''); |
||
| 192 | |||
| 193 | /*for ($i = 0, $iMax = count($moderators); $i < $iMax; ++$i) { |
||
| 194 | $allmods[] = $moderators[$i]; |
||
| 195 | } |
||
| 196 | |||
| 197 | $hiddenmods = new \XoopsFormHidden('allmods', $allmods); |
||
| 198 | $buttonTray->addElement($hiddenmods); |
||
| 199 | */ |
||
| 200 | $hidden = new \XoopsFormHidden('op', 'addcategory'); |
||
| 201 | $buttonTray->addElement($hidden); |
||
| 202 | // No ID for category -- then it is new category, button says 'Create' |
||
| 203 | if ($categoryid) { |
||
| 204 | // button says 'Update' |
||
| 205 | $butt_create = new \XoopsFormButton('', '', _AM_SF_MODIFY, 'submit'); |
||
| 206 | $butt_create->setExtra('onclick="this.form.elements.op.value=\'addcategory\'"'); |
||
| 207 | $buttonTray->addElement($butt_create); |
||
| 208 | |||
| 209 | $butt_cancel = new \XoopsFormButton('', '', _AM_SF_CANCEL, 'button'); |
||
| 210 | $butt_cancel->setExtra('onclick="history.go(-1)"'); |
||
| 211 | $buttonTray->addElement($butt_cancel); |
||
| 212 | } else { |
||
| 213 | $butt_create = new \XoopsFormButton('', '', _AM_SF_CREATE, 'submit'); |
||
| 214 | $butt_create->setExtra('onclick="this.form.elements.op.value=\'addcategory\'"'); |
||
| 215 | $buttonTray->addElement($butt_create); |
||
| 216 | |||
| 217 | $butt_clear = new \XoopsFormButton('', '', _AM_SF_CLEAR, 'reset'); |
||
| 218 | $buttonTray->addElement($butt_clear); |
||
| 219 | |||
| 220 | $butt_cancel = new \XoopsFormButton('', '', _AM_SF_CANCEL, 'button'); |
||
| 221 | $butt_cancel->setExtra('onclick="history.go(-1)"'); |
||
| 222 | $buttonTray->addElement($butt_cancel); |
||
| 223 | } |
||
| 224 | |||
| 225 | $sform->addElement($buttonTray); |
||
| 226 | $sform->display(); |
||
| 227 | echo '</div>'; |
||
| 228 | |||
| 229 | if ($categoryid) { |
||
| 230 | require_once XOOPS_ROOT_PATH . '/modules/smartfaq/include/displayfaqs.php'; |
||
| 231 | } |
||
| 232 | |||
| 233 | unset($hidden); |
||
| 234 | } |
||
| 385 |