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