Conditions | 6 |
Paths | 32 |
Total Lines | 58 |
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 |
||
50 | public function getForm($action = false) |
||
51 | { |
||
52 | global $xoopsDB, $xoopsModuleConfig; |
||
53 | |||
54 | if (false === $action) { |
||
55 | $action = $_SERVER['REQUEST_URI']; |
||
56 | } |
||
57 | |||
58 | $title = $this->isNew() ? sprintf(_AM_PRESENTER_CAT_ADD) : sprintf(_AM_PRESENTER_CAT_EDIT); |
||
59 | |||
60 | require_once XOOPS_ROOT_PATH . '/class/xoopsformloader.php'; |
||
61 | |||
62 | $form = new XoopsThemeForm($title, 'form', $action, 'post', true); |
||
63 | $form->setExtra('enctype="multipart/form-data"'); |
||
64 | |||
65 | // Cat_pid |
||
66 | require_once XOOPS_ROOT_PATH . '/class/tree.php'; |
||
67 | $categoriesHandler = xoops_getModuleHandler('categories', 'presenter'); |
||
68 | $criteria = new CriteriaCompo(); |
||
69 | $categories = $categoriesHandler->getObjects($criteria); |
||
70 | if ($categories) { |
||
71 | $categories_tree = new XoopsObjectTree($categories, 'cat_id', 'cat_pid'); |
||
72 | $cat_pid = $categories_tree->makeSelBox('cat_pid', 'cat_title', '--', $this->getVar('cat_pid', 'e'), false); |
||
73 | $form->addElement(new XoopsFormLabel(_AM_PRESENTER_CAT_PID, $cat_pid)); |
||
74 | } |
||
75 | // Cat_title |
||
76 | $form->addElement(new XoopsFormText(_AM_PRESENTER_CAT_TITLE, 'cat_title', 50, 255, $this->getVar('cat_title')), true); |
||
77 | // Cat_desc |
||
78 | $form->addElement(new XoopsFormTextArea(_AM_PRESENTER_CAT_DESC, 'cat_desc', $this->getVar('cat_desc'), 4, 47), true); |
||
79 | // Cat_image |
||
80 | $cat_image = $this->getVar('cat_image') ? $this->getVar('cat_image') : 'blank.gif'; |
||
81 | |||
82 | $uploadir = '/uploads/presenter/images/categories'; |
||
83 | $imgtray = new XoopsFormElementTray(_AM_PRESENTER_CAT_IMAGE, '<br>'); |
||
84 | $imgpath = sprintf(_AM_PRESENTER_FORMIMAGE_PATH, $uploadir); |
||
85 | $imageselect = new XoopsFormSelect($imgpath, 'cat_image', $cat_image); |
||
86 | $image_array = XoopsLists::getImgListAsArray(XOOPS_ROOT_PATH . $uploadir); |
||
87 | foreach ($image_array as $image) { |
||
88 | $imageselect->addOption("{$image}", $image); |
||
89 | } |
||
90 | $imageselect->setExtra("onchange='showImgSelected(\"image_cat_image\", \"cat_image\", \"" . $uploadir . "\", \"\", \"" . XOOPS_URL . "\")'"); |
||
91 | $imgtray->addElement($imageselect); |
||
92 | $imgtray->addElement(new XoopsFormLabel('', "<br><img src='" . XOOPS_URL . '/' . $uploadir . '/' . $cat_image . "' name='image_cat_image' id='image_cat_image' alt=''>")); |
||
93 | $fileseltray = new XoopsFormElementTray('', '<br>'); |
||
94 | $fileseltray->addElement(new XoopsFormFile(_AM_PRESENTER_FORMUPLOAD, 'cat_image', $xoopsModuleConfig['maxsize'])); |
||
95 | $fileseltray->addElement(new XoopsFormLabel('')); |
||
96 | $imgtray->addElement($fileseltray); |
||
97 | $form->addElement($imgtray); |
||
98 | // Cat_weight |
||
99 | $form->addElement(new XoopsFormText(_AM_PRESENTER_CAT_WEIGHT, 'cat_weight', 50, 255, $this->getVar('cat_weight')), false); |
||
100 | // Cat_color |
||
101 | // $form->addElement(new XoopsFormColorPicker(_AM_PRESENTER_CAT_COLOR, 'cat_color', $this->getVar('cat_color')), false); |
||
102 | |||
103 | $form->addElement(new XoopsFormHidden('op', 'save')); |
||
104 | $form->addElement(new XoopsFormButton('', 'submit', _SUBMIT, 'submit')); |
||
105 | |||
106 | return $form; |
||
107 | } |
||
108 | } |
||
124 |