| Total Complexity | 98 |
| Total Lines | 664 |
| Duplicated Lines | 0 % |
| Changes | 0 | ||
Complex classes like Event often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use Event, and based on these observations, apply Extract Interface, too.
| 1 | <?php declare(strict_types=1); |
||
| 39 | class Event extends \XoopsObject |
||
| 40 | { |
||
| 41 | /** |
||
| 42 | * @var int |
||
| 43 | */ |
||
| 44 | public $start = 0; |
||
| 45 | |||
| 46 | /** |
||
| 47 | * @var int |
||
| 48 | */ |
||
| 49 | public $limit = 0; |
||
| 50 | |||
| 51 | /** |
||
| 52 | * @var int |
||
| 53 | */ |
||
| 54 | public $idSource = 0; |
||
| 55 | |||
| 56 | /** |
||
| 57 | * @var string |
||
| 58 | */ |
||
| 59 | public $cats = ''; |
||
| 60 | |||
| 61 | /** |
||
| 62 | * Constructor |
||
| 63 | * |
||
| 64 | * @param null |
||
| 65 | */ |
||
| 66 | public function __construct() |
||
| 67 | { |
||
| 68 | $this->initVar('id', \XOBJ_DTYPE_INT); |
||
| 69 | $this->initVar('catid', \XOBJ_DTYPE_INT); |
||
| 70 | $this->initVar('subcats', \XOBJ_DTYPE_OTHER); |
||
| 71 | $this->initVar('name', \XOBJ_DTYPE_TXTBOX); |
||
| 72 | $this->initVar('logo', \XOBJ_DTYPE_TXTBOX); |
||
| 73 | $this->initVar('desc', \XOBJ_DTYPE_OTHER); |
||
| 74 | $this->initVar('datefrom', \XOBJ_DTYPE_INT); |
||
| 75 | $this->initVar('dateto', \XOBJ_DTYPE_INT); |
||
| 76 | $this->initVar('allday', \XOBJ_DTYPE_INT); |
||
| 77 | $this->initVar('contact', \XOBJ_DTYPE_TXTAREA); |
||
| 78 | $this->initVar('email', \XOBJ_DTYPE_TXTBOX); |
||
| 79 | $this->initVar('url', \XOBJ_DTYPE_TXTBOX); |
||
| 80 | $this->initVar('location', \XOBJ_DTYPE_TXTAREA); |
||
| 81 | $this->initVar('locgmlat', \XOBJ_DTYPE_FLOAT); |
||
| 82 | $this->initVar('locgmlon', \XOBJ_DTYPE_FLOAT); |
||
| 83 | $this->initVar('locgmzoom', \XOBJ_DTYPE_INT); |
||
| 84 | $this->initVar('fee', \XOBJ_DTYPE_OTHER); |
||
| 85 | $this->initVar('paymentinfo', \XOBJ_DTYPE_OTHER); |
||
| 86 | $this->initVar('register_use', \XOBJ_DTYPE_INT); |
||
| 87 | $this->initVar('register_from', \XOBJ_DTYPE_INT); |
||
| 88 | $this->initVar('register_to', \XOBJ_DTYPE_INT); |
||
| 89 | $this->initVar('register_max', \XOBJ_DTYPE_INT); |
||
| 90 | $this->initVar('register_listwait', \XOBJ_DTYPE_INT); |
||
| 91 | $this->initVar('register_autoaccept', \XOBJ_DTYPE_INT); |
||
| 92 | $this->initVar('register_notify', \XOBJ_DTYPE_TXTAREA); |
||
| 93 | $this->initVar('register_sendermail', \XOBJ_DTYPE_TXTBOX); |
||
| 94 | $this->initVar('register_sendername', \XOBJ_DTYPE_TXTBOX); |
||
| 95 | $this->initVar('register_signature', \XOBJ_DTYPE_TXTAREA); |
||
| 96 | $this->initVar('register_forceverif', \XOBJ_DTYPE_INT); |
||
| 97 | $this->initVar('status', \XOBJ_DTYPE_INT); |
||
| 98 | $this->initVar('galid', \XOBJ_DTYPE_INT); |
||
| 99 | $this->initVar('identifier', \XOBJ_DTYPE_TXTBOX); |
||
| 100 | $this->initVar('groups', \XOBJ_DTYPE_TXTBOX); |
||
| 101 | $this->initVar('datecreated', \XOBJ_DTYPE_INT); |
||
| 102 | $this->initVar('submitter', \XOBJ_DTYPE_INT); |
||
| 103 | } |
||
| 104 | |||
| 105 | /** |
||
| 106 | * @static function &getInstance |
||
| 107 | * |
||
| 108 | * @param null |
||
| 109 | */ |
||
| 110 | public static function getInstance() |
||
| 115 | } |
||
| 116 | } |
||
| 117 | |||
| 118 | /** |
||
| 119 | * The new inserted $Id |
||
| 120 | * @return inserted id |
||
| 121 | */ |
||
| 122 | public function getNewInsertedId() |
||
| 125 | } |
||
| 126 | |||
| 127 | /** |
||
| 128 | * @public function getForm |
||
| 129 | * @param bool $action |
||
| 130 | * @return \XoopsThemeForm |
||
| 131 | */ |
||
| 132 | public function getForm($action = false) |
||
| 133 | { |
||
| 134 | $helper = Helper::getInstance(); |
||
| 135 | |||
| 136 | $categoryHandler = $helper->getHandler('Category'); |
||
| 137 | $permissionsHandler = $helper->getHandler('Permission'); |
||
| 138 | |||
| 139 | $utility = new Utility(); |
||
| 140 | |||
| 141 | if (!$action) { |
||
| 142 | $action = $_SERVER['REQUEST_URI']; |
||
| 143 | } |
||
| 144 | $isAdmin = false; |
||
| 145 | $userUid = 0; |
||
| 146 | $userEmail = ''; |
||
| 147 | $userName = ''; |
||
| 148 | if (\is_object($GLOBALS['xoopsUser'])) { |
||
| 149 | if (\is_object($GLOBALS['xoopsModule'])) { |
||
| 150 | $isAdmin = $GLOBALS['xoopsUser']->isAdmin($GLOBALS['xoopsModule']->mid()); |
||
| 151 | } |
||
| 152 | $userUid = $GLOBALS['xoopsUser']->uid(); |
||
| 153 | $userEmail = $GLOBALS['xoopsUser']->email(); |
||
| 154 | $userName = ('' != (string)$GLOBALS['xoopsUser']->name()) ? $GLOBALS['xoopsUser']->name() : $GLOBALS['xoopsUser']->uname(); |
||
| 155 | } |
||
| 156 | |||
| 157 | $imgInfo = '<img class="wge-img-info" src="' . \WGEVENTS_ICONS_URL_24 . '/info.png" alt="img-info" title="%s">'; |
||
| 158 | |||
| 159 | // Title |
||
| 160 | $title = $this->isNew() ? \_MA_WGEVENTS_EVENT_ADD : \_MA_WGEVENTS_EVENT_EDIT; |
||
| 161 | if ($this->idSource > 0) { |
||
| 162 | $this->unsetNew(); |
||
| 163 | } |
||
| 164 | // Get Theme Form |
||
| 165 | \xoops_load('XoopsFormLoader'); |
||
| 166 | $form = new \XoopsThemeForm($title, 'formEvent', $action, 'post', true); |
||
| 167 | $form->setExtra('enctype="multipart/form-data"'); |
||
| 168 | // Form Text identifier |
||
| 169 | if (!$this->isNew()) { |
||
| 170 | if ($isAdmin) { |
||
| 171 | $form->addElement(new \XoopsFormText(\_MA_WGEVENTS_EVENT_IDENTIFIER, 'identifier', 50, 255, $this->getVar('identifier'))); |
||
| 172 | } else { |
||
| 173 | $form->addElement(new \XoopsFormLabel(\_MA_WGEVENTS_EVENT_IDENTIFIER, $this->getVar('identifier'))); |
||
| 174 | $form->addElement(new \XoopsFormHidden('identifier', (string)$this->getVar('identifier'))); |
||
| 175 | } |
||
| 176 | } |
||
| 177 | // Form Table categories |
||
| 178 | $evCatidSelect = new \XoopsFormSelect(\_MA_WGEVENTS_EVENT_CATID, 'catid', $this->getVar('catid')); |
||
| 179 | $evCatidSelect->addOptionArray($categoryHandler->getAllCatsOnline(Constants::CATEGORY_TYPE_MAIN)); |
||
| 180 | $form->addElement($evCatidSelect); |
||
| 181 | // Form Table sub categories |
||
| 182 | // count sub categories |
||
| 183 | $catsSubOnline = $categoryHandler->getAllCatsOnline(Constants::CATEGORY_TYPE_SUB); |
||
| 184 | if (\count($catsSubOnline) > 0) { |
||
| 185 | $evSubCats = $this->isNew() ? [] : \unserialize($this->getVar('subcats')); |
||
| 186 | $evSubCatsSelect = new \XoopsFormCheckBox(\_MA_WGEVENTS_EVENT_SUBCATS, 'subcats', $evSubCats); |
||
| 187 | $evSubCatsSelect->addOptionArray($catsSubOnline); |
||
| 188 | $form->addElement($evSubCatsSelect); |
||
| 189 | } |
||
| 190 | // Form Text evName |
||
| 191 | $form->addElement(new \XoopsFormText(\_MA_WGEVENTS_EVENT_NAME, 'name', 50, 255, $this->getVar('name')), true); |
||
| 192 | // Form Editor DhtmlTextArea evDesc |
||
| 193 | $editorConfigs = []; |
||
| 194 | if ($isAdmin) { |
||
| 195 | $editor = $helper->getConfig('editor_admin'); |
||
| 196 | } else { |
||
| 197 | $editor = $helper->getConfig('editor_user'); |
||
| 198 | } |
||
| 199 | $editorConfigs['name'] = 'desc'; |
||
| 200 | $editorConfigs['value'] = $this->getVar('desc', 'e'); |
||
| 201 | $editorConfigs['rows'] = 5; |
||
| 202 | $editorConfigs['cols'] = 40; |
||
| 203 | $editorConfigs['width'] = '100%'; |
||
| 204 | $editorConfigs['height'] = '400px'; |
||
| 205 | $editorConfigs['editor'] = $editor; |
||
| 206 | $form->addElement(new \XoopsFormEditor(\_MA_WGEVENTS_EVENT_DESC, 'desc', $editorConfigs)); |
||
| 207 | // Form Image evLogo |
||
| 208 | // Form Image evLogo: Select Uploaded Image |
||
| 209 | $getEvLogo = $this->getVar('logo'); |
||
| 210 | $evLogo = $getEvLogo ?: 'blank.gif'; |
||
| 211 | $imageDirectory = '/uploads/wgevents/events/logos/' . $userUid; |
||
| 212 | $folderUid = \XOOPS_ROOT_PATH . $imageDirectory; |
||
| 213 | if (!\file_exists($folderUid)) { |
||
| 214 | $utility::createFolder($folderUid); |
||
| 215 | \chmod($folderUid, 0777); |
||
| 216 | $file = \WGEVENTS_PATH . '/assets/images/blank.gif'; |
||
| 217 | $dest = $folderUid . '/blank.gif'; |
||
| 218 | $utility::copyFile($file, $dest); |
||
| 219 | } |
||
| 220 | $imageTray = new Forms\FormElementTray(\_MA_WGEVENTS_EVENT_LOGO, '<br>'); |
||
| 221 | $imageSelect = new \XoopsFormSelect(\_MA_WGEVENTS_EVENT_LOGO_UPLOADS, 'logo', $evLogo, 5); |
||
| 222 | $imageArray = \XoopsLists::getImgListAsArray(\XOOPS_ROOT_PATH . $imageDirectory); |
||
| 223 | foreach ($imageArray as $image1) { |
||
| 224 | $imageSelect->addOption(($image1), $image1); |
||
| 225 | } |
||
| 226 | $imageSelect->setExtra("onchange='showImgSelected(\"imglabel_logo\", \"logo\", \"" . $imageDirectory . '", "", "' . \XOOPS_URL . "\")'"); |
||
| 227 | $imageTray->addElement($imageSelect, false); |
||
| 228 | $imageTray->addElement(new \XoopsFormLabel('', "<br><img src='" . \XOOPS_URL . '/' . $imageDirectory . '/' . $evLogo . "' id='imglabel_logo' alt='' style='max-width:100px' >")); |
||
| 229 | // Form Image evLogo: Upload new image |
||
| 230 | $maxsize = $helper->getConfig('maxsize_image'); |
||
| 231 | $imageTray->addElement(new \XoopsFormFile('<br>' . \_AM_WGEVENTS_FORM_UPLOAD_NEW, 'logo', $maxsize)); |
||
| 232 | $imageTray->addElement(new \XoopsFormLabel(\_AM_WGEVENTS_FORM_UPLOAD_SIZE, ($maxsize / 1048576) . ' ' . \_AM_WGEVENTS_FORM_UPLOAD_SIZE_MB)); |
||
| 233 | $imageTray->addElement(new \XoopsFormLabel(\_AM_WGEVENTS_FORM_UPLOAD_IMG_WIDTH, $helper->getConfig('maxwidth_image') . ' px')); |
||
| 234 | $imageTray->addElement(new \XoopsFormLabel(\_AM_WGEVENTS_FORM_UPLOAD_IMG_HEIGHT, $helper->getConfig('maxheight_image') . ' px')); |
||
| 235 | $form->addElement($imageTray); |
||
| 236 | // Form Tray Datefrom |
||
| 237 | $evDatefromTray = new Forms\FormElementTray(\_MA_WGEVENTS_EVENT_DATEFROM, ' '); |
||
| 238 | // Text Date Select evDatefrom |
||
| 239 | $evDatefrom = ($this->isNew() && 0 == (int)$this->getVar('datefrom')) ? \time() : $this->getVar('datefrom'); |
||
| 240 | $evDatefromTray->addElement(new \XoopsFormDateTime('', 'datefrom', '', $evDatefrom), true); |
||
| 241 | // Text Date Checkbox evAllday |
||
| 242 | $evAllday = $this->isNew() ? 0 : (int)$this->getVar('allday'); |
||
| 243 | $checkAllday = new \XoopsFormCheckBox('', 'allday', $evAllday); |
||
| 244 | $checkAllday->addOption(1, \_MA_WGEVENTS_EVENT_ALLDAY); |
||
| 245 | $checkAllday->setExtra(" onclick='toggleAllday()' "); |
||
| 246 | $evDatefromTray->addElement($checkAllday); |
||
| 247 | $form->addElement($evDatefromTray); |
||
| 248 | // Form Text Date Select evDateto |
||
| 249 | $evDateto = ($this->isNew() && 0 == (int)$this->getVar('dateto')) ? \time() : $this->getVar('dateto'); |
||
| 250 | $form->addElement(new \XoopsFormDateTime(\_MA_WGEVENTS_EVENT_DATETO, 'dateto', '', $evDateto)); |
||
| 251 | // Form Text evContact |
||
| 252 | $form->addElement(new \XoopsFormTextArea(\_MA_WGEVENTS_EVENT_CONTACT, 'contact', $this->getVar('contact', 'e'), 4, 30)); |
||
| 253 | // Form Text evEmail |
||
| 254 | $form->addElement(new \XoopsFormText(\_MA_WGEVENTS_EVENT_EMAIL, 'email', 50, 255, $this->getVar('email'))); |
||
| 255 | // Form Text evUrl |
||
| 256 | $form->addElement(new \XoopsFormText(\_MA_WGEVENTS_EVENT_URL, 'url', 50, 255, $this->getVar('url'))); |
||
| 257 | // Location |
||
| 258 | // Form Editor TextArea evLocation |
||
| 259 | $evLocation = $this->isNew() ? '' : $this->getVar('location', 'e'); |
||
| 260 | $form->addElement(new \XoopsFormTextArea(\_MA_WGEVENTS_EVENT_LOCATION, 'location', $evLocation, 4, 50)); |
||
| 261 | |||
| 262 | if ($helper->getConfig('use_gmaps')) { |
||
| 263 | $gmapsTray = new Forms\FormElementTray('', '<br>'); |
||
| 264 | // Form Text evLocgmlat |
||
| 265 | $evLocgmlat = $this->isNew() ? '0.00' : $this->getVar('locgmlat'); |
||
| 266 | $gmapsTray->addElement(new \XoopsFormText(\_MA_WGEVENTS_EVENT_LOCGMLAT, 'locgmlat', 20, 50, $evLocgmlat)); |
||
| 267 | // Form Text evLocgmlon |
||
| 268 | $evLocgmlon = $this->isNew() ? '0.00' : $this->getVar('locgmlon'); |
||
| 269 | $gmapsTray->addElement(new \XoopsFormText(\_MA_WGEVENTS_EVENT_LOCGMLON, 'locgmlon', 20, 50, $evLocgmlon)); |
||
| 270 | // Form Text evLocgmzoom |
||
| 271 | $evLocgmzoom = $this->isNew() ? '10' : $this->getVar('locgmzoom'); |
||
| 272 | $gmapsTray->addElement(new \XoopsFormText(\_MA_WGEVENTS_EVENT_LOCGMZOOM, 'locgmzoom', 5, 50, $evLocgmzoom)); |
||
| 273 | // Form label |
||
| 274 | $locLabel = '<div class="row"><div class="col-sm-6">'; |
||
| 275 | $locLabel .= $gmapsTray->render(); |
||
| 276 | $locLabel .= '</div>'; |
||
| 277 | $locLabel .= '<div class="col-sm-6">'; |
||
| 278 | $locLabel .= "<button id='btnGetCoords' type='button' class='btn btn-primary' data-toggle='modal' data-target='#modalCoordsPicker'>" . \_MA_WGEVENTS_EVENT_GM_GETCOORDS . '</button>'; |
||
| 279 | $locLabel .= '</div></div>'; |
||
| 280 | $form->addElement(new \XoopsFormLabel('', $locLabel)); |
||
| 281 | } |
||
| 282 | // Form Text evFee |
||
| 283 | $default0 = '0' . $helper->getConfig('sep_comma') . '00'; |
||
| 284 | $evFeeArr = []; |
||
| 285 | if ($this->isNew()) { |
||
| 286 | $evFeeArr = [[$default0, '', 'placeholder' => \_MA_WGEVENTS_EVENT_FEE_DESC_PH]]; |
||
| 287 | } else { |
||
| 288 | $evFee = \json_decode($this->getVar('fee'), true); |
||
| 289 | foreach($evFee as $fee) { |
||
| 290 | $evFeeArr[] = [Utility::FloatToString((float)$fee[0]), $fee[1], 'placeholder' => \_MA_WGEVENTS_EVENT_FEE_DESC_PH]; |
||
| 291 | } |
||
| 292 | if (0 === \count($evFeeArr)) { |
||
| 293 | $evFeeArr = [[$default0, '', 'placeholder' => \_MA_WGEVENTS_EVENT_FEE_DESC_PH]]; |
||
| 294 | } |
||
| 295 | } |
||
| 296 | $evFeeTray = new Forms\FormElementTray(\_MA_WGEVENTS_EVENT_FEE, '<br>'); |
||
| 297 | $evFeeGroup = new Forms\FormTextDouble('', 'fee', 0, 0, ''); |
||
| 298 | $evFeeGroup->setElements($evFeeArr); |
||
| 299 | $evFeeGroup->setPlaceholder1(\_MA_WGEVENTS_EVENT_FEE_VAL_PH); |
||
| 300 | $evFeeGroup->setPlaceholder2(\_MA_WGEVENTS_EVENT_FEE_DESC_PH); |
||
| 301 | $evFeeTray->addElement($evFeeGroup); |
||
| 302 | |||
| 303 | $form->addElement($evFeeTray); |
||
| 304 | // Form TextArea evPaymentinfo |
||
| 305 | $editorConfigs2 = []; |
||
| 306 | $editorConfigs2['name'] = 'paymentinfo'; |
||
| 307 | $editorConfigs2['value'] = $this->getVar('paymentinfo', 'e'); |
||
| 308 | $editorConfigs2['rows'] = 5; |
||
| 309 | $editorConfigs2['cols'] = 40; |
||
| 310 | $editorConfigs2['width'] = '100%'; |
||
| 311 | $editorConfigs2['height'] = '400px'; |
||
| 312 | $editorConfigs2['editor'] = $editor; |
||
| 313 | $form->addElement(new \XoopsFormEditor(\_MA_WGEVENTS_EVENT_PAYMENTINFO, 'paymentinfo', $editorConfigs2)); |
||
| 314 | |||
| 315 | // Start block registration options |
||
| 316 | if ($helper->getConfig('use_register')) { |
||
| 317 | // Form Radio Yes/No evRegister_use |
||
| 318 | $evRegister_use = $this->isNew() ? 0 : $this->getVar('register_use'); |
||
| 319 | $evRegisterUseRadio = new \XoopsFormRadioYN(\_MA_WGEVENTS_EVENT_REGISTER_USE, 'register_use', $evRegister_use); |
||
| 320 | $evRegisterUseRadio->setExtra(" onclick='toggleRegistrationOpts()' "); |
||
| 321 | $form->addElement($evRegisterUseRadio); |
||
| 322 | $evReservUseTray = new \XoopsFormElementTray('', '<br>'); //double element tray is necessary for proper toggle |
||
| 323 | $evRegisterOptsTray = new Forms\FormElementTray('', '<br>', 'registeropttray'); |
||
| 324 | $evRegisterOptsTray->setClass('col-xs-12 col-sm-5 col-lg-5'); |
||
| 325 | if (!$evRegister_use) { |
||
| 326 | $evRegisterOptsTray->setHidden(); |
||
| 327 | } |
||
| 328 | // Form Text Date Select evRegisterfrom |
||
| 329 | $evRegisterfrom = $this->isNew() ? \time() : $this->getVar('register_from'); |
||
| 330 | $evRegisterOptsTray->addElement(new \XoopsFormDateTime(\_MA_WGEVENTS_EVENT_REGISTER_FROM, 'register_from', '', $evRegisterfrom)); |
||
| 331 | // Form Text Date Select evRegisterto |
||
| 332 | $evRegisterto = $this->isNew() ? \time() : $this->getVar('register_to'); |
||
| 333 | $evRegisterOptsTray->addElement(new \XoopsFormDateTime(\_MA_WGEVENTS_EVENT_REGISTER_TO, 'register_to', '', $evRegisterto)); |
||
| 334 | // Form Text evRegisterMax |
||
| 335 | $evRegisterMax = $this->isNew() ? 0 : $this->getVar('register_max'); |
||
| 336 | $captionRegisterMax = \_MA_WGEVENTS_EVENT_REGISTER_MAX . \sprintf($imgInfo, \_MA_WGEVENTS_EVENT_REGISTER_MAX_DESC); |
||
| 337 | $evRegisterOptsTray->addElement(new \XoopsFormText($captionRegisterMax, 'register_max', 5, 50, $evRegisterMax)); |
||
| 338 | // Form Radio Yes/No evRegisterListwait |
||
| 339 | $evRegisterListwait = $this->isNew() ? 0 : $this->getVar('register_listwait'); |
||
| 340 | $captionRegisterListwait = \_MA_WGEVENTS_EVENT_REGISTER_LISTWAIT . \sprintf($imgInfo, \_MA_WGEVENTS_EVENT_REGISTER_LISTWAIT_DESC); |
||
| 341 | $evRegisterOptsTray->addElement(new \XoopsFormRadioYN($captionRegisterListwait, 'register_listwait', $evRegisterListwait)); |
||
| 342 | // Form Select User evRegisterAutoaccept |
||
| 343 | $evRegisterAutoaccept = $this->isNew() ? 0 : $this->getVar('register_autoaccept'); |
||
| 344 | $captionRegisterAutoaccept = \_MA_WGEVENTS_EVENT_REGISTER_AUTOACCEPT . \sprintf($imgInfo, \_MA_WGEVENTS_EVENT_REGISTER_AUTOACCEPT_DESC); |
||
| 345 | $evRegisterOptsTray->addElement(new \XoopsFormRadioYN($captionRegisterAutoaccept, 'register_autoaccept', $evRegisterAutoaccept)); |
||
| 346 | // Form Editor TextArea evRegisterNotify |
||
| 347 | $evRegisterNotify = $this->isNew() ? $userEmail : $this->getVar('register_notify', 'e'); |
||
| 348 | $captionRegisterNotify = \_MA_WGEVENTS_EVENT_REGISTER_NOTIFY . \sprintf($imgInfo, \_MA_WGEVENTS_EVENT_REGISTER_NOTIFY_DESC); |
||
| 349 | $evRegisterOptsTray->addElement(new \XoopsFormTextArea($captionRegisterNotify, 'register_notify', $evRegisterNotify, 4, 30)); |
||
| 350 | // Form Text evRegisterSendermail |
||
| 351 | $evRegisterSendermail = $this->isNew() ? $userEmail : $this->getVar('register_sendermail'); |
||
| 352 | $captionRegisterSendermail = \_MA_WGEVENTS_EVENT_REGISTER_SENDERMAIL . \sprintf($imgInfo, \_MA_WGEVENTS_EVENT_REGISTER_SENDERMAIL_DESC); |
||
| 353 | $evRegisterOptsTray->addElement(new \XoopsFormText($captionRegisterSendermail, 'register_sendermail', 35, 255, $evRegisterSendermail)); |
||
| 354 | // Form Text evRegisterSendername |
||
| 355 | $evRegisterSendername = $this->isNew() ? $userName : $this->getVar('register_sendername'); |
||
| 356 | $captionRegisterSendername = \_MA_WGEVENTS_EVENT_REGISTER_SENDERNAME . \sprintf($imgInfo, \_MA_WGEVENTS_EVENT_REGISTER_SENDERNAME_DESC); |
||
| 357 | $evRegisterOptsTray->addElement(new \XoopsFormText($captionRegisterSendername, 'register_sendername', 35, 255, $evRegisterSendername)); |
||
| 358 | // Form Editor TextArea evRegisterSignature |
||
| 359 | $evRegisterSignature = $this->isNew() ? '' : $this->getVar('register_signature', 'e'); |
||
| 360 | $captionRegisterSignature = \_MA_WGEVENTS_EVENT_REGISTER_SIGNATURE . \sprintf($imgInfo, \_MA_WGEVENTS_EVENT_REGISTER_SIGNATURE_DESC); |
||
| 361 | $evRegisterOptsTray->addElement(new \XoopsFormTextArea($captionRegisterSignature, 'register_signature', $evRegisterSignature, 4, 30)); |
||
| 362 | // Form Radio Yes/No evRegisterListwait |
||
| 363 | $evRegisterForceverif = $this->isNew() ? 1 : $this->getVar('register_forceverif'); |
||
| 364 | $captionRegisterForceverif = \_MA_WGEVENTS_EVENT_REGISTER_FORCEVERIF . \sprintf($imgInfo, \_MA_WGEVENTS_EVENT_REGISTER_FORCEVERIF_DESC); |
||
| 365 | $evRegisterOptsTray->addElement(new \XoopsFormRadioYN($captionRegisterForceverif, 'register_forceverif', $evRegisterForceverif)); |
||
| 366 | |||
| 367 | $evReservUseTray->addElement($evRegisterOptsTray); |
||
| 368 | $form->addElement($evReservUseTray); |
||
| 369 | //$form->addElement(new \XoopsFormLabel('', $evReservUseTray)); |
||
| 370 | // End block registration options |
||
| 371 | } |
||
| 372 | // Form Select evGalid |
||
| 373 | if ($helper->getConfig('use_wggallery')) { |
||
| 374 | /*TODO */ |
||
| 375 | /* |
||
| 376 | $evGalidSelect = new \XoopsFormSelect(\_MA_WGEVENTS_EVENT_GALID, 'galid', $this->getVar('galid')); |
||
| 377 | $evGalidSelect->addOption('Empty'); |
||
| 378 | $evGalidSelect->addOptionArray($albumHandler->getList()); |
||
| 379 | $form->addElement($evGalidSelect); |
||
| 380 | */ |
||
| 381 | } |
||
| 382 | // Form Select evGroups |
||
| 383 | if ($helper->getConfig('use_groups')) { |
||
| 384 | if ($this->isNew()) { |
||
| 385 | $groups = ['00000']; |
||
| 386 | } else { |
||
| 387 | $groups = \explode("|", $this->getVar('groups')); |
||
| 388 | } |
||
| 389 | $evGroupsSelect = new \XoopsFormSelect(\_MA_WGEVENTS_EVENT_GROUPS, 'groups', $groups, 5, true); |
||
| 390 | $evGroupsSelect->addOption('00000', \_MA_WGEVENTS_EVENT_GROUPS_ALL); |
||
| 391 | // Get groups |
||
| 392 | $memberHandler = \xoops_getHandler('member'); |
||
| 393 | $xoopsGroups = $memberHandler->getGroupList(); |
||
| 394 | foreach ($xoopsGroups as $key => $group) { |
||
| 395 | if (3 !== (int)$key) { |
||
| 396 | $evGroupsSelect->addOption(substr('00000' . $key, -5), $group); |
||
| 397 | } |
||
| 398 | } |
||
| 399 | $form->addElement($evGroupsSelect, true); |
||
| 400 | } else { |
||
| 401 | $form->addElement(new \XoopsFormHidden('groups', '00000')); |
||
| 402 | } |
||
| 403 | // Form Select Status evStatus |
||
| 404 | // Form Text Date Select evDatecreated |
||
| 405 | // Form Select User evSubmitter |
||
| 406 | $permEventsApprove = $permissionsHandler->getPermEventsApprove(); |
||
| 407 | $permEventsApproveAuto = $permissionsHandler->getPermEventsApproveAuto(); |
||
| 408 | if ($this->isNew()) { |
||
| 409 | $evStatus = $permEventsApproveAuto ? Constants::STATUS_APPROVED : Constants::STATUS_SUBMITTED; |
||
| 410 | } else { |
||
| 411 | $evStatus = $this->getVar('status'); |
||
| 412 | } |
||
| 413 | $evDatecreated = $this->isNew() ? \time() : (int)$this->getVar('datecreated'); |
||
| 414 | $evSubmitter = $this->isNew() ? $userUid : (int)$this->getVar('submitter'); |
||
| 415 | if ($isAdmin) { |
||
| 416 | $evStatusSelect = new \XoopsFormSelect(\_MA_WGEVENTS_STATUS, 'status', $evStatus); |
||
| 417 | $evStatusSelect->addOption(Constants::STATUS_NONE, \_MA_WGEVENTS_STATUS_NONE); |
||
| 418 | $evStatusSelect->addOption(Constants::STATUS_OFFLINE, \_MA_WGEVENTS_STATUS_OFFLINE); |
||
| 419 | $evStatusSelect->addOption(Constants::STATUS_SUBMITTED, \_MA_WGEVENTS_STATUS_SUBMITTED); |
||
| 420 | $evStatusSelect->addOption(Constants::STATUS_APPROVED, \_MA_WGEVENTS_STATUS_APPROVED); |
||
| 421 | $evStatusSelect->addOption(Constants::STATUS_LOCKED, \_MA_WGEVENTS_STATUS_LOCKED); |
||
| 422 | $evStatusSelect->addOption(Constants::STATUS_CANCELED, \_MA_WGEVENTS_STATUS_CANCELED); |
||
| 423 | $form->addElement($evStatusSelect, true); |
||
| 424 | $form->addElement(new \XoopsFormTextDateSelect(\_MA_WGEVENTS_DATECREATED, 'datecreated', '', $evDatecreated)); |
||
| 425 | $form->addElement(new \XoopsFormSelectUser(\_MA_WGEVENTS_SUBMITTER, 'submitter', false, $evSubmitter)); |
||
| 426 | } else { |
||
| 427 | $form->addElement(new \XoopsFormHidden('status', $evStatus)); |
||
| 428 | $form->addElement(new \XoopsFormHidden('datecreated_int', $evDatecreated)); |
||
| 429 | $form->addElement(new \XoopsFormHidden('submitter', $evSubmitter)); |
||
| 430 | if (!$this->isNew() && $permEventsApprove) { |
||
| 431 | $evStatusSelect = new \XoopsFormSelect(\_MA_WGEVENTS_STATUS, 'status', $evStatus); |
||
| 432 | $evStatusSelect->addOption(Constants::STATUS_NONE, \_MA_WGEVENTS_STATUS_NONE); |
||
| 433 | $evStatusSelect->addOption(Constants::STATUS_OFFLINE, \_MA_WGEVENTS_STATUS_OFFLINE); |
||
| 434 | $evStatusSelect->addOption(Constants::STATUS_SUBMITTED, \_MA_WGEVENTS_STATUS_SUBMITTED); |
||
| 435 | $evStatusSelect->addOption(Constants::STATUS_APPROVED, \_MA_WGEVENTS_STATUS_APPROVED); |
||
| 436 | $form->addElement($evStatusSelect, true); |
||
| 437 | $form->addElement(new \XoopsFormLabel(\_MA_WGEVENTS_DATECREATED, \formatTimestamp($evDatecreated, 's'))); |
||
| 438 | $form->addElement(new \XoopsFormLabel(\_MA_WGEVENTS_SUBMITTER, \XoopsUser::getUnameFromId($evSubmitter))); |
||
| 439 | } |
||
| 440 | } |
||
| 441 | if ($this->idSource > 0 && $helper->getConfig('use_register')) { |
||
| 442 | $form->addElement(new \XoopsFormRadioYN(\_MA_WGEVENTS_EVENT_CLONE_QUESTION, 'clone_question', 1)); |
||
| 443 | $form->addElement(new \XoopsFormHidden('id_source', $this->idSource)); |
||
| 444 | } |
||
| 445 | if (!$this->isNew() && 0 === $this->idSource) { |
||
| 446 | $informModif = new \XoopsFormRadioYN(\_MA_WGEVENTS_EVENT_INFORM_MODIF, 'informModif', 0); |
||
| 447 | $informModif->setDescription(\_MA_WGEVENTS_EVENT_INFORM_MODIF_DESC); |
||
| 448 | $form->addElement($informModif); |
||
| 449 | } |
||
| 450 | // To Save |
||
| 451 | $form->addElement(new \XoopsFormHidden('op', 'save')); |
||
| 452 | $form->addElement(new \XoopsFormHidden('start', $this->start)); |
||
| 453 | $form->addElement(new \XoopsFormHidden('limit', $this->limit)); |
||
| 454 | $form->addElement(new \XoopsFormHidden('cats', $this->cats)); |
||
| 455 | // button tray |
||
| 456 | $buttonTray = new \XoopsFormElementTray(''); |
||
| 457 | $buttonBack = new Forms\FormButton('', 'confirm_back', \_CANCEL, 'button'); |
||
| 458 | $buttonBack->setExtra('onclick="history.go(-1);return true;"'); |
||
| 459 | $buttonBack->setClass('btn-danger'); |
||
| 460 | $buttonTray->addElement($buttonBack); |
||
| 461 | |||
| 462 | $buttonReset = new Forms\FormButton('', 'reset', \_RESET, 'reset'); |
||
| 463 | $buttonReset->setClass('btn-warning'); |
||
| 464 | $buttonTray->addElement($buttonReset); |
||
| 465 | |||
| 466 | $buttonSubmit = new Forms\FormButton('', '_submit', \_MA_WGEVENTS_SAVE, 'submit'); |
||
| 467 | $buttonSubmit->setClass('btn-primary'); |
||
| 468 | $buttonTray->addElement($buttonSubmit); |
||
| 469 | |||
| 470 | $buttonNext = new Forms\FormButton('', 'continue_questions', \_MA_WGEVENTS_CONTINUE_QUESTIONY, 'submit'); |
||
| 471 | $buttonNext->setClass('btn-primary'); |
||
| 472 | if (!$evRegister_use) { |
||
| 473 | $buttonNext->setHidden(); |
||
| 474 | } |
||
| 475 | $buttonTray->addElement($buttonNext); |
||
| 476 | $form->addElement($buttonTray); |
||
| 477 | |||
| 478 | return $form; |
||
| 479 | } |
||
| 480 | |||
| 481 | /** |
||
| 482 | * @public function getFormContactAll |
||
| 483 | * @param bool $action |
||
| 484 | * @return \XoopsThemeForm |
||
| 485 | */ |
||
| 486 | public function getFormContactAll($action = false) |
||
| 543 | } |
||
| 544 | |||
| 545 | /** |
||
| 546 | * Get Values |
||
| 547 | * @param null $keys |
||
| 548 | * @param null $format |
||
| 549 | * @param null $maxDepth |
||
| 550 | * @return array |
||
| 551 | */ |
||
| 552 | public function getValuesEvents($keys = null, $format = null, $maxDepth = null) |
||
| 553 | { |
||
| 554 | $helper = \XoopsModules\Wgevents\Helper::getInstance(); |
||
| 555 | $utility = new \XoopsModules\Wgevents\Utility(); |
||
| 556 | $ret = $this->getValues($keys, $format, $maxDepth); |
||
| 557 | $adminMaxchar = $helper->getConfig('admin_maxchar'); |
||
| 558 | $userMaxchar = $helper->getConfig('user_maxchar'); |
||
| 559 | $eventDayname = $helper->getConfig('event_dayname'); |
||
| 560 | $categoryHandler = $helper->getHandler('Category'); |
||
| 561 | $catId = (int)$this->getVar('catid'); |
||
| 562 | $categoryObj = $categoryHandler->get($catId); |
||
| 563 | $catName = ''; |
||
| 564 | $catLogo = ''; |
||
| 565 | if (\is_object($categoryObj)) { |
||
| 566 | $catName = $categoryObj->getVar('name'); |
||
| 567 | if ('blank.gif' !== (string)$categoryObj->getVar('logo')) { |
||
| 568 | $catLogo = $categoryObj->getVar('logo'); |
||
| 569 | } |
||
| 570 | } |
||
| 571 | $ret['catname'] = $catName; |
||
| 572 | $ret['catlogo'] = $catLogo; |
||
| 573 | $subcatsArr = []; |
||
| 574 | $subcats = \unserialize($this->getVar('subcats')); |
||
| 575 | if (\is_array($subcats) && \count($subcats) > 0) { |
||
| 576 | foreach ($subcats as $subcat) { |
||
| 577 | $subcategoryObj = $categoryHandler->get($subcat); |
||
| 578 | // do not repeat main cat in sub cats even if it is checked there once more |
||
| 579 | if (\is_object($subcategoryObj) && $catId !== (int)$subcat) { |
||
| 580 | //if (\is_object($subcategoryObj)) { |
||
| 581 | $subcatsArr[$subcat]['id'] = $subcat; |
||
| 582 | $subcatsArr[$subcat]['name'] = $subcategoryObj->getVar('name'); |
||
| 583 | $subcatsArr[$subcat]['logo'] = $subcat; |
||
| 584 | if ('blank.gif' !== (string)$subcategoryObj->getVar('logo')) { |
||
| 585 | $subcatsArr[$subcat]['logo'] = $subcategoryObj->getVar('logo'); |
||
| 586 | } |
||
| 587 | } |
||
| 588 | } |
||
| 589 | } |
||
| 590 | $ret['subcats_arr'] = $subcatsArr; |
||
| 591 | $ret['name_clean'] = \htmlspecialchars($this->getVar('name'), ENT_QUOTES | ENT_HTML5); |
||
| 592 | $ret['desc_text'] = $this->getVar('desc', 'e'); |
||
| 593 | $ret['desc_short_admin'] = $utility::truncateHtml($ret['desc_text'], $adminMaxchar); |
||
| 594 | $ret['desc_short_user'] = $utility::truncateHtml($ret['desc_text'], $userMaxchar); |
||
| 595 | $ret['logoExist'] = ('blank.gif' !== (string)$this->getVar('logo') && 'blank.png' !== (string)$this->getVar('logo')); |
||
| 596 | $evAllday = (int)$this->getVar('allday'); |
||
| 597 | $ret['allday_single'] = 0; |
||
| 598 | if ($evAllday > 0) { |
||
| 599 | $datefrom_text = \formatTimestamp($this->getVar('datefrom'), 's'); |
||
| 600 | $dateto_text = \formatTimestamp($this->getVar('dateto'), 's'); |
||
| 601 | $ret['datefrom_text'] = $datefrom_text . ' ' . \_MA_WGEVENTS_EVENT_ALLDAY; |
||
| 602 | if ($datefrom_text === $dateto_text) { |
||
| 603 | //single allday |
||
| 604 | $ret['allday_single'] = 1; |
||
| 605 | $ret['dateto_text'] = ' '; |
||
| 606 | } else { |
||
| 607 | $ret['dateto_text'] = $dateto_text . ' ' . \_MA_WGEVENTS_EVENT_ALLDAY; |
||
| 608 | } |
||
| 609 | } else { |
||
| 610 | $ret['datefrom_text'] = \formatTimestamp($this->getVar('datefrom'), 'm'); |
||
| 611 | $ret['dateto_text'] = \formatTimestamp($this->getVar('dateto'), 'm'); |
||
| 612 | } |
||
| 613 | $ret['datefrom_dayname'] = $this->getDayname($eventDayname, \formatTimestamp($this->getVar('datefrom'), 'w')); |
||
| 614 | $ret['dateto_dayname'] = $this->getDayname($eventDayname, \formatTimestamp($this->getVar('dateto'), 'w')); |
||
| 615 | $evLocation = $this->getVar('location', 'e'); |
||
| 616 | $ret['location_text'] = $evLocation; |
||
| 617 | if ($evLocation) { |
||
| 618 | $loc = preg_split("/\r\n|\n|\r/", $evLocation); |
||
| 619 | $ret['location_text_user'] = \implode('<br>', $loc); |
||
| 620 | } |
||
| 621 | $evContact = $this->getVar('contact', 'e'); |
||
| 622 | $ret['contact_text'] = $evContact; |
||
| 623 | if ($evContact) { |
||
| 624 | $contactLines = preg_split("/\r\n|\n|\r/", $evContact); |
||
| 625 | $ret['contact_text_user'] = \implode('<br>', $contactLines); |
||
| 626 | } |
||
| 627 | $evFee = \json_decode($this->getVar('fee'), true); |
||
| 628 | $evFeeText = ''; |
||
| 629 | foreach($evFee as $fee) { |
||
| 630 | $evFeeText .= Utility::FloatToString((float)$fee[0]) . ' ' . $fee[1] . '<br>'; |
||
| 631 | } |
||
| 632 | $ret['fee_text'] = $evFeeText; |
||
| 633 | $ret['paymentinfo_text'] = $this->getVar('paymentinfo', 'e'); |
||
| 634 | $ret['register_use_text'] = (int)$this->getVar('register_use') > 0 ? \_YES : \_NO; |
||
| 635 | $ret['register_from_text'] = ''; |
||
| 636 | $ret['register_from_dayname'] = ''; |
||
| 637 | if ($this->getVar('register_from') > 0) { |
||
| 638 | $ret['register_from_text'] = \formatTimestamp($this->getVar('register_from'), 'm'); |
||
| 639 | $ret['register_from_dayname'] = $this->getDayname($eventDayname, \formatTimestamp($this->getVar('register_from'), 'w')); |
||
| 640 | } |
||
| 641 | $ret['register_to_text'] = ''; |
||
| 642 | $ret['register_to_dayname'] = ''; |
||
| 643 | if ($this->getVar('register_to') > 0) { |
||
| 644 | $ret['register_to_text'] = \formatTimestamp($this->getVar('register_to'), 'm'); |
||
| 645 | $ret['register_to_dayname'] = $this->getDayname($eventDayname, \formatTimestamp($this->getVar('register_to'), 'w')); |
||
| 646 | } |
||
| 647 | $regMax = $this->getVar('register_max'); |
||
| 648 | $ret['register_max_text'] = $regMax > 0 ? $this->getVar('register_max') : \_MA_WGEVENTS_EVENT_REGISTER_MAX_UNLIMITED; |
||
| 649 | $ret['register_listwait_text'] = (int)$this->getVar('register_listwait') > 0 ? \_YES : \_NO; |
||
| 650 | $ret['register_autoaccept_text'] = (int)$this->getVar('register_autoaccept') > 0 ? \_YES : \_NO; |
||
| 651 | $evRegisterNotify = $this->getVar('register_notify', 'e'); |
||
| 652 | $ret['register_notify_text'] = $evRegisterNotify; |
||
| 653 | if ($evRegisterNotify) { |
||
| 654 | $notifyEmails = preg_split("/\r\n|\n|\r/", $evRegisterNotify); |
||
| 655 | $ret['register_notify_user'] = \implode('<br>', $notifyEmails); |
||
| 656 | } |
||
| 657 | $ret['register_forceverif_text'] = (int)$this->getVar('register_forceverif') > 0 ? \_YES : \_NO; |
||
| 658 | $evGroups = $this->getVar('groups', 'e'); |
||
| 659 | $groups_text = ''; |
||
| 660 | if (0 == (int)$evGroups) { |
||
| 661 | $groups_text = \_MA_WGEVENTS_EVENT_GROUPS_ALL; |
||
| 662 | } else { |
||
| 663 | // Get groups |
||
| 664 | $groups_text .= '<ul>'; |
||
| 665 | $memberHandler = \xoops_getHandler('member'); |
||
| 666 | $xoopsGroups = $memberHandler->getGroupList(); |
||
| 667 | $groups = explode("|", $evGroups); |
||
| 668 | foreach ($groups as $group) { |
||
| 669 | $groups_text .= '<li>' . $xoopsGroups[(int)$group] . '</li>' ; |
||
| 670 | } |
||
| 671 | $groups_text .= '</ul>'; |
||
| 672 | } |
||
| 673 | $ret['groups_text'] = $groups_text; |
||
| 674 | $ret['status_text'] = Utility::getStatusText($this->getVar('status')); |
||
| 675 | $ret['datecreated_text'] = \formatTimestamp($this->getVar('datecreated'), 's'); |
||
| 676 | $ret['submitter_text'] = \XoopsUser::getUnameFromId($this->getVar('submitter')); |
||
| 677 | return $ret; |
||
| 678 | } |
||
| 679 | |||
| 680 | /** function to get day name |
||
| 681 | * @param $eventDayname // module preference 'event_dayname' |
||
| 682 | * @param $day // weekday of date |
||
| 683 | * @return string |
||
| 684 | */ |
||
| 685 | private function getDayname ($eventDayname, $day) { |
||
| 703 | } |
||
| 704 | } |
||
| 723 |
Let?s assume that you have a directory layout like this:
. |-- OtherDir | |-- Bar.php | `-- Foo.php `-- SomeDir `-- Foo.phpand let?s assume the following content of
Bar.php:If both files
OtherDir/Foo.phpandSomeDir/Foo.phpare 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.phpHowever, as
OtherDir/Foo.phpdoes 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: