| Conditions | 4 |
| Paths | 8 |
| Total Lines | 60 |
| Code Lines | 44 |
| 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 namespace XoopsModules\Extcal; |
||
| 64 | public function getForm($action = false) |
||
| 65 | { |
||
| 66 | global $xoopsDB, $extcalConfig; |
||
| 67 | |||
| 68 | if (false === $action) { |
||
| 69 | $action = $_SERVER['REQUEST_URI']; |
||
| 70 | } |
||
| 71 | |||
| 72 | $title = $this->isNew() ? sprintf(_MD_EXTCAL_LOCATION_ADD) : sprintf(_MD_EXTCAL_LOCATION_EDIT); |
||
| 73 | |||
| 74 | require_once XOOPS_ROOT_PATH . '/class/xoopsformloader.php'; |
||
| 75 | |||
| 76 | $form = new \XoopsThemeForm($title, 'form', $action, 'post', true); |
||
| 77 | $form->setExtra('enctype="multipart/form-data"'); |
||
| 78 | |||
| 79 | $form->addElement(new \XoopsFormText(_MD_EXTCAL_LOCATION_NOM, 'nom', 50, 255, $this->getVar('nom')), true); |
||
| 80 | $form->addElement(new \XoopsFormDhtmlTextArea(_MD_EXTCAL_LOCATION_DESCRIPTION, 'description', $this->getVar('description'), 10), false); |
||
| 81 | $form->addElement(new \XoopsFormText(_MD_EXTCAL_LOCATION_CATEGORIE, 'categorie', 40, 255, $this->getVar('categorie')), false); |
||
| 82 | $form->addElement(new \XoopsFormText(_MD_EXTCAL_LOCATION_ADRESSE, 'adresse', 50, 255, $this->getVar('adresse')), false); |
||
| 83 | $form->addElement(new \XoopsFormText(_MD_EXTCAL_LOCATION_ADRESSE2, 'adresse2', 50, 255, $this->getVar('adresse2')), false); |
||
| 84 | $form->addElement(new \XoopsFormText(_MD_EXTCAL_LOCATION_CP, 'cp', 10, 10, $this->getVar('cp')), false); |
||
| 85 | $form->addElement(new \XoopsFormText(_MD_EXTCAL_LOCATION_VILLE, 'ville', 20, 255, $this->getVar('ville')), false); |
||
| 86 | $form->addElement(new \XoopsFormText(_MD_EXTCAL_LOCATION_TEL_FIXE, 'tel_fixe', 20, 20, $this->getVar('tel_fixe')), false); |
||
| 87 | $form->addElement(new \XoopsFormText(_MD_EXTCAL_LOCATION_TEL_PORTABLE, 'tel_portable', 20, 20, $this->getVar('tel_portable')), false); |
||
| 88 | $form->addElement(new \XoopsFormText(_MD_EXTCAL_LOCATION_MAIL, 'mail', 50, 255, $this->getVar('mail')), false); |
||
| 89 | $form->addElement(new \XoopsFormText(_MD_EXTCAL_LOCATION_SITE, 'site', 50, 255, $this->getVar('site')), false); |
||
| 90 | $form->addElement(new \XoopsFormTextArea(_MD_EXTCAL_LOCATION_HORAIRES, 'horaires', $this->getVar('horaires'), 3, 40)); |
||
| 91 | $form->addElement(new \XoopsFormTextArea(_MD_EXTCAL_LOCATION_DIVERS, 'divers', $this->getVar('divers'), 5, 40)); |
||
| 92 | //$form->addElement( new \XoopsFormTextArea(_MD_EXTCAL_LOCATION_TARIFS, 'tarifs', $this->getVar("tarifs"), 5, 40)); |
||
| 93 | $form->addElement(new \XoopsFormText(_MD_EXTCAL_LOCATION_TARIFS . ' ( ' . _MD_EXTCAL_DEVISE2 . ' )', 'tarifs', 20, 20, $this->getVar('tarifs')), false); |
||
| 94 | |||
| 95 | //$form->addElement( new \XoopsFormTextArea(_MD_EXTCAL_LOCATION_MAP, 'map', $this->getVar("map"), 5, 40)); |
||
| 96 | $form->addElement(new \XoopsFormText(_MD_EXTCAL_LOCATION_MAP, 'map', 150, 255, $this->getVar('map')), false); |
||
| 97 | |||
| 98 | //Logo |
||
| 99 | $file_tray = new \XoopsFormElementTray(sprintf(_MD_EXTCAL_FORM_IMG, 2), ''); |
||
| 100 | if ('' != $this->getVar('logo')) { |
||
| 101 | $file_tray->addElement(new \XoopsFormLabel('', "<img src='" . XOOPS_URL . '/uploads/extcal/location/' . $this->getVar('logo') . "' name='image' id='image' alt=''><br><br>")); |
||
| 102 | $check_del_img = new \XoopsFormCheckBox('', 'delimg'); |
||
| 103 | $check_del_img->addOption(1, _MD_EXTCAL_DEL_IMG); |
||
| 104 | $file_tray->addElement($check_del_img); |
||
| 105 | $file_img = new \XoopsFormFile(_MD_EXTCAL_IMG, 'attachedimage', 3145728); |
||
| 106 | unset($check_del_img); |
||
| 107 | } else { |
||
| 108 | $file_img = new \XoopsFormFile('', 'attachedimage', 3145728); |
||
| 109 | } |
||
| 110 | $file_img->setExtra("size ='40'"); |
||
| 111 | $file_tray->addElement($file_img); |
||
| 112 | $msg = sprintf(_MD_EXTCAL_IMG_CONFIG, (int)(3145728 / 1000), 500, 500); |
||
| 113 | $file_label = new \XoopsFormLabel('', '<br>' . $msg); |
||
| 114 | $file_tray->addElement($file_label); |
||
| 115 | $form->addElement($file_tray); |
||
| 116 | $form->addElement(new \XoopsFormHidden('file', $this->getVar('logo'))); |
||
| 117 | unset($file_img, $file_tray); |
||
| 118 | |||
| 119 | $form->addElement(new \XoopsFormHidden('op', 'save_location')); |
||
| 120 | $form->addElement(new \XoopsFormButton('', 'submit', _SUBMIT, 'submit')); |
||
| 121 | $form->display(); |
||
| 122 | |||
| 123 | return $form; |
||
| 124 | } |
||
| 126 |