Conditions | 62 |
Paths | 0 |
Total Lines | 367 |
Code Lines | 275 |
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 declare(strict_types=1); |
||
133 | public function getForm($action = false) |
||
134 | { |
||
135 | $helper = Helper::getInstance(); |
||
136 | |||
137 | $categoryHandler = $helper->getHandler('Category'); |
||
138 | $permissionsHandler = $helper->getHandler('Permission'); |
||
139 | |||
140 | $utility = new Utility(); |
||
141 | |||
142 | if (!$action) { |
||
143 | $action = $_SERVER['REQUEST_URI']; |
||
144 | } |
||
145 | $isAdmin = false; |
||
146 | $userUid = 0; |
||
147 | $userEmail = ''; |
||
148 | $userName = ''; |
||
149 | if (\is_object($GLOBALS['xoopsUser'])) { |
||
150 | if (\is_object($GLOBALS['xoopsModule'])) { |
||
151 | $isAdmin = $GLOBALS['xoopsUser']->isAdmin($GLOBALS['xoopsModule']->mid()); |
||
152 | } |
||
153 | $userUid = $GLOBALS['xoopsUser']->uid(); |
||
154 | $userEmail = $GLOBALS['xoopsUser']->email(); |
||
155 | $userName = ('' !== (string)$GLOBALS['xoopsUser']->name()) ? $GLOBALS['xoopsUser']->name() : $GLOBALS['xoopsUser']->uname(); |
||
156 | } |
||
157 | |||
158 | $imgInfo = '<img class="wge-img-info" src="' . \WGEVENTS_ICONS_URL_24 . '/info.png" alt="img-info" title="%s">'; |
||
159 | |||
160 | // Title |
||
161 | $title = $this->isNew() ? \_MA_WGEVENTS_EVENT_ADD : \_MA_WGEVENTS_EVENT_EDIT; |
||
162 | if ($this->idSource > 0) { |
||
163 | $this->unsetNew(); |
||
164 | } |
||
165 | // Get Theme Form |
||
166 | \xoops_load('XoopsFormLoader'); |
||
167 | $form = new \XoopsThemeForm($title, 'formEvent', $action, 'post', true); |
||
168 | $form->setExtra('enctype="multipart/form-data"'); |
||
169 | // Form Text identifier |
||
170 | if (!$this->isNew()) { |
||
171 | if ($isAdmin) { |
||
172 | $form->addElement(new \XoopsFormText(\_MA_WGEVENTS_EVENT_IDENTIFIER, 'identifier', 50, 255, $this->getVar('identifier'))); |
||
173 | } else { |
||
174 | $form->addElement(new \XoopsFormLabel(\_MA_WGEVENTS_EVENT_IDENTIFIER, $this->getVar('identifier'))); |
||
175 | $form->addElement(new \XoopsFormHidden('identifier', (string)$this->getVar('identifier'))); |
||
176 | } |
||
177 | } |
||
178 | // Form Table categories |
||
179 | $evCatidSelect = new \XoopsFormSelect(\_MA_WGEVENTS_EVENT_CATID, 'catid', $this->getVar('catid')); |
||
180 | $evCatidSelect->addOptionArray($categoryHandler->getAllCatsOnline(Constants::CATEGORY_TYPE_MAIN)); |
||
181 | $form->addElement($evCatidSelect); |
||
182 | // Form Table sub categories |
||
183 | // count sub categories |
||
184 | $catsSubOnline = $categoryHandler->getAllCatsOnline(Constants::CATEGORY_TYPE_SUB); |
||
185 | if (\count($catsSubOnline) > 0) { |
||
186 | $evSubCats = $this->isNew() ? [] : \unserialize($this->getVar('subcats'), ['allowed_classes' => false]); |
||
187 | $evSubCatsSelect = new \XoopsFormCheckBox(\_MA_WGEVENTS_EVENT_SUBCATS, 'subcats', $evSubCats); |
||
188 | $evSubCatsSelect->addOptionArray($catsSubOnline); |
||
189 | $form->addElement($evSubCatsSelect); |
||
190 | } |
||
191 | // Form Text evName |
||
192 | $form->addElement(new \XoopsFormText(\_MA_WGEVENTS_EVENT_NAME, 'name', 50, 255, $this->getVar('name')), true); |
||
193 | // Form Editor DhtmlTextArea evDesc |
||
194 | $editorConfigs = []; |
||
195 | if ($isAdmin) { |
||
196 | $editor = $helper->getConfig('editor_admin'); |
||
197 | } else { |
||
198 | $editor = $helper->getConfig('editor_user'); |
||
199 | } |
||
200 | $editorConfigs['name'] = 'desc'; |
||
201 | $editorConfigs['value'] = $this->getVar('desc', 'e'); |
||
202 | $editorConfigs['rows'] = 5; |
||
203 | $editorConfigs['cols'] = 40; |
||
204 | $editorConfigs['width'] = '100%'; |
||
205 | $editorConfigs['height'] = '400px'; |
||
206 | $editorConfigs['editor'] = $editor; |
||
207 | $form->addElement(new \XoopsFormEditor(\_MA_WGEVENTS_EVENT_DESC, 'desc', $editorConfigs)); |
||
208 | // Form Image evLogo |
||
209 | // Form Image evLogo: Select Uploaded Image |
||
210 | $getEvLogo = $this->getVar('logo'); |
||
211 | $evLogo = $getEvLogo ?: 'blank.gif'; |
||
212 | $imageDirectory = '/uploads/wgevents/events/logos/' . $userUid; |
||
213 | $folderUid = \XOOPS_ROOT_PATH . $imageDirectory; |
||
214 | if (!\file_exists($folderUid)) { |
||
215 | $utility::createFolder($folderUid); |
||
216 | \chmod($folderUid, 0777); |
||
217 | $file = \WGEVENTS_PATH . '/assets/images/blank.gif'; |
||
218 | $dest = $folderUid . '/blank.gif'; |
||
219 | $utility::copyFile($file, $dest); |
||
220 | } |
||
221 | $imageTray = new Forms\FormElementTray(\_MA_WGEVENTS_EVENT_LOGO, '<br>'); |
||
222 | $imageSelect = new \XoopsFormSelect(\_MA_WGEVENTS_EVENT_LOGO_UPLOADS, 'logo', $evLogo, 5); |
||
223 | $imageArray = \XoopsLists::getImgListAsArray(\XOOPS_ROOT_PATH . $imageDirectory); |
||
224 | foreach ($imageArray as $image1) { |
||
225 | $imageSelect->addOption(($image1), $image1); |
||
226 | } |
||
227 | $imageSelect->setExtra("onchange='showImgSelected(\"imglabel_logo\", \"logo\", \"" . $imageDirectory . '", "", "' . \XOOPS_URL . "\")'"); |
||
228 | $imageTray->addElement($imageSelect); |
||
229 | $imageTray->addElement(new \XoopsFormLabel('', "<br><img src='" . \XOOPS_URL . '/' . $imageDirectory . '/' . $evLogo . "' id='imglabel_logo' alt='' style='max-width:100px' >")); |
||
230 | // Form Image evLogo: Upload new image |
||
231 | $maxsize = $helper->getConfig('maxsize_image'); |
||
232 | $imageTray->addElement(new \XoopsFormFile('<br>' . \_AM_WGEVENTS_FORM_UPLOAD_NEW, 'logo', $maxsize)); |
||
233 | $imageTray->addElement(new \XoopsFormLabel(\_AM_WGEVENTS_FORM_UPLOAD_SIZE, ($maxsize / 1048576) . ' ' . \_AM_WGEVENTS_FORM_UPLOAD_SIZE_MB)); |
||
234 | $imageTray->addElement(new \XoopsFormLabel(\_AM_WGEVENTS_FORM_UPLOAD_IMG_WIDTH, $helper->getConfig('maxwidth_image') . ' px')); |
||
235 | $imageTray->addElement(new \XoopsFormLabel(\_AM_WGEVENTS_FORM_UPLOAD_IMG_HEIGHT, $helper->getConfig('maxheight_image') . ' px')); |
||
236 | $form->addElement($imageTray); |
||
237 | // Form Tray Datefrom |
||
238 | $evDatefromTray = new Forms\FormElementTray(\_MA_WGEVENTS_EVENT_DATEFROM, ' '); |
||
239 | // Text Date Select evDatefrom |
||
240 | $evDatefrom = ($this->isNew() && 0 === (int)$this->getVar('datefrom')) ? \time() : $this->getVar('datefrom'); |
||
241 | $evDatefromTray->addElement(new \XoopsFormDateTime('', 'datefrom', '', $evDatefrom), true); |
||
242 | // Text Date Checkbox evAllday |
||
243 | $evAllday = $this->isNew() ? 0 : (int)$this->getVar('allday'); |
||
244 | $checkAllday = new \XoopsFormCheckBox('', 'allday', $evAllday); |
||
245 | $checkAllday->addOption(1, \_MA_WGEVENTS_EVENT_ALLDAY); |
||
246 | $checkAllday->setExtra(" onclick='toggleAllday()' "); |
||
247 | $evDatefromTray->addElement($checkAllday); |
||
248 | $form->addElement($evDatefromTray); |
||
249 | // Form Text Date Select evDateto |
||
250 | $evDateto = ($this->isNew() && 0 === (int)$this->getVar('dateto')) ? \time() : $this->getVar('dateto'); |
||
251 | $form->addElement(new \XoopsFormDateTime(\_MA_WGEVENTS_EVENT_DATETO, 'dateto', '', $evDateto)); |
||
252 | // Form Text evContact |
||
253 | $form->addElement(new \XoopsFormTextArea(\_MA_WGEVENTS_EVENT_CONTACT, 'contact', $this->getVar('contact', 'e'), 4, 30)); |
||
254 | // Form Text evEmail |
||
255 | $evEmail = new \XoopsFormText(\_MA_WGEVENTS_EVENT_EMAIL, 'email', 50, 255, $this->getVar('email')); |
||
256 | $evEmail->setExtra("onfocusout='emailValidation(\"email\", \"" . \sprintf(\_MA_WGEVENTS_INVALID_EMAIL, \_MA_WGEVENTS_EVENT_EMAIL) . "\")'"); |
||
257 | $form->addElement($evEmail); |
||
258 | // Form Text evUrl |
||
259 | $form->addElement(new \XoopsFormText(\_MA_WGEVENTS_EVENT_URL, 'url', 50, 255, $this->getVar('url'))); |
||
260 | // Location |
||
261 | // Form Editor TextArea evLocation |
||
262 | $evLocation = $this->isNew() ? '' : $this->getVar('location', 'e'); |
||
263 | $form->addElement(new \XoopsFormTextArea(\_MA_WGEVENTS_EVENT_LOCATION, 'location', $evLocation, 4, 50)); |
||
264 | |||
265 | if ($helper->getConfig('use_gmaps')) { |
||
266 | $gmapsTray = new Forms\FormElementTray('', '<br>'); |
||
267 | // Form Text evLocgmlat |
||
268 | $evLocgmlat = $this->isNew() ? '0.00' : $this->getVar('locgmlat'); |
||
269 | $gmapsTray->addElement(new \XoopsFormText(\_MA_WGEVENTS_EVENT_LOCGMLAT, 'locgmlat', 20, 50, $evLocgmlat)); |
||
270 | // Form Text evLocgmlon |
||
271 | $evLocgmlon = $this->isNew() ? '0.00' : $this->getVar('locgmlon'); |
||
272 | $gmapsTray->addElement(new \XoopsFormText(\_MA_WGEVENTS_EVENT_LOCGMLON, 'locgmlon', 20, 50, $evLocgmlon)); |
||
273 | // Form Text evLocgmzoom |
||
274 | $evLocgmzoom = $this->isNew() ? '10' : $this->getVar('locgmzoom'); |
||
275 | $gmapsTray->addElement(new \XoopsFormText(\_MA_WGEVENTS_EVENT_LOCGMZOOM, 'locgmzoom', 5, 50, $evLocgmzoom)); |
||
276 | // Form label |
||
277 | $locLabel = '<div class="row"><div class="col-sm-6">'; |
||
278 | $locLabel .= $gmapsTray->render(); |
||
279 | $locLabel .= '</div>'; |
||
280 | $locLabel .= '<div class="col-sm-6">'; |
||
281 | $locLabel .= "<button id='btnGetCoords' type='button' class='btn btn-primary' data-toggle='modal' data-target='#modalCoordsPicker'>" . \_MA_WGEVENTS_EVENT_GM_GETCOORDS . '</button>'; |
||
282 | $locLabel .= '</div></div>'; |
||
283 | $form->addElement(new \XoopsFormLabel('', $locLabel)); |
||
284 | } |
||
285 | // Form Text evFee |
||
286 | $default0 = '0' . $helper->getConfig('sep_comma') . '00'; |
||
287 | $evFeeArr = []; |
||
288 | if ($this->isNew()) { |
||
289 | $evFeeArr = [[$default0, '', 'placeholder' => \_MA_WGEVENTS_EVENT_FEE_DESC_PH]]; |
||
290 | } else { |
||
291 | $evFee = \json_decode($this->getVar('fee'), true); |
||
292 | foreach($evFee as $fee) { |
||
293 | $evFeeArr[] = [Utility::FloatToString((float)$fee[0]), $fee[1], 'placeholder' => \_MA_WGEVENTS_EVENT_FEE_DESC_PH]; |
||
294 | } |
||
295 | if (0 === \count($evFeeArr)) { |
||
296 | $evFeeArr = [[$default0, '', 'placeholder' => \_MA_WGEVENTS_EVENT_FEE_DESC_PH]]; |
||
297 | } |
||
298 | } |
||
299 | $evFeeTray = new Forms\FormElementTray(\_MA_WGEVENTS_EVENT_FEE, '<br>'); |
||
300 | $evFeeType = $this->isNew() ? Constants::FEETYPE_DECLARED : (int)$this->getVar('fee_type'); |
||
301 | $evFeeTypeRadio = new \XoopsFormRadio('', 'fee_type', $evFeeType); |
||
302 | $evFeeTypeRadio->addOption(Constants::FEETYPE_DECLARED, \_MA_WGEVENTS_EVENT_FEETYPE_DECLARED); |
||
303 | $evFeeTypeRadio->addOption(Constants::FEETYPE_FREE, \_MA_WGEVENTS_EVENT_FEETYPE_FREE); |
||
304 | $evFeeTypeRadio->addOption(Constants::FEETYPE_NONDECL, \_MA_WGEVENTS_EVENT_FEETYPE_NONDECL); |
||
305 | $evFeeTypeRadio->setExtra(" onchange='toggleFeeFields()' "); |
||
306 | $evFeeTray->addElement($evFeeTypeRadio); |
||
307 | $evFeeGroup = new Forms\FormTextDouble('', 'fee', 0, 0, ''); |
||
308 | $evFeeGroup->setElements($evFeeArr); |
||
309 | $evFeeGroup->setPlaceholder1(\_MA_WGEVENTS_EVENT_FEE_VAL_PH); |
||
310 | $evFeeGroup->setPlaceholder2(\_MA_WGEVENTS_EVENT_FEE_DESC_PH); |
||
311 | $evFeeGroup->setVisible(Constants::FEETYPE_DECLARED === $evFeeType); |
||
312 | $evFeeTray->addElement($evFeeGroup); |
||
313 | $form->addElement($evFeeTray); |
||
314 | // Form TextArea evPaymentinfo |
||
315 | $editorConfigs2 = []; |
||
316 | $editorConfigs2['name'] = 'paymentinfo'; |
||
317 | $editorConfigs2['value'] = $this->getVar('paymentinfo', 'e'); |
||
318 | $editorConfigs2['rows'] = 5; |
||
319 | $editorConfigs2['cols'] = 40; |
||
320 | $editorConfigs2['width'] = '100%'; |
||
321 | $editorConfigs2['height'] = '400px'; |
||
322 | $editorConfigs2['editor'] = $editor; |
||
323 | $form->addElement(new \XoopsFormEditor(\_MA_WGEVENTS_EVENT_PAYMENTINFO, 'paymentinfo', $editorConfigs2)); |
||
324 | |||
325 | // Start block registration options |
||
326 | $evRegister_use = $this->isNew() ? 0 : $this->getVar('register_use'); |
||
327 | if ($helper->getConfig('use_register')) { |
||
328 | // Form Radio Yes/No evRegister_use |
||
329 | $evRegisterUseRadio = new \XoopsFormRadioYN(\_MA_WGEVENTS_EVENT_REGISTER_USE, 'register_use', $evRegister_use); |
||
330 | $evRegisterUseRadio->setExtra(" onclick='toggleRegistrationOpts()' "); |
||
331 | $form->addElement($evRegisterUseRadio); |
||
332 | $evReservUseTray = new \XoopsFormElementTray('', '<br>'); //double element tray is necessary for proper toggle |
||
333 | $evRegisterOptsTray = new Forms\FormElementTray('', '<br>', 'registeropttray'); |
||
334 | $evRegisterOptsTray->setClass('col-xs-12 col-sm-5 col-lg-5'); |
||
335 | if (!$evRegister_use) { |
||
336 | $evRegisterOptsTray->setHidden(); |
||
337 | } |
||
338 | // Form Text Date Select evRegisterfrom |
||
339 | $evRegisterfrom = $this->isNew() ? \time() : $this->getVar('register_from'); |
||
340 | $evRegisterOptsTray->addElement(new \XoopsFormDateTime(\_MA_WGEVENTS_EVENT_REGISTER_FROM, 'register_from', '', $evRegisterfrom)); |
||
341 | // Form Text Date Select evRegisterto |
||
342 | $evRegisterto = $this->isNew() ? \time() : $this->getVar('register_to'); |
||
343 | $evRegisterOptsTray->addElement(new \XoopsFormDateTime(\_MA_WGEVENTS_EVENT_REGISTER_TO, 'register_to', '', $evRegisterto)); |
||
344 | // Form Text evRegisterMax |
||
345 | $evRegisterMax = $this->isNew() ? 0 : $this->getVar('register_max'); |
||
346 | $captionRegisterMax = \_MA_WGEVENTS_EVENT_REGISTER_MAX . \sprintf($imgInfo, \_MA_WGEVENTS_EVENT_REGISTER_MAX_DESC); |
||
347 | $evRegisterOptsTray->addElement(new \XoopsFormText($captionRegisterMax, 'register_max', 5, 50, $evRegisterMax)); |
||
348 | // Form Radio Yes/No evRegisterListwait |
||
349 | $evRegisterListwait = $this->isNew() ? 0 : $this->getVar('register_listwait'); |
||
350 | $captionRegisterListwait = \_MA_WGEVENTS_EVENT_REGISTER_LISTWAIT . \sprintf($imgInfo, \_MA_WGEVENTS_EVENT_REGISTER_LISTWAIT_DESC); |
||
351 | $evRegisterOptsTray->addElement(new \XoopsFormRadioYN($captionRegisterListwait, 'register_listwait', $evRegisterListwait)); |
||
352 | // Form Select User evRegisterAutoaccept |
||
353 | $evRegisterAutoaccept = $this->isNew() ? 0 : $this->getVar('register_autoaccept'); |
||
354 | $captionRegisterAutoaccept = \_MA_WGEVENTS_EVENT_REGISTER_AUTOACCEPT . \sprintf($imgInfo, \_MA_WGEVENTS_EVENT_REGISTER_AUTOACCEPT_DESC); |
||
355 | $evRegisterOptsTray->addElement(new \XoopsFormRadioYN($captionRegisterAutoaccept, 'register_autoaccept', $evRegisterAutoaccept)); |
||
356 | // Form Editor TextArea evRegisterNotify |
||
357 | $evRegisterNotify = $this->isNew() ? $userEmail : $this->getVar('register_notify', 'e'); |
||
358 | $captionRegisterNotify = \_MA_WGEVENTS_EVENT_REGISTER_NOTIFY . \sprintf($imgInfo, \_MA_WGEVENTS_EVENT_REGISTER_NOTIFY_DESC); |
||
359 | $evRegisterOptsTray->addElement(new \XoopsFormTextArea($captionRegisterNotify, 'register_notify', $evRegisterNotify, 4, 30)); |
||
360 | // Form Text evRegisterSendermail |
||
361 | $evRegisterSendermailText = $this->isNew() ? $userEmail : $this->getVar('register_sendermail'); |
||
362 | $captionRegisterSendermail = \_MA_WGEVENTS_EVENT_REGISTER_SENDERMAIL . \sprintf($imgInfo, \_MA_WGEVENTS_EVENT_REGISTER_SENDERMAIL_DESC); |
||
363 | $evRegisterSendermail = new \XoopsFormText($captionRegisterSendermail, 'register_sendermail', 35, 255, $evRegisterSendermailText); |
||
364 | $evRegisterSendermail->setExtra("onfocusout='emailValidation(\"register_sendermail\", \"" . \sprintf(\_MA_WGEVENTS_INVALID_EMAIL, \_MA_WGEVENTS_EVENT_REGISTER_SENDERMAIL) . "\")'"); |
||
365 | $evRegisterOptsTray->addElement($evRegisterSendermail); |
||
366 | // Form Text evRegisterSendername |
||
367 | $evRegisterSendername = $this->isNew() ? $userName : $this->getVar('register_sendername'); |
||
368 | $captionRegisterSendername = \_MA_WGEVENTS_EVENT_REGISTER_SENDERNAME . \sprintf($imgInfo, \_MA_WGEVENTS_EVENT_REGISTER_SENDERNAME_DESC); |
||
369 | $evRegisterOptsTray->addElement(new \XoopsFormText($captionRegisterSendername, 'register_sendername', 35, 255, $evRegisterSendername)); |
||
370 | // Form Editor TextArea evRegisterSignature |
||
371 | $evRegisterSignature = $this->isNew() ? '' : $this->getVar('register_signature', 'e'); |
||
372 | $captionRegisterSignature = \_MA_WGEVENTS_EVENT_REGISTER_SIGNATURE . \sprintf($imgInfo, \_MA_WGEVENTS_EVENT_REGISTER_SIGNATURE_DESC); |
||
373 | $evRegisterOptsTray->addElement(new \XoopsFormTextArea($captionRegisterSignature, 'register_signature', $evRegisterSignature, 4, 30)); |
||
374 | // Form Radio Yes/No evRegisterListwait |
||
375 | $evRegisterForceverif = $this->isNew() ? 1 : $this->getVar('register_forceverif'); |
||
376 | $captionRegisterForceverif = \_MA_WGEVENTS_EVENT_REGISTER_FORCEVERIF . \sprintf($imgInfo, \_MA_WGEVENTS_EVENT_REGISTER_FORCEVERIF_DESC); |
||
377 | $evRegisterOptsTray->addElement(new \XoopsFormRadioYN($captionRegisterForceverif, 'register_forceverif', $evRegisterForceverif)); |
||
378 | |||
379 | $evReservUseTray->addElement($evRegisterOptsTray); |
||
380 | $form->addElement($evReservUseTray); |
||
381 | //$form->addElement(new \XoopsFormLabel('', $evReservUseTray)); |
||
382 | // End block registration options |
||
383 | } |
||
384 | if ($helper->getConfig('use_urlregistration')) { |
||
385 | // Form Text urlRegistration |
||
386 | $evUrlregistration = $this->getVar('url_registration'); |
||
387 | $evUrlregText = new Forms\FormText(\_MA_WGEVENTS_EVENT_URL_REGISTRATION, 'url_registration', 50, 255, $evUrlregistration); |
||
388 | $evUrlregText->setPlaceholder(\_MA_WGEVENTS_EVENT_URL_REGISTRATION_PH); |
||
389 | if ($evRegister_use) { |
||
390 | $evUrlregText->setExtra('disabled'); |
||
391 | } |
||
392 | $form->addElement($evUrlregText); |
||
393 | } |
||
394 | // Form Select evGalid |
||
395 | if ($helper->getConfig('use_wggallery') && \class_exists('WggalleryCorePreload')) { |
||
396 | $helperGallery = \XoopsModules\Wggallery\Helper::getInstance(); |
||
397 | $albumsHandler = $helperGallery->getHandler('Albums'); |
||
398 | $evGalidSelect = new \XoopsFormSelect(\_MA_WGEVENTS_EVENT_GALID, 'galid', $this->getVar('galid')); |
||
399 | $evGalidSelect->addOption(0, ' '); |
||
400 | $evGalidSelect->addOptionArray($albumsHandler->getList()); |
||
401 | $form->addElement($evGalidSelect); |
||
402 | } |
||
403 | // Form Select evGroups |
||
404 | if ($helper->getConfig('use_groups')) { |
||
405 | if ($this->isNew()) { |
||
406 | $groups = ['00000']; |
||
407 | } else { |
||
408 | $groups = \explode('|', $this->getVar('groups')); |
||
409 | } |
||
410 | $evGroupsSelect = new \XoopsFormSelect(\_MA_WGEVENTS_EVENT_GROUPS, 'groups', $groups, 5, true); |
||
411 | $evGroupsSelect->addOption('00000', \_MA_WGEVENTS_EVENT_GROUPS_ALL); |
||
412 | // Get groups |
||
413 | $memberHandler = \xoops_getHandler('member'); |
||
414 | $xoopsGroups = $memberHandler->getGroupList(); |
||
415 | foreach ($xoopsGroups as $key => $group) { |
||
416 | if (3 !== (int)$key) { |
||
417 | $evGroupsSelect->addOption(substr('00000' . $key, -5), $group); |
||
418 | } |
||
419 | } |
||
420 | $form->addElement($evGroupsSelect, true); |
||
421 | } else { |
||
422 | $form->addElement(new \XoopsFormHidden('groups', '00000')); |
||
423 | } |
||
424 | // Form Select Status evStatus |
||
425 | // Form Text Date Select evDatecreated |
||
426 | // Form Select User evSubmitter |
||
427 | $permEventsApprove = $permissionsHandler->getPermEventsApprove(); |
||
428 | $permEventsApproveAuto = $permissionsHandler->getPermEventsApproveAuto(); |
||
429 | if ($this->isNew()) { |
||
430 | $evStatus = $permEventsApproveAuto ? Constants::STATUS_APPROVED : Constants::STATUS_SUBMITTED; |
||
431 | } else { |
||
432 | $evStatus = $this->getVar('status'); |
||
433 | } |
||
434 | $evDatecreated = $this->isNew() ? \time() : (int)$this->getVar('datecreated'); |
||
435 | $evSubmitter = $this->isNew() ? $userUid : (int)$this->getVar('submitter'); |
||
436 | if ($isAdmin) { |
||
437 | $evStatusSelect = new \XoopsFormSelect(\_MA_WGEVENTS_STATUS, 'status', $evStatus); |
||
438 | $evStatusSelect->addOption(Constants::STATUS_NONE, \_MA_WGEVENTS_STATUS_NONE); |
||
439 | $evStatusSelect->addOption(Constants::STATUS_OFFLINE, \_MA_WGEVENTS_STATUS_OFFLINE); |
||
440 | $evStatusSelect->addOption(Constants::STATUS_SUBMITTED, \_MA_WGEVENTS_STATUS_SUBMITTED); |
||
441 | $evStatusSelect->addOption(Constants::STATUS_APPROVED, \_MA_WGEVENTS_STATUS_APPROVED); |
||
442 | $evStatusSelect->addOption(Constants::STATUS_LOCKED, \_MA_WGEVENTS_STATUS_LOCKED); |
||
443 | $evStatusSelect->addOption(Constants::STATUS_CANCELED, \_MA_WGEVENTS_STATUS_CANCELED); |
||
444 | $form->addElement($evStatusSelect, true); |
||
445 | $form->addElement(new \XoopsFormTextDateSelect(\_MA_WGEVENTS_DATECREATED, 'datecreated', '', $evDatecreated)); |
||
446 | $form->addElement(new \XoopsFormSelectUser(\_MA_WGEVENTS_SUBMITTER, 'submitter', false, $evSubmitter)); |
||
447 | } else { |
||
448 | $form->addElement(new \XoopsFormHidden('status', $evStatus)); |
||
449 | $form->addElement(new \XoopsFormHidden('datecreated_int', $evDatecreated)); |
||
450 | $form->addElement(new \XoopsFormHidden('submitter', $evSubmitter)); |
||
451 | if (!$this->isNew() && $permEventsApprove) { |
||
452 | $evStatusSelect = new \XoopsFormSelect(\_MA_WGEVENTS_STATUS, 'status', $evStatus); |
||
453 | $evStatusSelect->addOption(Constants::STATUS_NONE, \_MA_WGEVENTS_STATUS_NONE); |
||
454 | $evStatusSelect->addOption(Constants::STATUS_OFFLINE, \_MA_WGEVENTS_STATUS_OFFLINE); |
||
455 | $evStatusSelect->addOption(Constants::STATUS_SUBMITTED, \_MA_WGEVENTS_STATUS_SUBMITTED); |
||
456 | $evStatusSelect->addOption(Constants::STATUS_APPROVED, \_MA_WGEVENTS_STATUS_APPROVED); |
||
457 | $form->addElement($evStatusSelect, true); |
||
458 | $form->addElement(new \XoopsFormLabel(\_MA_WGEVENTS_DATECREATED, \formatTimestamp($evDatecreated, 's'))); |
||
459 | $form->addElement(new \XoopsFormLabel(\_MA_WGEVENTS_SUBMITTER, \XoopsUser::getUnameFromId($evSubmitter))); |
||
460 | } |
||
461 | } |
||
462 | if ($this->idSource > 0 && $helper->getConfig('use_register')) { |
||
463 | $form->addElement(new \XoopsFormRadioYN(\_MA_WGEVENTS_EVENT_CLONE_QUESTION, 'clone_question', 1)); |
||
464 | $form->addElement(new \XoopsFormHidden('id_source', $this->idSource)); |
||
465 | } |
||
466 | if (!$this->isNew() && 0 === $this->idSource) { |
||
467 | $informModif = new \XoopsFormRadioYN(\_MA_WGEVENTS_EVENT_INFORM_MODIF, 'informModif', 0); |
||
468 | $informModif->setDescription(\_MA_WGEVENTS_EVENT_INFORM_MODIF_DESC); |
||
469 | $form->addElement($informModif); |
||
470 | } |
||
471 | // To Save |
||
472 | $form->addElement(new \XoopsFormHidden('op', 'save')); |
||
473 | $form->addElement(new \XoopsFormHidden('start', $this->start)); |
||
474 | $form->addElement(new \XoopsFormHidden('limit', $this->limit)); |
||
475 | $form->addElement(new \XoopsFormHidden('cats', $this->cats)); |
||
476 | // button tray |
||
477 | $buttonTray = new \XoopsFormElementTray(''); |
||
478 | $buttonBack = new Forms\FormButton('', 'confirm_back', \_CANCEL, 'button'); |
||
479 | $buttonBack->setExtra('onclick="history.go(-1);return true;"'); |
||
480 | $buttonBack->setClass('btn-danger'); |
||
481 | $buttonTray->addElement($buttonBack); |
||
482 | |||
483 | $buttonReset = new Forms\FormButton('', 'reset', \_RESET, 'reset'); |
||
484 | $buttonReset->setClass('btn-warning'); |
||
485 | $buttonTray->addElement($buttonReset); |
||
486 | |||
487 | $buttonSubmit = new Forms\FormButton('', '_submit', \_MA_WGEVENTS_SAVE, 'submit'); |
||
488 | $buttonSubmit->setClass('btn-primary'); |
||
489 | $buttonTray->addElement($buttonSubmit); |
||
490 | |||
491 | $buttonNext = new Forms\FormButton('', 'continue_questions', \_MA_WGEVENTS_CONTINUE_QUESTIONY, 'submit'); |
||
492 | $buttonNext->setClass('btn-primary'); |
||
493 | if (!$evRegister_use) { |
||
494 | $buttonNext->setHidden(); |
||
495 | } |
||
496 | $buttonTray->addElement($buttonNext); |
||
497 | $form->addElement($buttonTray); |
||
498 | |||
499 | return $form; |
||
500 | } |
||
791 |
Let?s assume that you have a directory layout like this:
and let?s assume the following content of
Bar.php
:If both files
OtherDir/Foo.php
andSomeDir/Foo.php
are loaded in the same runtime, you will see a PHP error such as the following:PHP Fatal error: Cannot use SomeDir\Foo as Foo because the name is already in use in OtherDir/Foo.php
However, as
OtherDir/Foo.php
does not necessarily have to be loaded and the error is only triggered if it is loaded beforeOtherDir/Bar.php
, this problem might go unnoticed for a while. In order to prevent this error from surfacing, you must import the namespace with a different alias: