Conditions | 12 |
Paths | 512 |
Total Lines | 104 |
Code Lines | 79 |
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 |
||
132 | public function getFormTables($action = false) |
||
133 | { |
||
134 | if (false === $action) { |
||
135 | $action = \Xmf\Request::getString('REQUEST_URI', '', 'SERVER'); |
||
136 | } |
||
137 | $helper = Modulebuilder\Helper::getInstance(); |
||
138 | $isNew = $this->isNew(); |
||
139 | $tableName = $this->getVar('table_name'); |
||
140 | $tableMid = $this->getVar('table_mid'); |
||
141 | $title = $isNew ? \sprintf(\_AM_MODULEBUILDER_TABLES_NEW) : \sprintf(\_AM_MODULEBUILDER_TABLES_EDIT); |
||
142 | |||
143 | \xoops_load('XoopsFormLoader'); |
||
144 | $form = new \XoopsThemeForm($title, 'tableform', $action, 'post', true); |
||
145 | $form->setExtra('enctype="multipart/form-data"'); |
||
146 | |||
147 | $modules = $helper->getHandler('Modules')->getObjects(null); |
||
148 | $modulesSelect = new \XoopsFormSelect(\_AM_MODULEBUILDER_TABLE_MODULES, 'table_mid', $tableMid); |
||
149 | $modulesSelect->addOption('', \_AM_MODULEBUILDER_TABLE_MODSELOPT); |
||
150 | foreach ($modules as $mod) { |
||
151 | $modulesSelect->addOption($mod->getVar('mod_id'), $mod->getVar('mod_name')); |
||
152 | } |
||
153 | $form->addElement($modulesSelect, true); |
||
154 | |||
155 | $tableNameText = new \XoopsFormText(\_AM_MODULEBUILDER_TABLE_NAME, 'table_name', 40, 150, $tableName); |
||
|
|||
156 | $tableNameText->setDescription(\_AM_MODULEBUILDER_TABLE_NAME_DESC); |
||
157 | $form->addElement($tableNameText, true); |
||
158 | |||
159 | $tableSoleNameText = new \XoopsFormText(\_AM_MODULEBUILDER_TABLE_SOLENAME, 'table_solename', 40, 150, $this->getVar('table_solename')); |
||
160 | $tableSoleNameText->setDescription(\_AM_MODULEBUILDER_TABLE_SOLENAME_DESC); |
||
161 | $form->addElement($tableSoleNameText, true); |
||
162 | |||
163 | $radioCategory = $isNew ? 0 : $this->getVar('table_category'); |
||
164 | $category = new \XoopsFormRadioYN(\_AM_MODULEBUILDER_TABLE_CATEGORY, 'table_category', $radioCategory); |
||
165 | $category->setDescription(\_AM_MODULEBUILDER_TABLE_CATEGORY_DESC); |
||
166 | $form->addElement($category); |
||
167 | |||
168 | $tableFieldname = new \XoopsFormText(\_AM_MODULEBUILDER_TABLE_FIELDNAME, 'table_fieldname', 30, 50, $this->getVar('table_fieldname')); |
||
169 | $tableFieldname->setDescription(\_AM_MODULEBUILDER_TABLE_FIELDNAME_DESC); |
||
170 | $form->addElement($tableFieldname); |
||
171 | |||
172 | $tableNumbFileds = new \XoopsFormText(\_AM_MODULEBUILDER_TABLE_NBFIELDS, 'table_nbfields', 10, 25, $this->getVar('table_nbfields')); |
||
173 | $tableNumbFileds->setDescription(\_AM_MODULEBUILDER_TABLE_NBFIELDS_DESC); |
||
174 | $form->addElement($tableNumbFileds, true); |
||
175 | |||
176 | if (!$isNew) { |
||
177 | $tableOrder = new \XoopsFormText(\_AM_MODULEBUILDER_TABLE_ORDER, 'table_order', 5, 10, $this->getVar('table_order')); |
||
178 | $tableOrder->setDescription(\_AM_MODULEBUILDER_TABLE_ORDER_DESC); |
||
179 | $form->addElement($tableOrder, true); |
||
180 | } |
||
181 | |||
182 | $getTableImage = $this->getVar('table_image'); |
||
183 | $tableImage = $getTableImage ?: 'blank.gif'; |
||
184 | $icons32Directory = '/Frameworks/moduleclasses/icons/32'; |
||
185 | $uploadsDirectory = '/uploads/modulebuilder/images/tables'; |
||
186 | $iconsDirectory = \is_dir(\XOOPS_ROOT_PATH . $icons32Directory) ? $icons32Directory : $uploadsDirectory; |
||
187 | |||
188 | $imgtray1 = new \XoopsFormElementTray(\_AM_MODULEBUILDER_TABLE_IMAGE, '<br>'); |
||
189 | $imgpath1 = \sprintf(\_AM_MODULEBUILDER_FORMIMAGE_PATH, ".{$iconsDirectory}/"); |
||
190 | $imageSelect1 = new \XoopsFormSelect($imgpath1, 'table_image', $tableImage, 10); |
||
191 | $imageArray1 = \XoopsLists::getImgListAsArray(\XOOPS_ROOT_PATH . $iconsDirectory); |
||
192 | foreach ($imageArray1 as $image1) { |
||
193 | $imageSelect1->addOption($image1, $image1); |
||
194 | } |
||
195 | $imageSelect1->setExtra("onchange='showImgSelected(\"image1\", \"table_image\", \"" . $iconsDirectory . '", "", "' . \XOOPS_URL . "\")'"); |
||
196 | $imgtray1->addElement($imageSelect1, false); |
||
197 | $imgtray1->addElement(new \XoopsFormLabel('', "<br><img src='" . \XOOPS_URL . '/' . $iconsDirectory . '/' . $tableImage . "' id='image1' alt='' />")); |
||
198 | $fileseltray1 = new \XoopsFormElementTray('', '<br>'); |
||
199 | $fileseltray1->addElement(new \XoopsFormFile(\_AM_MODULEBUILDER_FORMUPLOAD, 'attachedfile', $helper->getConfig('maxsize_image'))); |
||
200 | $fileseltray1->addElement(new \XoopsFormLabel('')); |
||
201 | $imgtray1->addElement($fileseltray1); |
||
202 | $imgtray1->setDescription(\_AM_MODULEBUILDER_TABLE_IMAGE_DESC); |
||
203 | $form->addElement($imgtray1); |
||
204 | |||
205 | $tableAutoincrement = $this->isNew() ? 1 : $this->getVar('table_autoincrement'); |
||
206 | $checkTableAutoincrement = new \XoopsFormRadioYN(\_AM_MODULEBUILDER_TABLE_AUTO_INCREMENT, 'table_autoincrement', $tableAutoincrement); |
||
207 | $checkTableAutoincrement->setDescription(\_AM_MODULEBUILDER_TABLE_AUTO_INCREMENT_DESC); |
||
208 | $form->addElement($checkTableAutoincrement); |
||
209 | |||
210 | $optionsTray = new \XoopsFormElementTray(_OPTIONS, '<br>'); |
||
211 | |||
212 | $tableCheckAll = new \XoopsFormCheckBox('', 'tablebox', 1); |
||
213 | $tableCheckAll->addOption('allbox', \_AM_MODULEBUILDER_TABLE_ALL); |
||
214 | $tableCheckAll->setExtra(' onclick="xoopsCheckAll(\'tableform\', \'tablebox\');" '); |
||
215 | $tableCheckAll->setClass('xo-checkall'); |
||
216 | $optionsTray->addElement($tableCheckAll); |
||
217 | // Options |
||
218 | $checkbox = new \XoopsFormCheckbox(' ', 'table_option', $this->getOptionsTables(), '<br>'); |
||
219 | $checkbox->setDescription(\_AM_MODULEBUILDER_OPTIONS_DESC); |
||
220 | foreach ($this->options as $option) { |
||
221 | $checkbox->addOption($option, self::getDefinedLanguage('\_AM_MODULEBUILDER_TABLE_' . \mb_strtoupper($option))); |
||
222 | } |
||
223 | $optionsTray->addElement($checkbox); |
||
224 | |||
225 | $optionsTray->setDescription(\_AM_MODULEBUILDER_TABLE_OPTIONS_CHECKS_DESC); |
||
226 | |||
227 | $form->addElement($optionsTray); |
||
228 | |||
229 | $buttonTray = new \XoopsFormElementTray(_REQUIRED . ' <sup class="red bold">*</sup>', ''); |
||
230 | $buttonTray->addElement(new \XoopsFormHidden('op', 'save')); |
||
231 | $buttonTray->addElement(new \XoopsFormHidden('table_id', ($isNew ? 0 : $this->getVar('table_id')))); |
||
232 | $buttonTray->addElement(new \XoopsFormButton('', 'submit', \_SUBMIT, 'submit')); |
||
233 | $form->addElement($buttonTray); |
||
234 | |||
235 | return $form; |
||
236 | } |
||
308 |