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