| Conditions | 8 |
| Paths | 128 |
| Total Lines | 99 |
| 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 |
||
| 53 | public function getForm($action = false) |
||
| 54 | { |
||
| 55 | global $xoopsDB, $xoopsModule, $xoopsModuleConfig; |
||
| 56 | if ($action === false) { |
||
| 57 | $action = $_SERVER['REQUEST_URI']; |
||
| 58 | } |
||
| 59 | include_once(XOOPS_ROOT_PATH."/class/xoopsformloader.php"); |
||
| 60 | |||
| 61 | //nom du formulaire selon l'action (editer ou ajouter): |
||
| 62 | $title = $this->isNew() ? sprintf(_AM_TDMDOWNLOADS_FORMADD) : sprintf(_AM_TDMDOWNLOADS_FORMEDIT); |
||
| 63 | |||
| 64 | //création du formulaire |
||
| 65 | $form = new XoopsThemeForm($title, 'form', $action, 'post', true); |
||
| 66 | $form->setExtra('enctype="multipart/form-data"'); |
||
| 67 | //titre |
||
| 68 | $form->addElement(new XoopsFormText(_AM_TDMDOWNLOADS_FORMTITLE, 'cat_title', 50, 255, $this->getVar('cat_title')), true); |
||
|
|
|||
| 69 | //editeur |
||
| 70 | $editor_configs=array(); |
||
| 71 | $editor_configs["name"] ="cat_description_main"; |
||
| 72 | $editor_configs["value"] = $this->getVar('cat_description_main', 'e'); |
||
| 73 | $editor_configs["rows"] = 20; |
||
| 74 | $editor_configs["cols"] = 160; |
||
| 75 | $editor_configs["width"] = "100%"; |
||
| 76 | $editor_configs["height"] = "400px"; |
||
| 77 | $editor_configs["editor"] = $xoopsModuleConfig['editor']; |
||
| 78 | $form->addElement( new XoopsFormEditor(_AM_TDMDOWNLOADS_FORMTEXT, "cat_description_main", $editor_configs), false); |
||
| 79 | //image |
||
| 80 | $downloadscat_img = $this->getVar('cat_imgurl') ? $this->getVar('cat_imgurl') : 'blank.gif'; |
||
| 81 | $uploadirectory='/uploads/TDMDownloads/images/cats'; |
||
| 82 | $imgtray = new XoopsFormElementTray(_AM_TDMDOWNLOADS_FORMIMG,'<br />'); |
||
| 83 | $imgpath=sprintf(_AM_TDMDOWNLOADS_FORMPATH, $uploadirectory ); |
||
| 84 | $imageselect= new XoopsFormSelect($imgpath, 'downloadscat_img',$downloadscat_img); |
||
| 85 | $topics_array = XoopsLists :: getImgListAsArray( XOOPS_ROOT_PATH . $uploadirectory ); |
||
| 86 | foreach ($topics_array as $image) { |
||
| 87 | $imageselect->addOption("$image", $image); |
||
| 88 | } |
||
| 89 | $imageselect->setExtra( "onchange='showImgSelected(\"image3\", \"downloadscat_img\", \"" . $uploadirectory . "\", \"\", \"" . XOOPS_URL . "\")'" ); |
||
| 90 | $imgtray->addElement($imageselect,false); |
||
| 91 | $imgtray -> addElement( new XoopsFormLabel( '', "<br /><img src='" . XOOPS_URL . "/" . $uploadirectory . "/" . $downloadscat_img . "' name='image3' id='image3' alt='' />" ) ); |
||
| 92 | $fileseltray= new XoopsFormElementTray('','<br />'); |
||
| 93 | $fileseltray->addElement(new XoopsFormFile(_AM_TDMDOWNLOADS_FORMUPLOAD , 'attachedfile', $xoopsModuleConfig['maxuploadsize']), false); |
||
| 94 | $fileseltray->addElement(new XoopsFormLabel('' ), false); |
||
| 95 | $imgtray->addElement($fileseltray); |
||
| 96 | $form->addElement($imgtray); |
||
| 97 | // Pour faire une sous-catégorie |
||
| 98 | $downloadscat_Handler = xoops_getModuleHandler('tdmdownloads_cat', 'TDMDownloads'); |
||
| 99 | $criteria = new CriteriaCompo(); |
||
| 100 | $criteria->setSort('cat_weight ASC, cat_title'); |
||
| 101 | $criteria->setOrder('ASC'); |
||
| 102 | $downloadscat_arr = $downloadscat_Handler->getall($criteria); |
||
| 103 | $mytree = new XoopsObjectTree($downloadscat_arr, 'cat_cid', 'cat_pid'); |
||
| 104 | $form->addElement($mytree->makeSelectElement('cat_pid', 'cat_title', '--', $this->getVar('cat_pid'), true, 0, '', _AM_TDMDOWNLOADS_FORMINCAT), true); |
||
| 105 | //poids de la catégorie |
||
| 106 | $form->addElement(new XoopsFormText(_AM_TDMDOWNLOADS_FORMWEIGHT, 'cat_weight', 5, 5, $this->getVar('cat_weight', 'e')), false); |
||
| 107 | |||
| 108 | //permissions |
||
| 109 | $member_handler = xoops_gethandler('member'); |
||
| 110 | $group_list = $member_handler->getGroupList(); |
||
| 111 | $gperm_handler = xoops_gethandler('groupperm'); |
||
| 112 | $full_list = array_keys($group_list); |
||
| 113 | global $xoopsModule; |
||
| 114 | if (!$this->isNew()) { |
||
| 115 | $groups_ids_view = $gperm_handler->getGroupIds('tdmdownloads_view', $this->getVar('cat_cid'), $xoopsModule->getVar('mid')); |
||
| 116 | $groups_ids_submit = $gperm_handler->getGroupIds('tdmdownloads_submit', $this->getVar('cat_cid'), $xoopsModule->getVar('mid')); |
||
| 117 | $groups_ids_download = $gperm_handler->getGroupIds('tdmdownloads_download', $this->getVar('cat_cid'), $xoopsModule->getVar('mid')); |
||
| 118 | $groups_ids_view = array_values($groups_ids_view); |
||
| 119 | $groups_news_can_view_checkbox = new XoopsFormCheckBox(_AM_TDMDOWNLOADS_PERM_VIEW_DSC, 'groups_view[]', $groups_ids_view); |
||
| 120 | $groups_ids_submit = array_values($groups_ids_submit); |
||
| 121 | $groups_news_can_submit_checkbox = new XoopsFormCheckBox(_AM_TDMDOWNLOADS_PERM_SUBMIT_DSC, 'groups_submit[]', $groups_ids_submit); |
||
| 122 | $groups_ids_download = array_values($groups_ids_download); |
||
| 123 | $groups_news_can_download_checkbox = new XoopsFormCheckBox(_AM_TDMDOWNLOADS_PERM_DOWNLOAD_DSC, 'groups_download[]', $groups_ids_download); |
||
| 124 | } else { |
||
| 125 | $groups_news_can_view_checkbox = new XoopsFormCheckBox(_AM_TDMDOWNLOADS_PERM_VIEW_DSC, 'groups_view[]', $full_list); |
||
| 126 | $groups_news_can_submit_checkbox = new XoopsFormCheckBox(_AM_TDMDOWNLOADS_PERM_SUBMIT_DSC, 'groups_submit[]', $full_list); |
||
| 127 | $groups_news_can_download_checkbox = new XoopsFormCheckBox(_AM_TDMDOWNLOADS_PERM_DOWNLOAD_DSC, 'groups_download[]', $full_list); |
||
| 128 | } |
||
| 129 | // pour voir |
||
| 130 | $groups_news_can_view_checkbox->addOptionArray($group_list); |
||
| 131 | $form->addElement($groups_news_can_view_checkbox); |
||
| 132 | // pour editer |
||
| 133 | $groups_news_can_submit_checkbox->addOptionArray($group_list); |
||
| 134 | $form->addElement($groups_news_can_submit_checkbox); |
||
| 135 | // pour télécharger |
||
| 136 | if ($xoopsModuleConfig['permission_download'] == 1) { |
||
| 137 | $groups_news_can_download_checkbox->addOptionArray($group_list); |
||
| 138 | $form->addElement($groups_news_can_download_checkbox); |
||
| 139 | } |
||
| 140 | |||
| 141 | // pour passer "cid" si on modifie la catégorie |
||
| 142 | if (!$this->isNew()) { |
||
| 143 | $form->addElement(new XoopsFormHidden('cat_cid', $this->getVar('cat_cid'))); |
||
| 144 | $form->addElement(new XoopsFormHidden('categorie_modified', true)); |
||
| 145 | } |
||
| 146 | //pour enregistrer le formulaire |
||
| 147 | $form->addElement(new XoopsFormHidden('op', 'save_cat')); |
||
| 148 | //boutton d'envoi du formulaire |
||
| 149 | $form->addElement(new XoopsFormButton('', 'submit', _SUBMIT, 'submit')); |
||
| 150 | |||
| 151 | return $form; |
||
| 152 | } |
||
| 166 |