Conditions | 8 |
Paths | 64 |
Total Lines | 97 |
Code Lines | 74 |
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 |
||
73 | public function getForm($action = false) |
||
74 | { |
||
75 | $helper = Helper::getInstance(); |
||
76 | if (!$action) { |
||
77 | $action = $_SERVER['REQUEST_URI']; |
||
78 | } |
||
79 | $moduleDirName = \basename(\dirname(__DIR__)); |
||
80 | require_once XOOPS_ROOT_PATH . '/class/xoopsformloader.php'; |
||
81 | //nom du formulaire selon l'action (editer ou ajouter): |
||
82 | $title = $this->isNew() ? \sprintf(_AM_TDMDOWNLOADS_FORMADD) : \sprintf(_AM_TDMDOWNLOADS_FORMEDIT); |
||
83 | //création du formulaire |
||
84 | $form = new \XoopsThemeForm($title, 'form', $action, 'post', true); |
||
85 | $form->setExtra('enctype="multipart/form-data"'); |
||
86 | //titre |
||
87 | $form->addElement(new \XoopsFormText(_AM_TDMDOWNLOADS_FORMTITLE, 'cat_title', 50, 255, $this->getVar('cat_title')), true); |
||
|
|||
88 | //editeur |
||
89 | $editorConfigs = []; |
||
90 | $editorConfigs['name'] = 'cat_description_main'; |
||
91 | $editorConfigs['value'] = $this->getVar('cat_description_main', 'e'); |
||
92 | $editorConfigs['rows'] = 20; |
||
93 | $editorConfigs['cols'] = 160; |
||
94 | $editorConfigs['width'] = '100%'; |
||
95 | $editorConfigs['height'] = '400px'; |
||
96 | $editorConfigs['editor'] = $helper->getConfig('editor'); |
||
97 | $form->addElement(new \XoopsFormEditor(_AM_TDMDOWNLOADS_FORMTEXT, 'cat_description_main', $editorConfigs), false); |
||
98 | //image |
||
99 | $categoryImage = $this->getVar('cat_imgurl') ?: 'blank.gif'; |
||
100 | $uploadirectory = '/uploads/' . $moduleDirName . '/images/cats'; |
||
101 | $imgtray = new \XoopsFormElementTray(_AM_TDMDOWNLOADS_FORMIMG, '<br>'); |
||
102 | $imgpath = \sprintf(_AM_TDMDOWNLOADS_FORMPATH, $uploadirectory); |
||
103 | $imageselect = new \XoopsFormSelect($imgpath, 'downloadscat_img', $categoryImage); |
||
104 | $topics_array = \XoopsLists::getImgListAsArray(XOOPS_ROOT_PATH . $uploadirectory); |
||
105 | foreach ($topics_array as $image) { |
||
106 | $imageselect->addOption($image, $image); |
||
107 | } |
||
108 | $imageselect->setExtra("onchange='showImgSelected(\"image3\", \"downloadscat_img\", \"" . $uploadirectory . '", "", "' . XOOPS_URL . "\")'"); |
||
109 | $imgtray->addElement($imageselect, false); |
||
110 | $imgtray->addElement(new \XoopsFormLabel('', "<br><img src='" . XOOPS_URL . '/' . $uploadirectory . '/' . $categoryImage . "' name='image3' id='image3' alt=''>")); |
||
111 | $fileseltray = new \XoopsFormElementTray('', '<br>'); |
||
112 | $fileseltray->addElement(new \XoopsFormFile(_AM_TDMDOWNLOADS_FORMUPLOAD, 'attachedfile', $helper->getConfig('maxuploadsize')), false); |
||
113 | $fileseltray->addElement(new \XoopsFormLabel(''), false); |
||
114 | $imgtray->addElement($fileseltray); |
||
115 | $form->addElement($imgtray); |
||
116 | // Pour faire une sous-catégorie |
||
117 | $categoryHandler = Helper::getInstance()->getHandler('Category'); |
||
118 | $criteria = new \CriteriaCompo(); |
||
119 | $criteria->setSort('cat_weight ASC, cat_title'); |
||
120 | $criteria->setOrder('ASC'); |
||
121 | $downloadscatArray = $categoryHandler->getAll($criteria); |
||
122 | $mytree = new \XoopsModules\Tdmdownloads\Tree($downloadscatArray, 'cat_cid', 'cat_pid'); |
||
123 | $form->addElement($mytree->makeSelectElement('cat_pid', 'cat_title', '--', $this->getVar('cat_pid'), true, 0, '', _AM_TDMDOWNLOADS_FORMINCAT), true); |
||
124 | //poids de la catégorie |
||
125 | $form->addElement(new \XoopsFormText(_AM_TDMDOWNLOADS_FORMWEIGHT, 'cat_weight', 5, 5, $this->getVar('cat_weight', 'e')), false); |
||
126 | //permissions |
||
127 | /** @var \XoopsMemberHandler $memberHandler */ |
||
128 | $memberHandler = \xoops_getHandler('member'); |
||
129 | $group_list = $memberHandler->getGroupList(); |
||
130 | /** @var \XoopsGroupPermHandler $grouppermHandler */ |
||
131 | $grouppermHandler = \xoops_getHandler('groupperm'); |
||
132 | $full_list = \array_keys($group_list); |
||
133 | global $xoopsModule; |
||
134 | if (!$this->isNew()) { |
||
135 | $groups_ids_view = $grouppermHandler->getGroupIds('tdmdownloads_view', $this->getVar('cat_cid'), $xoopsModule->getVar('mid')); |
||
136 | $groups_ids_submit = $grouppermHandler->getGroupIds('tdmdownloads_submit', $this->getVar('cat_cid'), $xoopsModule->getVar('mid')); |
||
137 | $groups_ids_download = $grouppermHandler->getGroupIds('tdmdownloads_download', $this->getVar('cat_cid'), $xoopsModule->getVar('mid')); |
||
138 | $groups_ids_view = \array_values($groups_ids_view); |
||
139 | $groups_news_can_view_checkbox = new \XoopsFormCheckBox(_AM_TDMDOWNLOADS_PERM_VIEW_DSC, 'groups_view[]', $groups_ids_view); |
||
140 | $groups_ids_submit = \array_values($groups_ids_submit); |
||
141 | $groups_news_can_submit_checkbox = new \XoopsFormCheckBox(_AM_TDMDOWNLOADS_PERM_SUBMIT_DSC, 'groups_submit[]', $groups_ids_submit); |
||
142 | $groups_ids_download = \array_values($groups_ids_download); |
||
143 | $groups_news_can_download_checkbox = new \XoopsFormCheckBox(_AM_TDMDOWNLOADS_PERM_DOWNLOAD_DSC, 'groups_download[]', $groups_ids_download); |
||
144 | } else { |
||
145 | $groups_news_can_view_checkbox = new \XoopsFormCheckBox(_AM_TDMDOWNLOADS_PERM_VIEW_DSC, 'groups_view[]', $full_list); |
||
146 | $groups_news_can_submit_checkbox = new \XoopsFormCheckBox(_AM_TDMDOWNLOADS_PERM_SUBMIT_DSC, 'groups_submit[]', $full_list); |
||
147 | $groups_news_can_download_checkbox = new \XoopsFormCheckBox(_AM_TDMDOWNLOADS_PERM_DOWNLOAD_DSC, 'groups_download[]', $full_list); |
||
148 | } |
||
149 | // pour voir |
||
150 | $groups_news_can_view_checkbox->addOptionArray($group_list); |
||
151 | $form->addElement($groups_news_can_view_checkbox); |
||
152 | // pour editer |
||
153 | $groups_news_can_submit_checkbox->addOptionArray($group_list); |
||
154 | $form->addElement($groups_news_can_submit_checkbox); |
||
155 | // pour télécharger |
||
156 | if (1 == $helper->getConfig('permission_download')) { |
||
157 | $groups_news_can_download_checkbox->addOptionArray($group_list); |
||
158 | $form->addElement($groups_news_can_download_checkbox); |
||
159 | } |
||
160 | // pour passer "cid" si on modifie la catégorie |
||
161 | if (!$this->isNew()) { |
||
162 | $form->addElement(new \XoopsFormHidden('cat_cid', $this->getVar('cat_cid'))); |
||
163 | $form->addElement(new \XoopsFormHidden('categorie_modified', true)); |
||
164 | } |
||
165 | //pour enregistrer le formulaire |
||
166 | $form->addElement(new \XoopsFormHidden('op', 'save_cat')); |
||
167 | //boutton d'envoi du formulaire |
||
168 | $form->addElement(new \XoopsFormButtonTray('', \_SUBMIT, 'submit', 'submit', false)); |
||
169 | return $form; |
||
170 | } |
||
172 |