| Conditions | 6 |
| Paths | 16 |
| Total Lines | 92 |
| Code Lines | 73 |
| 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 namespace XoopsModules\Tdmcreate; |
||
| 138 | public function getFormSettings($action = false) |
||
| 139 | { |
||
| 140 | $helper = Tdmcreate\Helper::getInstance(); |
||
| 141 | if (false === $action) { |
||
| 142 | $action = $_SERVER['REQUEST_URI']; |
||
| 143 | } |
||
| 144 | |||
| 145 | $isNew = $this->isNew(); |
||
| 146 | $title = $isNew ? sprintf(_AM_TDMCREATE_SETTING_NEW) : sprintf(_AM_TDMCREATE_SETTING_EDIT); |
||
| 147 | |||
| 148 | include_once XOOPS_ROOT_PATH . '/class/xoopsformloader.php'; |
||
| 149 | |||
| 150 | $form = new \XoopsThemeForm($title, 'settingform', $action, 'post', true); |
||
| 151 | $form->setExtra('enctype="multipart/form-data"'); |
||
| 152 | |||
| 153 | $form->addElement(new \XoopsFormHidden('set_id', $this->getVar('set_id'))); |
||
|
|
|||
| 154 | $form->addElement(new \XoopsFormText(_AM_TDMCREATE_SETTING_NAME, 'set_name', 50, 255, $this->getVar('set_name'))); |
||
| 155 | $form->addElement(new \XoopsFormText(_AM_TDMCREATE_SETTING_DIRNAME, 'set_dirname', 25, 255, $this->getVar('set_dirname'))); |
||
| 156 | $form->addElement(new \XoopsFormText(_AM_TDMCREATE_SETTING_VERSION, 'set_version', 10, 25, $this->getVar('set_version'))); |
||
| 157 | $form->addElement(new \XoopsFormText(_AM_TDMCREATE_SETTING_SINCE, 'set_since', 10, 25, $this->getVar('set_since'))); |
||
| 158 | $form->addElement(new \XoopsFormText(_AM_TDMCREATE_SETTING_MIN_PHP, 'set_min_php', 10, 25, $this->getVar('set_min_php'))); |
||
| 159 | $form->addElement(new \XoopsFormText(_AM_TDMCREATE_SETTING_MIN_XOOPS, 'set_min_xoops', 10, 25, $this->getVar('set_min_xoops'))); |
||
| 160 | $form->addElement(new \XoopsFormText(_AM_TDMCREATE_SETTING_MIN_ADMIN, 'set_min_admin', 10, 25, $this->getVar('set_min_admin'))); |
||
| 161 | $form->addElement(new \XoopsFormText(_AM_TDMCREATE_SETTING_MIN_MYSQL, 'set_min_mysql', 10, 25, $this->getVar('set_min_mysql'))); |
||
| 162 | $form->addElement(new \XoopsFormTextArea(_AM_TDMCREATE_SETTING_DESCRIPTION, 'set_description', $this->getVar('set_description'), 4, 25)); |
||
| 163 | $form->addElement(new \XoopsFormText(_AM_TDMCREATE_SETTING_AUTHOR, 'set_author', 50, 255, $this->getVar('set_author'))); |
||
| 164 | $form->addElement(new \XoopsFormText(_AM_TDMCREATE_SETTING_LICENSE, 'set_license', 50, 255, $this->getVar('set_license'))); |
||
| 165 | // Check All Settings Options |
||
| 166 | $optionsTray = new \XoopsFormElementTray(_OPTIONS, '<br>'); |
||
| 167 | $checkAllOptions = new \XoopsFormCheckBox('', 'settingbox', 1); |
||
| 168 | $checkAllOptions->addOption('allbox', _AM_TDMCREATE_SETTING_ALL); |
||
| 169 | $checkAllOptions->setExtra(' onclick="xoopsCheckAll(\'settingform\', \'settingbox\');" '); |
||
| 170 | $checkAllOptions->setClass('xo-checkall'); |
||
| 171 | $optionsTray->addElement($checkAllOptions); |
||
| 172 | // Options |
||
| 173 | $settingOption = $this->getOptionsSettings(); |
||
| 174 | $checkbox = new \XoopsFormCheckbox(' ', 'setting_option', $settingOption, '<br>'); |
||
| 175 | $checkbox->setDescription(_AM_TDMCREATE_OPTIONS_DESC); |
||
| 176 | foreach ($this->options as $option) { |
||
| 177 | $checkbox->addOption($option, self::getDefinedLanguage('_AM_TDMCREATE_SETTING_' . mb_strtoupper($option))); |
||
| 178 | } |
||
| 179 | $optionsTray->addElement($checkbox); |
||
| 180 | |||
| 181 | $form->addElement($optionsTray); |
||
| 182 | |||
| 183 | $modImage = $this->getVar('set_image'); |
||
| 184 | $modImage = $modImage ?: $set['image']; |
||
| 185 | |||
| 186 | $uploadDirectory = 'uploads/' . $GLOBALS['xoopsModule']->dirname() . '/images/modules'; |
||
| 187 | $imgtray = new \XoopsFormElementTray(_AM_TDMCREATE_SETTING_IMAGE, '<br>'); |
||
| 188 | $imgpath = sprintf(_AM_TDMCREATE_FORMIMAGE_PATH, './' . mb_strtolower($uploadDirectory) . '/'); |
||
| 189 | $imageSelect = new \XoopsFormSelect($imgpath, 'set_image', $modImage); |
||
| 190 | $modImage_array = \XoopsLists::getImgListAsArray(TDMC_UPLOAD_IMGMOD_PATH); |
||
| 191 | foreach ($modImage_array as $image) { |
||
| 192 | $imageSelect->addOption($image, $image); |
||
| 193 | } |
||
| 194 | $imageSelect->setExtra("onchange='showImgSelected(\"image3\", \"set_image\", \"" . $uploadDirectory . '", "", "' . XOOPS_URL . "\")'"); |
||
| 195 | $imgtray->addElement($imageSelect); |
||
| 196 | $imgtray->addElement(new \XoopsFormLabel('', "<br><img src='" . TDMC_UPLOAD_IMGMOD_URL . '/' . $modImage . "' name='image3' id='image3' alt='' /><br>")); |
||
| 197 | |||
| 198 | $fileseltray = new \XoopsFormElementTray('', '<br>'); |
||
| 199 | $fileseltray->addElement(new \XoopsFormFile(_AM_TDMCREATE_FORMUPLOAD, 'attachedfile', $helper->getConfig('maxsize'))); |
||
| 200 | $fileseltray->addElement(new \XoopsFormLabel('')); |
||
| 201 | $imgtray->addElement($fileseltray); |
||
| 202 | $form->addElement($imgtray); |
||
| 203 | |||
| 204 | $form->addElement(new \XoopsFormText(_AM_TDMCREATE_SETTING_AUTHOR_MAIL, 'set_author_mail', 50, 255, $this->getVar('set_author_mail'))); |
||
| 205 | $form->addElement(new \XoopsFormText(_AM_TDMCREATE_SETTING_AUTHOR_WEBSITE_URL, 'set_author_website_url', 50, 255, $this->getVar('set_author_website_url'))); |
||
| 206 | $form->addElement(new \XoopsFormText(_AM_TDMCREATE_SETTING_AUTHOR_WEBSITE_NAME, 'set_author_website_name', 50, 255, $this->getVar('set_author_website_name'))); |
||
| 207 | $form->addElement(new \XoopsFormText(_AM_TDMCREATE_SETTING_CREDITS, 'set_credits', 50, 255, $this->getVar('set_credits'))); |
||
| 208 | $form->addElement(new \XoopsFormText(_AM_TDMCREATE_SETTING_RELEASE_INFO, 'set_release_info', 50, 255, $this->getVar('set_release_info'))); |
||
| 209 | $form->addElement(new \XoopsFormText(_AM_TDMCREATE_SETTING_RELEASE_FILE, 'set_release_file', 50, 255, $this->getVar('set_release_file'))); |
||
| 210 | $form->addElement(new \XoopsFormText(_AM_TDMCREATE_SETTING_MANUAL, 'set_manual', 50, 255, $this->getVar('set_manual'))); |
||
| 211 | $form->addElement(new \XoopsFormText(_AM_TDMCREATE_SETTING_MANUAL_FILE, 'set_manual_file', 50, 255, $this->getVar('set_manual_file'))); |
||
| 212 | $form->addElement(new \XoopsFormText(_AM_TDMCREATE_SETTING_DEMO_SITE_URL, 'set_demo_site_url', 50, 255, $this->getVar('set_demo_site_url'))); |
||
| 213 | $form->addElement(new \XoopsFormText(_AM_TDMCREATE_SETTING_DEMO_SITE_NAME, 'set_demo_site_name', 50, 255, $this->getVar('set_demo_site_name'))); |
||
| 214 | $form->addElement(new \XoopsFormText(_AM_TDMCREATE_SETTING_SUPPORT_URL, 'set_support_url', 50, 255, $this->getVar('set_support_url'))); |
||
| 215 | $form->addElement(new \XoopsFormText(_AM_TDMCREATE_SETTING_SUPPORT_NAME, 'set_support_name', 50, 255, $this->getVar('set_support_name'))); |
||
| 216 | $form->addElement(new \XoopsFormText(_AM_TDMCREATE_SETTING_WEBSITE_URL, 'set_website_url', 50, 255, $this->getVar('set_website_url'))); |
||
| 217 | $form->addElement(new \XoopsFormText(_AM_TDMCREATE_SETTING_WEBSITE_NAME, 'set_website_name', 50, 255, $this->getVar('set_website_name'))); |
||
| 218 | // Form Text Date Select |
||
| 219 | $form->addElement(new \XoopsFormTextDateSelect(_AM_TDMCREATE_SETTING_RELEASE, 'set_release', '', $this->getVar('set_release'))); |
||
| 220 | $form->addElement(new \XoopsFormText(_AM_TDMCREATE_SETTING_STATUS, 'set_status', 50, 255, $this->getVar('set_status'))); |
||
| 221 | $form->addElement(new \XoopsFormText(_AM_TDMCREATE_SETTING_PAYPAL_BUTTON, 'set_donations', 50, 255, $this->getVar('set_donations'))); |
||
| 222 | $form->addElement(new \XoopsFormText(_AM_TDMCREATE_SETTING_SUBVERSION, 'set_subversion', 50, 255, $this->getVar('set_subversion'))); |
||
| 223 | |||
| 224 | $buttonTray = new \XoopsFormElementTray(_REQUIRED . ' <sup class="red bold">*</sup>', ''); |
||
| 225 | $buttonTray->addElement(new \XoopsFormHidden('op', 'save')); |
||
| 226 | $buttonTray->addElement(new \XoopsFormButton('', 'submit', _SUBMIT, 'submit')); |
||
| 227 | $form->addElement($buttonTray); |
||
| 228 | |||
| 229 | return $form; |
||
| 230 | } |
||
| 288 |