| Conditions | 10 |
| Paths | 144 |
| Total Lines | 121 |
| Code Lines | 93 |
| 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 |
||
| 83 | public function getForm($action = false) |
||
| 84 | { |
||
| 85 | $grouppermHandler = \xoops_getHandler('groupperm'); |
||
| 86 | |||
| 87 | if (!$action) { |
||
| 88 | $action = $_SERVER['REQUEST_URI']; |
||
| 89 | } |
||
| 90 | $title = $this->isNew() ? \_AM_WFDOWNLOADS_CCATEGORY_CREATENEW : \_AM_WFDOWNLOADS_CCATEGORY_MODIFY; |
||
| 91 | |||
| 92 | require_once XOOPS_ROOT_PATH . '/class/xoopsformloader.php'; |
||
| 93 | |||
| 94 | $form = new \XoopsThemeForm($title, 'form_error', $action, 'post', true); |
||
| 95 | $form->setExtra('enctype="multipart/form-data"'); |
||
| 96 | // category: title |
||
| 97 | $form->addElement(new \XoopsFormText(\_AM_WFDOWNLOADS_FCATEGORY_TITLE, 'title', 50, 255, $this->getVar('title', 'e')), true); |
||
| 98 | // category: pid |
||
| 99 | if (Utility::categoriesCount() > 0) { |
||
| 100 | $categoryObjs = $this->helper->getHandler('Category')->getObjects(); |
||
| 101 | $categoryObjsTree = new ObjectTree($categoryObjs, 'cid', 'pid'); |
||
| 102 | |||
| 103 | if (Utility::checkVerXoops($GLOBALS['xoopsModule'], '2.5.9')) { |
||
| 104 | $catSelect = $categoryObjsTree->makeSelectElement('pid', 'title', '-', $this->getVar('pid'), true, 0, '', \_AM_WFDOWNLOADS_FCATEGORY_SUBCATEGORY); |
||
| 105 | $form->addElement($catSelect); |
||
| 106 | } else { |
||
| 107 | $form->addElement(new \XoopsFormLabel(\_AM_WFDOWNLOADS_FCATEGORY_SUBCATEGORY, $categoryObjsTree->makeSelBox('pid', 'title', '-', $this->getVar('pid', 'e'), true))); |
||
| 108 | } |
||
| 109 | } |
||
| 110 | // category: weight |
||
| 111 | $form->addElement(new \XoopsFormText(\_AM_WFDOWNLOADS_FCATEGORY_WEIGHT, 'weight', 11, 11, $this->getVar('weight')), false); |
||
| 112 | // permission: WFDownCatPerm |
||
| 113 | $groups = $grouppermHandler->getGroupIds('WFDownCatPerm', $this->getVar('cid'), $this->helper->getModule()->mid()); |
||
| 114 | $groups_down_select = new \XoopsFormSelectGroup(\_AM_WFDOWNLOADS_FCATEGORY_GROUPPROMPT, 'groups', true, $groups, 5, true); |
||
| 115 | $groups_down_select->setDescription(\_AM_WFDOWNLOADS_FCATEGORY_GROUPPROMPT_DESC); |
||
| 116 | $form->addElement($groups_down_select); |
||
| 117 | // permission: WFUpCatPerm |
||
| 118 | $up_groups = $grouppermHandler->getGroupIds('WFUpCatPerm', $this->getVar('cid'), $this->helper->getModule()->mid()); |
||
| 119 | $groups_up_select = new \XoopsFormSelectGroup(\_AM_WFDOWNLOADS_FCATEGORY_GROUPPROMPT_UP, 'up_groups', true, $up_groups, 5, true); |
||
| 120 | $groups_up_select->setDescription(\_AM_WFDOWNLOADS_FCATEGORY_GROUPPROMPT_UP_DESC); |
||
| 121 | $form->addElement($groups_up_select); |
||
| 122 | // category: imgurl |
||
| 123 | $imgurl_path = $this->getVar('imgurl') ? $this->helper->getConfig('catimage') . '/' . $this->getVar('imgurl') : WFDOWNLOADS_IMAGE_URL . '/blank.png'; |
||
| 124 | $imgurl_tray = new \XoopsFormElementTray(\_AM_WFDOWNLOADS_FCATEGORY_CIMAGE, '<br>'); |
||
| 125 | $imgurl_tray->addElement(new \XoopsFormLabel(_AM_WFDOWNLOADS_DOWN_FUPLOADPATH, XOOPS_ROOT_PATH . '/' . $this->helper->getConfig('catimage'))); |
||
| 126 | $imgurl_tray->addElement(new \XoopsFormLabel(_AM_WFDOWNLOADS_DOWN_FUPLOADURL, XOOPS_URL . '/' . $this->helper->getConfig('catimage'))); |
||
| 127 | $graph_array = WfsLists::getListTypeAsArray(XOOPS_ROOT_PATH . '/' . $this->helper->getConfig('catimage'), 'images'); |
||
| 128 | $imgurl_select = new \XoopsFormSelect('', 'imgurl', $this->getVar('imgurl')); |
||
| 129 | $imgurl_select->addOptionArray($graph_array); |
||
| 130 | $imgurl_select->setExtra("onchange='showImgSelected(\"image\", \"imgurl\", \"" . $this->helper->getConfig('catimage') . '", "", "' . XOOPS_URL . "\")'"); |
||
| 131 | $imgurl_tray->addElement($imgurl_select, false); |
||
| 132 | $imgurl_tray->addElement(new \XoopsFormLabel('', "<img src='" . XOOPS_URL . '/' . $imgurl_path . "' name='image' id='image' alt=''>")); |
||
| 133 | $imgurl_tray->addElement(new \XoopsFormFile(\_AM_WFDOWNLOADS_BUPLOAD, 'uploadfile', 0), false); |
||
| 134 | $form->addElement($imgurl_tray); |
||
| 135 | // category: description |
||
| 136 | $description_textarea = new \XoopsFormDhtmlTextArea(\_AM_WFDOWNLOADS_FCATEGORY_DESCRIPTION, 'description', $this->getVar('description', 'e'), 15, 60); |
||
| 137 | $description_textarea->setDescription(\_AM_WFDOWNLOADS_FCATEGORY_DESCRIPTION_DESC); |
||
| 138 | $form->addElement($description_textarea, true); |
||
| 139 | // category: summary |
||
| 140 | $summary_textarea = new \XoopsFormTextArea(\_AM_WFDOWNLOADS_FCATEGORY_SUMMARY, 'summary', $this->getVar('summary'), 10, 60); |
||
| 141 | $summary_textarea->setDescription(\_AM_WFDOWNLOADS_FCATEGORY_SUMMARY_DESC); |
||
| 142 | $form->addElement($summary_textarea); |
||
| 143 | // category: dohtml, dosmiley, doxcode, doimage, dobr |
||
| 144 | $options_tray = new \XoopsFormElementTray(\_AM_WFDOWNLOADS_TEXTOPTIONS, ' '); |
||
| 145 | $options_tray->setDescription(\_AM_WFDOWNLOADS_TEXTOPTIONS_DESC); |
||
| 146 | $html_checkbox = new \XoopsFormCheckBox('', 'dohtml', $this->getVar('dohtml')); |
||
| 147 | $html_checkbox->addOption(1, \_AM_WFDOWNLOADS_ALLOWHTML); |
||
| 148 | $options_tray->addElement($html_checkbox); |
||
| 149 | $smiley_checkbox = new \XoopsFormCheckBox('', 'dosmiley', $this->getVar('dosmiley')); |
||
| 150 | $smiley_checkbox->addOption(1, \_AM_WFDOWNLOADS_ALLOWSMILEY); |
||
| 151 | $options_tray->addElement($smiley_checkbox); |
||
| 152 | $xcodes_checkbox = new \XoopsFormCheckBox('', 'doxcode', $this->getVar('doxcode')); |
||
| 153 | $xcodes_checkbox->addOption(1, \_AM_WFDOWNLOADS_ALLOWXCODE); |
||
| 154 | $options_tray->addElement($xcodes_checkbox); |
||
| 155 | $noimages_checkbox = new \XoopsFormCheckBox('', 'doimage', $this->getVar('doimage')); |
||
| 156 | $noimages_checkbox->addOption(1, \_AM_WFDOWNLOADS_ALLOWIMAGES); |
||
| 157 | $options_tray->addElement($noimages_checkbox); |
||
| 158 | $breaks_checkbox = new \XoopsFormCheckBox('', 'dobr', $this->getVar('dobr')); |
||
| 159 | $breaks_checkbox->addOption(1, \_AM_WFDOWNLOADS_ALLOWBREAK); |
||
| 160 | $options_tray->addElement($breaks_checkbox); |
||
| 161 | $form->addElement($options_tray); |
||
| 162 | // Formulize module support (2006/05/04) jpc - start |
||
| 163 | // category: formulize_fid |
||
| 164 | if (Utility::checkModule('formulize')) { |
||
| 165 | if (\is_file(XOOPS_ROOT_PATH . '/modules/formulize/include/functions.php')) { |
||
| 166 | require_once XOOPS_ROOT_PATH . '/modules/formulize/include/functions.php'; |
||
| 167 | $fids = allowedForms(); // is a Formulize function |
||
| 168 | $fids_select = []; |
||
| 169 | $fids_select[0] = \_AM_WFDOWNLOADS_FFS_STANDARD_FORM; |
||
| 170 | foreach ($fids as $fid) { |
||
| 171 | $fids_select[$fid] = \getFormTitle($fid); // is a Formulize function |
||
| 172 | } |
||
| 173 | |||
| 174 | $formulize_forms = new \XoopsFormSelect(\_AM_WFDOWNLOADS_FFS_CUSTOM_FORM, 'formulize_fid', $this->getVar('formulize_fid')); |
||
| 175 | $formulize_forms->addOptionArray($fids_select); |
||
| 176 | $form->addElement($formulize_forms); |
||
| 177 | } |
||
| 178 | } |
||
| 179 | // Formulize module support (2006/05/04) jpc - end |
||
| 180 | // form: buttons |
||
| 181 | $buttonTray = new \XoopsFormElementTray('', ''); |
||
| 182 | $buttonTray->addElement(new \XoopsFormHidden('op', 'category.save')); |
||
| 183 | if ($this->isNew()) { |
||
| 184 | $button_create = new \XoopsFormButton('', '', _SUBMIT, 'submit'); |
||
| 185 | $button_create->setExtra('onclick="this.form.elements.op.value=\'category.save\'"'); |
||
| 186 | $buttonTray->addElement($button_create); |
||
| 187 | } else { |
||
| 188 | $form->addElement(new \XoopsFormHidden('cid', $this->getVar('cid'))); |
||
| 189 | $button_create = new \XoopsFormButton('', '', _SUBMIT, 'submit'); |
||
| 190 | $button_create->setExtra('onclick="this.form.elements.op.value=\'category.save\'"'); |
||
| 191 | $buttonTray->addElement($button_create); |
||
| 192 | $deleteButton = new \XoopsFormButton('', '', _DELETE, 'submit'); |
||
| 193 | $deleteButton->setExtra('onclick="this.form.elements.op.value=\'category.delete\'"'); |
||
| 194 | $buttonTray->addElement($deleteButton); |
||
| 195 | } |
||
| 196 | $button_reset = new \XoopsFormButton('', '', _RESET, 'reset'); |
||
| 197 | $buttonTray->addElement($button_reset); |
||
| 198 | $buttonCancel = new \XoopsFormButton('', '', _CANCEL, 'button'); |
||
| 199 | $buttonCancel->setExtra('onclick="history.go(-1)"'); |
||
| 200 | $buttonTray->addElement($buttonCancel); |
||
| 201 | $form->addElement($buttonTray); |
||
| 202 | |||
| 203 | return $form; |
||
| 204 | } |
||
| 206 |