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