| Conditions | 9 |
| Paths | 32 |
| Total Lines | 63 |
| Code Lines | 42 |
| 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 |
||
| 65 | public function getForm($action = false) |
||
| 66 | { |
||
| 67 | /** @var \XoopsModules\Tdmdownloads\Helper $helper */ |
||
| 68 | $helper = \XoopsModules\Tdmdownloads\Helper::getInstance(); |
||
| 69 | |||
| 70 | $moduleDirName = basename(dirname(__DIR__)); |
||
| 71 | if (false === $action) { |
||
| 72 | $action = $_SERVER['REQUEST_URI']; |
||
| 73 | } |
||
| 74 | require_once XOOPS_ROOT_PATH . '/class/xoopsformloader.php'; |
||
| 75 | |||
| 76 | //nom du formulaire selon l'action (editer ou ajouter): |
||
| 77 | $title = $this->isNew() ? sprintf(_AM_TDMDOWNLOADS_FORMADD) : sprintf(_AM_TDMDOWNLOADS_FORMEDIT); |
||
| 78 | |||
| 79 | //création du formulaire |
||
| 80 | $form = new \XoopsThemeForm($title, 'form', $action, 'post', true); |
||
| 81 | $form->setExtra('enctype="multipart/form-data"'); |
||
| 82 | //titre |
||
| 83 | if (1 == $this->getVar('status_def')) { |
||
| 84 | $form->addElement(new \XoopsFormLabel(_AM_TDMDOWNLOADS_FORMTITLE, $this->getVar('title'))); |
||
| 85 | $form->addElement(new \XoopsFormHidden('title', $this->getVar('title'))); |
||
| 86 | } else { |
||
| 87 | $form->addElement(new \XoopsFormText(_AM_TDMDOWNLOADS_FORMTITLE, 'title', 50, 255, $this->getVar('title')), true); |
||
| 88 | } |
||
| 89 | //image |
||
| 90 | $downloadsfield_img = $this->getVar('img') ?: 'blank.gif'; |
||
| 91 | $uploadirectory = '/uploads/' . $moduleDirName . '/images/field'; |
||
| 92 | $imgtray = new \XoopsFormElementTray(_AM_TDMDOWNLOADS_FORMIMAGE, '<br>'); |
||
| 93 | $imgpath = sprintf(_AM_TDMDOWNLOADS_FORMPATH, $uploadirectory); |
||
| 94 | $imageselect = new \XoopsFormSelect($imgpath, 'downloadsfield_img', $downloadsfield_img); |
||
| 95 | $topics_array = \XoopsLists:: getImgListAsArray(XOOPS_ROOT_PATH . $uploadirectory); |
||
| 96 | foreach ($topics_array as $image) { |
||
| 97 | $imageselect->addOption((string)$image, $image); |
||
| 98 | } |
||
| 99 | $imageselect->setExtra("onchange='showImgSelected(\"image3\", \"downloadsfield_img\", \"" . $uploadirectory . '", "", "' . XOOPS_URL . "\")'"); |
||
| 100 | $imgtray->addElement($imageselect, false); |
||
| 101 | $imgtray->addElement(new \XoopsFormLabel('', "<br><img src='" . XOOPS_URL . '/' . $uploadirectory . '/' . $downloadsfield_img . "' name='image3' id='image3' alt=''><br>")); |
||
| 102 | $fileseltray = new \XoopsFormElementTray('', '<br>'); |
||
| 103 | $fileseltray->addElement(new \XoopsFormFile(_AM_TDMDOWNLOADS_FORMUPLOAD, 'attachedfile', $helper->getConfig('maxuploadsize')), false); |
||
| 104 | $fileseltray->addElement(new \XoopsFormLabel(''), false); |
||
| 105 | $imgtray->addElement($fileseltray); |
||
| 106 | $form->addElement($imgtray); |
||
| 107 | //poids du champ |
||
| 108 | $form->addElement(new \XoopsFormText(_AM_TDMDOWNLOADS_FORMWEIGHT, 'weight', 5, 5, $this->getVar('weight', 'e')), false); |
||
| 109 | // affiché? |
||
| 110 | $status = $this->getVar('status') ?: 0; |
||
| 111 | $form->addElement(new \XoopsFormRadioYN(_AM_TDMDOWNLOADS_FORMAFFICHE, 'status', $status)); |
||
| 112 | // affiché dans le champ de recherche? |
||
| 113 | $search = $this->getVar('search') ?: 0; |
||
| 114 | $form->addElement(new \XoopsFormRadioYN(_AM_TDMDOWNLOADS_FORMAFFICHESEARCH, 'search', $search)); |
||
| 115 | // pour passer "fid" si on modifie le champ |
||
| 116 | if (!$this->isNew()) { |
||
| 117 | $form->addElement(new \XoopsFormHidden('fid', $this->getVar('fid'))); |
||
| 118 | $form->addElement(new \XoopsFormHidden('status_def', $this->getVar('status_def'))); |
||
| 119 | } else { |
||
| 120 | $form->addElement(new \XoopsFormHidden('status_def', 0)); |
||
| 121 | } |
||
| 122 | //pour enregistrer le formulaire |
||
| 123 | $form->addElement(new \XoopsFormHidden('op', 'save_field')); |
||
| 124 | //boutton d'envoi du formulaire |
||
| 125 | $form->addElement(new \XoopsFormButton('', 'submit', _SUBMIT, 'submit')); |
||
| 126 | |||
| 127 | return $form; |
||
| 128 | } |
||
| 130 |