| Conditions | 14 |
| Paths | 2160 |
| Total Lines | 130 |
| Code Lines | 88 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 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); |
||
| 168 | function manageStatus() |
||
| 169 | { |
||
| 170 | global $aSortBy, $aOrderBy, $aLimitBy, $order, $limit, $start, $sort; |
||
| 171 | $helper = Xhelp\Helper::getInstance(); |
||
| 172 | /** @var \XoopsModules\Xhelp\StatusHandler $statusHandler */ |
||
| 173 | $statusHandler = $helper->getHandler('Status'); |
||
| 174 | $helper = Xhelp\Helper::getInstance(); |
||
| 175 | |||
| 176 | if (Request::hasVar('changeDefaultStatus', 'POST')) { |
||
| 177 | Xhelp\Utility::setMeta('default_status', $_POST['default']); |
||
| 178 | } |
||
| 179 | |||
| 180 | if (Request::hasVar('newStatus', 'POST')) { |
||
| 181 | if ('' === \Xmf\Request::getString('desc', '', 'POST')) { // If no description supplied |
||
| 182 | $message = _AM_XHELP_MESSAGE_NO_DESC; |
||
| 183 | $helper->redirect('admin/status.php?op=manageStatus', 3, $message); |
||
| 184 | } |
||
| 185 | /** @var \XoopsModules\Xhelp\Status $newStatus */ |
||
| 186 | $newStatus = $statusHandler->create(); |
||
| 187 | |||
| 188 | $newStatus->setVar('state', Request::getInt('state', 0, 'POST')); |
||
| 189 | $newStatus->setVar('description', \Xmf\Request::getString('desc', '', 'POST')); |
||
| 190 | if ($statusHandler->insert($newStatus)) { |
||
| 191 | $helper->redirect('admin/status.php?op=manageStatus'); |
||
| 192 | } else { |
||
| 193 | $message = _AM_MESSAGE_ADD_STATUS_ERR; |
||
| 194 | $helper->redirect('admin/status.php?op=manageStatus', 3, $message); |
||
| 195 | } |
||
| 196 | } |
||
| 197 | xoops_cp_header(); |
||
| 198 | //echo $oAdminButton->renderButtons('manStatus'); |
||
| 199 | $adminObject = Admin::getInstance(); |
||
| 200 | $adminObject->displayNavigation('status.php?op=manageStatus'); |
||
| 201 | |||
| 202 | echo "<form method='post' action='" . XHELP_ADMIN_URL . "/status.php?op=manageStatus'>"; |
||
| 203 | echo "<table width='100%' cellspacing='1' class='outer'> |
||
| 204 | <tr><th colspan='2'><label>" . _AM_XHELP_TEXT_ADD_STATUS . '</label></th></tr>'; |
||
| 205 | echo "<tr><td class='head' width='20%'>" . _AM_XHELP_TEXT_DESCRIPTION . "</td> |
||
| 206 | <td class='even'> |
||
| 207 | <input type='text' name='desc' value='' class='formButton'> |
||
| 208 | </td> |
||
| 209 | </tr>"; |
||
| 210 | echo "<tr><td class='head' width='20%'>" . _AM_XHELP_TEXT_STATE . "</td><td class='even'> |
||
| 211 | <select name='state'> |
||
| 212 | <option value='1'>" . Xhelp\Utility::getState(1) . "</option> |
||
| 213 | <option value='2'>" . Xhelp\Utility::getState(2) . '</option> |
||
| 214 | </select></td></tr>'; |
||
| 215 | echo "<tr><td class='foot' colspan='2'><input type='submit' name='newStatus' value='" . _AM_XHELP_TEXT_ADD_STATUS . "' class='formButton'></td></tr>"; |
||
| 216 | echo '</table></form>'; |
||
| 217 | |||
| 218 | // Get list of existing statuses |
||
| 219 | $criteria = new \Criteria('', ''); |
||
| 220 | $criteria->setOrder($order); |
||
| 221 | $criteria->setSort($sort); |
||
| 222 | $criteria->setLimit($limit); |
||
| 223 | $criteria->setStart($start); |
||
| 224 | $statuses = $statusHandler->getObjects($criteria); |
||
| 225 | $total = $statusHandler->getCount($criteria); |
||
| 226 | |||
| 227 | $aStatuses = []; |
||
| 228 | foreach ($statuses as $status) { |
||
| 229 | $aStatuses[$status->getVar('id')] = $status->getVar('description'); |
||
| 230 | } |
||
| 231 | |||
| 232 | if (!$default_status = Xhelp\Utility::getMeta('default_status')) { |
||
| 233 | Xhelp\Utility::setMeta('default_status', '1'); |
||
| 234 | $default_status = 1; |
||
| 235 | } |
||
| 236 | $form = new Xhelp\Form(_AM_XHELP_TEXT_DEFAULT_STATUS, 'default_status', Xhelp\Utility::createURI(XHELP_ADMIN_URL . '/status.php', ['op' => 'manageStatus'])); |
||
| 237 | $status_select = new \XoopsFormSelect(_AM_XHELP_TEXT_STATUS, 'default', $default_status); |
||
| 238 | $status_select->addOptionArray($aStatuses); |
||
| 239 | $btn_tray = new \XoopsFormElementTray(''); |
||
| 240 | $btn_tray->addElement(new \XoopsFormButton('', 'changeDefaultStatus', _SUBMIT, 'submit')); |
||
| 241 | $form->addElement($status_select); |
||
| 242 | $form->addElement($btn_tray); |
||
| 243 | $form->setLabelWidth('20%'); |
||
| 244 | echo $form->render(); |
||
| 245 | |||
| 246 | $nav = new \XoopsPageNav($total, $limit, $start, 'start', "op=manageStatus&limit=$limit"); |
||
| 247 | |||
| 248 | echo "<form action='" . XHELP_ADMIN_URL . "/status.php?op=manageStatus' style='margin:0; padding:0;' method='post'>"; |
||
| 249 | echo $GLOBALS['xoopsSecurity']->getTokenHTML(); |
||
| 250 | echo "<table width='100%' cellspacing='1' class='outer'>"; |
||
| 251 | echo "<tr><td align='right'>" . _AM_XHELP_TEXT_SORT_BY . " |
||
| 252 | <select name='sort'>"; |
||
| 253 | foreach ($aSortBy as $value => $text) { |
||
| 254 | ($sort == $value) ? $selected = 'selected' : $selected = ''; |
||
| 255 | echo "<option value='$value' $selected>$text</option>"; |
||
| 256 | } |
||
| 257 | echo '</select> |
||
| 258 | |
||
| 259 | ' . _AM_XHELP_TEXT_ORDER_BY . " |
||
| 260 | <select name='order'>"; |
||
| 261 | foreach ($aOrderBy as $value => $text) { |
||
| 262 | ($order == $value) ? $selected = 'selected' : $selected = ''; |
||
| 263 | echo "<option value='$value' $selected>$text</option>"; |
||
| 264 | } |
||
| 265 | echo '</select> |
||
| 266 | |
||
| 267 | ' . _AM_XHELP_TEXT_NUMBER_PER_PAGE . " |
||
| 268 | <select name='limit'>"; |
||
| 269 | foreach ($aLimitBy as $value => $text) { |
||
| 270 | ($limit == $value) ? $selected = 'selected' : $selected = ''; |
||
| 271 | echo "<option value='$value' $selected>$text</option>"; |
||
| 272 | } |
||
| 273 | echo "</select> |
||
| 274 | <input type='submit' name='status_sort' id='status_sort' value='" . _AM_XHELP_BUTTON_SUBMIT . "'> |
||
| 275 | </td> |
||
| 276 | </tr>"; |
||
| 277 | echo '</table></form>'; |
||
| 278 | |||
| 279 | echo "<table width='100%' cellspacing='1' class='outer'> |
||
| 280 | <tr><th colspan='4'><label>" . _AM_XHELP_TEXT_MANAGE_STATUSES . '</label></th></tr>'; |
||
| 281 | echo "<tr class='head'> |
||
| 282 | <td>" . _AM_XHELP_TEXT_ID . '</td> |
||
| 283 | <td>' . _AM_XHELP_TEXT_DESCRIPTION . '</td> |
||
| 284 | <td>' . _AM_XHELP_TEXT_STATE . '</td> |
||
| 285 | <td>' . _AM_XHELP_TEXT_ACTIONS . '</td> |
||
| 286 | </tr>'; |
||
| 287 | foreach ($statuses as $status) { |
||
| 288 | echo "<tr class='even'><td>" . $status->getVar('id') . '</td><td>' . $status->getVar('description') . '</td> |
||
| 289 | <td>' . Xhelp\Utility::getState($status->getVar('state')) . "</td> |
||
| 290 | <td> |
||
| 291 | <a href='status.php?op=editStatus&statusid=" . $status->getVar('id') . "'><img src='" . XHELP_IMAGE_URL . "/button_edit.png' title='" . _AM_XHELP_TEXT_EDIT . "' name='editStatus'></a> |
||
| 292 | <a href='status.php?op=deleteStatus&statusid=" . $status->getVar('id') . "'><img src='" . XHELP_IMAGE_URL . "/button_delete.png' title='" . _AM_XHELP_TEXT_DELETE . "' name='deleteStatus'></a></td></tr> |
||
| 293 | </td></tr>"; |
||
| 294 | } |
||
| 295 | echo '</table>'; |
||
| 296 | echo "<div id='status_nav'>" . $nav->renderNav() . '</div>'; |
||
| 297 | require_once __DIR__ . '/admin_footer.php'; |
||
| 298 | } |
||
| 299 |