Conditions | 26 |
Paths | > 20000 |
Total Lines | 219 |
Code Lines | 146 |
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 declare(strict_types=1); |
||
70 | public function createElements(): void |
||
71 | { |
||
72 | // require_once \dirname(__DIR__, 2) . '/include/common.php'; |
||
73 | // Category |
||
74 | $criteria = new \Criteria(null); |
||
75 | $criteria->setSort('weight'); |
||
76 | $criteria->order = 'ASC'; // patch for XOOPS <= 2.5.10, does not set order correctly using setOrder() method |
||
77 | $myTree = new \XoopsObjectTree( |
||
78 | $this->helper->getHandler('Category') |
||
79 | ->getObjects($criteria), 'categoryid', 'parentid' |
||
80 | ); |
||
81 | $moduleDirName = \basename(\dirname(__DIR__)); |
||
82 | $module = \XoopsModule::getByDirname($moduleDirName); |
||
|
|||
83 | $catSelect = $myTree->makeSelectElement('parentid', 'name', '--', $this->targetObject->parentid(), true, 0, '', \_AM_PUBLISHER_PARENT_CATEGORY_EXP); |
||
84 | $this->addElement($catSelect); |
||
85 | |||
86 | // Name |
||
87 | $this->addElement(new \XoopsFormText(\_AM_PUBLISHER_CATEGORY, 'name', 50, 255, $this->targetObject->name('e')), true); |
||
88 | |||
89 | // Description |
||
90 | $this->addElement(new \XoopsFormTextArea(\_AM_PUBLISHER_COLDESCRIPT, 'description', $this->targetObject->description('e'), 7, 60)); |
||
91 | |||
92 | // EDITOR |
||
93 | $groups = $GLOBALS['xoopsUser'] ? $GLOBALS['xoopsUser']->getGroups() : XOOPS_GROUP_ANONYMOUS; |
||
94 | $grouppermHandler = $this->helper->getHandler('GroupPerm'); |
||
95 | $moduleId = $this->helper->getModule() |
||
96 | ->mid(); |
||
97 | $allowedEditors = Utility::getEditors($grouppermHandler->getItemIds('editors', $groups, $moduleId)); |
||
98 | $nohtml = false; |
||
99 | if (\count($allowedEditors) > 0) { |
||
100 | $editor = Request::getString('editor', '', 'POST'); |
||
101 | if (!empty($editor)) { |
||
102 | Utility::setCookieVar('publisher_editor', $editor); |
||
103 | } else { |
||
104 | $editor = Utility::getCookieVar('publisher_editor'); |
||
105 | if (empty($editor) && \is_object($GLOBALS['xoopsUser'])) { |
||
106 | $editor = $GLOBALS['xoopsUser']->getVar('publisher_editor') ?? ''; // Need set through user profile |
||
107 | } |
||
108 | } |
||
109 | $editor = (empty($editor) || !\in_array($editor, $allowedEditors, true)) ? $this->helper->getConfig('submit_editor') : $editor; |
||
110 | $formEditor = new \XoopsFormSelectEditor($this, 'editor', $editor, $nohtml, $allowedEditors); |
||
111 | $this->addElement($formEditor); |
||
112 | } else { |
||
113 | $editor = $this->helper->getConfig('submit_editor'); |
||
114 | } |
||
115 | |||
116 | $editorConfigs = []; |
||
117 | $editorConfigs['rows'] = '' == $this->helper->getConfig('submit_editor_rows') ? 35 : $this->helper->getConfig('submit_editor_rows'); |
||
118 | $editorConfigs['cols'] = '' == $this->helper->getConfig('submit_editor_cols') ? 60 : $this->helper->getConfig('submit_editor_cols'); |
||
119 | $editorConfigs['width'] = '' == $this->helper->getConfig('submit_editor_width') ? '100%' : $this->helper->getConfig('submit_editor_width'); |
||
120 | $editorConfigs['height'] = '' == $this->helper->getConfig('submit_editor_height') ? '400px' : $this->helper->getConfig('submit_editor_height'); |
||
121 | |||
122 | $editorConfigs['name'] = 'header'; |
||
123 | $editorConfigs['value'] = $this->targetObject->header('e'); |
||
124 | |||
125 | $textHeader = new \XoopsFormEditor(\_AM_PUBLISHER_CATEGORY_HEADER, $editor, $editorConfigs, $nohtml, $onfailure = null); |
||
126 | $textHeader->setDescription(\_AM_PUBLISHER_CATEGORY_HEADER_DSC); |
||
127 | $this->addElement($textHeader); |
||
128 | |||
129 | // IMAGE |
||
130 | $imageArray = \XoopsLists::getImgListAsArray(Utility::getImageDir('category')); |
||
131 | $imageSelect = new \XoopsFormSelect('', 'image', $this->targetObject->getImage()); |
||
132 | //$imageSelect -> addOption ('-1', '---------------'); |
||
133 | $imageSelect->addOptionArray($imageArray); |
||
134 | $imageSelect->setExtra("onchange='showImgSelected(\"image3\", \"image\", \"" . 'uploads/' . $this->helper->getDirname() . '/images/category/' . '", "", "' . XOOPS_URL . "\")'"); |
||
135 | $imageTray = new \XoopsFormElementTray(\_AM_PUBLISHER_IMAGE, ' '); |
||
136 | $imageTray->addElement($imageSelect); |
||
137 | $imageTray->addElement(new \XoopsFormLabel('', "<br><br><img src='" . Utility::getImageDir('category', false) . $this->targetObject->getImage() . "' name='image3' id='image3' alt=''>")); |
||
138 | $imageTray->setDescription(\_AM_PUBLISHER_IMAGE_DSC); |
||
139 | $this->addElement($imageTray); |
||
140 | |||
141 | // IMAGE UPLOAD |
||
142 | $maxSize = 5000000; |
||
143 | $fileBox = new \XoopsFormFile(\_AM_PUBLISHER_IMAGE_UPLOAD, 'image_file', $maxSize); |
||
144 | $fileBox->setExtra("size ='45'"); |
||
145 | $fileBox->setDescription(\_AM_PUBLISHER_IMAGE_UPLOAD_DSC); |
||
146 | $this->addElement($fileBox); |
||
147 | |||
148 | // Short url |
||
149 | $textShortUrl = new \XoopsFormText(\_AM_PUBLISHER_CATEGORY_SHORT_URL, 'short_url', 50, 255, $this->targetObject->short_url('e')); |
||
150 | $textShortUrl->setDescription(\_AM_PUBLISHER_CATEGORY_SHORT_URL_DSC); |
||
151 | $this->addElement($textShortUrl); |
||
152 | |||
153 | // Meta Keywords |
||
154 | $textMetaKeywords = new \XoopsFormTextArea(\_AM_PUBLISHER_CATEGORY_META_KEYWORDS, 'meta_keywords', $this->targetObject->meta_keywords('e'), 7, 60); |
||
155 | $textMetaKeywords->setDescription(\_AM_PUBLISHER_CATEGORY_META_KEYWORDS_DSC); |
||
156 | $this->addElement($textMetaKeywords); |
||
157 | |||
158 | // Meta Description |
||
159 | $textMetaDescription = new \XoopsFormTextArea(\_AM_PUBLISHER_CATEGORY_META_DESCRIPTION, 'meta_description', $this->targetObject->meta_description('e'), 7, 60); |
||
160 | $textMetaDescription->setDescription(\_AM_PUBLISHER_CATEGORY_META_DESCRIPTION_DSC); |
||
161 | $this->addElement($textMetaDescription); |
||
162 | |||
163 | // Weight |
||
164 | $this->addElement(new \XoopsFormText(\_AM_PUBLISHER_COLPOSIT, 'weight', 4, 4, $this->targetObject->weight())); |
||
165 | |||
166 | // Added by skalpa: custom template support for Category view |
||
167 | // $this->addElement(new \XoopsFormText('Custom template', 'template', 50, 255, $this->targetObject->getTemplate('e')), false); |
||
168 | |||
169 | $dir = $this->helper->path('templates/custom/category'); |
||
170 | $availableTemplates = []; |
||
171 | if (\is_dir($dir)) { |
||
172 | $templateList = \XoopsLists::getFileListAsArray($dir); |
||
173 | foreach ($templateList as $file) { |
||
174 | if (\preg_match('/(\.tpl)$/i', $file)) { |
||
175 | $availableTemplates[$file] = $file; |
||
176 | } |
||
177 | } |
||
178 | } |
||
179 | |||
180 | $categoryTemplate = new \XoopsFormSelect(\_AM_PUBLISHER_CUSTOM_CATEGORY_TEMPLATE, 'template', $this->targetObject->getVar('template')); |
||
181 | |||
182 | $categoryTemplate->addOption('', ''); |
||
183 | $categoryTemplate->addOptionArray($availableTemplates); |
||
184 | |||
185 | $this->addElement($categoryTemplate, false); |
||
186 | |||
187 | // CUSTOM TEMPLATE FOR ARTICLES in Particular Category |
||
188 | $dirCategoryItem = $this->helper->path('templates/custom/categoryitem'); |
||
189 | $availableItemTemplates = []; |
||
190 | if (\is_dir($dirCategoryItem)) { |
||
191 | $templateItemList = \XoopsLists::getFileListAsArray($dirCategoryItem); |
||
192 | foreach ($templateItemList as $file) { |
||
193 | if (\preg_match('/(\.tpl)$/i', $file)) { |
||
194 | $availableItemTemplates[$file] = $file; |
||
195 | } |
||
196 | } |
||
197 | } |
||
198 | |||
199 | $categoryItemTemplate = new \XoopsFormSelect(\_AM_PUBLISHER_CUSTOM_CATEGORY_ITEM_TEMPLATE, 'template_item', $this->targetObject->getVar('template_item')); |
||
200 | |||
201 | $categoryItemTemplate->addOption('', ''); |
||
202 | $categoryItemTemplate->addOptionArray($availableItemTemplates); |
||
203 | |||
204 | $this->addElement($categoryItemTemplate, false); |
||
205 | |||
206 | // READ PERMISSIONS |
||
207 | $readPermissionsTray = new \XoopsFormElementTray(\_AM_PUBLISHER_PERMISSIONS_CAT_READ, ''); |
||
208 | $selectAllReadCheckbox = new \XoopsFormCheckBox('', 'adminbox', 1); |
||
209 | $selectAllReadCheckbox->addOption('allbox', \_AM_SYSTEM_ALL); |
||
210 | $selectAllReadCheckbox->setExtra(" onclick='xoopsCheckGroup(\"form\", \"adminbox\" , \"groupsRead[]\");' "); |
||
211 | $selectAllReadCheckbox->setClass('xo-checkall'); |
||
212 | $readPermissionsTray->addElement($selectAllReadCheckbox); |
||
213 | |||
214 | $groupsReadCheckbox = new \XoopsFormCheckBox('', 'groupsRead[]', $this->targetObject->getGroupsRead()); |
||
215 | |||
216 | foreach ($this->userGroups as $groupId => $groupName) { |
||
217 | $groupsReadCheckbox->addOption($groupId, $groupName); |
||
218 | } |
||
219 | $readPermissionsTray->addElement($groupsReadCheckbox); |
||
220 | $this->addElement($readPermissionsTray); |
||
221 | |||
222 | // SUBMIT PERMISSIONS |
||
223 | $submitPermissionsTray = new \XoopsFormElementTray(\_AM_PUBLISHER_PERMISSIONS_CAT_SUBMIT, ''); |
||
224 | $submitPermissionsTray->setDescription(\_AM_PUBLISHER_PERMISSIONS_CAT_SUBMIT_DSC); |
||
225 | |||
226 | $selectAllSubmitCheckbox = new \XoopsFormCheckBox('', 'adminbox2', 1); |
||
227 | $selectAllSubmitCheckbox->addOption('allbox', \_AM_SYSTEM_ALL); |
||
228 | $selectAllSubmitCheckbox->setExtra(" onclick='xoopsCheckGroup(\"form\", \"adminbox2\" , \"groupsSubmit[]\");' "); |
||
229 | $selectAllSubmitCheckbox->setClass('xo-checkall'); |
||
230 | $submitPermissionsTray->addElement($selectAllSubmitCheckbox); |
||
231 | |||
232 | $groupsSubmitCheckbox = new \XoopsFormCheckBox('', 'groupsSubmit[]', $this->targetObject->getGroupsSubmit()); |
||
233 | foreach ($this->userGroups as $groupId => $groupName) { |
||
234 | $groupsSubmitCheckbox->addOption($groupId, $groupName); |
||
235 | } |
||
236 | $submitPermissionsTray->addElement($groupsSubmitCheckbox); |
||
237 | $this->addElement($submitPermissionsTray); |
||
238 | |||
239 | // MODERATION PERMISSIONS |
||
240 | $moderatePermissionsTray = new \XoopsFormElementTray(\_AM_PUBLISHER_PERMISSIONS_CAT_MODERATOR, ''); |
||
241 | $moderatePermissionsTray->setDescription(\_AM_PUBLISHER_PERMISSIONS_CAT_MODERATOR_DSC); |
||
242 | |||
243 | $selectAllModerateCheckbox = new \XoopsFormCheckBox('', 'adminbox3', 1); |
||
244 | $selectAllModerateCheckbox->addOption('allbox', \_AM_SYSTEM_ALL); |
||
245 | $selectAllModerateCheckbox->setExtra(" onclick='xoopsCheckGroup(\"form\", \"adminbox3\" , \"groupsModeration[]\");' "); |
||
246 | $selectAllModerateCheckbox->setClass('xo-checkall'); |
||
247 | $moderatePermissionsTray->addElement($selectAllModerateCheckbox); |
||
248 | |||
249 | $groupsModerationCheckbox = new \XoopsFormCheckBox('', 'groupsModeration[]', $this->targetObject->getGroupsModeration()); |
||
250 | |||
251 | foreach ($this->userGroups as $groupId => $groupName) { |
||
252 | $groupsModerationCheckbox->addOption($groupId, $groupName); |
||
253 | } |
||
254 | $moderatePermissionsTray->addElement($groupsModerationCheckbox); |
||
255 | $this->addElement($moderatePermissionsTray); |
||
256 | |||
257 | $moderator = new \XoopsFormSelectUser(\_AM_PUBLISHER_CATEGORY_MODERATOR, 'moderator', true, $this->targetObject->moderator('e'), 1, false); |
||
258 | $moderator->setDescription(\_AM_PUBLISHER_CATEGORY_MODERATOR_DSC); |
||
259 | $this->addElement($moderator); |
||
260 | |||
261 | //SUBCATEGORY |
||
262 | $catTray = new \XoopsFormElementTray(\_AM_PUBLISHER_SCATEGORYNAME, '<br><br>'); |
||
263 | for ($i = 0; $i < $this->subCatsCount; ++$i) { |
||
264 | $subname = ''; |
||
265 | if ($i < (($scname = Request::getArray('scname', [], 'POST')) ? \count($scname) : 0)) { |
||
266 | $temp = Request::getArray('scname', [], 'POST'); |
||
267 | $subname = ($scname = Request::getArray('scname', '', 'POST')) ? $temp[$i] : ''; |
||
268 | } |
||
269 | $catTray->addElement(new \XoopsFormText('', 'scname[' . $i . ']', 50, 255, $subname)); |
||
270 | } |
||
271 | $t = new \XoopsFormText('', 'nb_subcats', 3, 2); |
||
272 | $l = new \XoopsFormLabel('', \sprintf(\_AM_PUBLISHER_ADD_OPT, $t->render())); |
||
273 | $b = new \XoopsFormButton('', 'submit_subcats', \_AM_PUBLISHER_ADD_OPT_SUBMIT, 'submit'); |
||
274 | |||
275 | if ($this->targetObject->categoryid()) { |
||
276 | $b->setExtra('onclick="this.form.elements.op.value=\'mod\'"'); |
||
277 | } else { |
||
278 | $b->setExtra('onclick="this.form.elements.op.value=\'addsubcats\'"'); |
||
279 | } |
||
280 | |||
281 | $r = new \XoopsFormElementTray(''); |
||
282 | $r->addElement($l); |
||
283 | $r->addElement($b); |
||
284 | $catTray->addElement($r); |
||
285 | $this->addElement($catTray); |
||
286 | |||
287 | $this->addElement(new \XoopsFormHidden('categoryid', $this->targetObject->categoryid())); |
||
288 | $this->addElement(new \XoopsFormHidden('nb_sub_yet', $this->subCatsCount)); |
||
289 | } |
||
318 |