Total Complexity | 109 |
Total Lines | 729 |
Duplicated Lines | 0 % |
Changes | 2 | ||
Bugs | 0 | Features | 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 | */ |
||
65 | public function __construct() |
||
66 | { |
||
67 | $this->initVar('id', \XOBJ_DTYPE_INT); |
||
68 | $this->initVar('catid', \XOBJ_DTYPE_INT); |
||
69 | $this->initVar('subcats', \XOBJ_DTYPE_OTHER); |
||
70 | $this->initVar('name', \XOBJ_DTYPE_TXTBOX); |
||
71 | $this->initVar('logo', \XOBJ_DTYPE_TXTBOX); |
||
72 | $this->initVar('desc', \XOBJ_DTYPE_OTHER); |
||
73 | $this->initVar('datefrom', \XOBJ_DTYPE_INT); |
||
74 | $this->initVar('dateto', \XOBJ_DTYPE_INT); |
||
75 | $this->initVar('allday', \XOBJ_DTYPE_INT); |
||
76 | $this->initVar('contact', \XOBJ_DTYPE_TXTAREA); |
||
77 | $this->initVar('email', \XOBJ_DTYPE_TXTBOX); |
||
78 | $this->initVar('url', \XOBJ_DTYPE_TXTBOX); |
||
79 | $this->initVar('location', \XOBJ_DTYPE_TXTAREA); |
||
80 | $this->initVar('locgmlat', \XOBJ_DTYPE_FLOAT); |
||
81 | $this->initVar('locgmlon', \XOBJ_DTYPE_FLOAT); |
||
82 | $this->initVar('locgmzoom', \XOBJ_DTYPE_INT); |
||
83 | $this->initVar('fee_type', \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_TXTBOX); |
||
99 | $this->initVar('url_info', \XOBJ_DTYPE_TXTBOX); |
||
100 | $this->initVar('url_registration', \XOBJ_DTYPE_TXTBOX); |
||
101 | $this->initVar('identifier', \XOBJ_DTYPE_TXTBOX); |
||
102 | $this->initVar('groups', \XOBJ_DTYPE_TXTBOX); |
||
103 | $this->initVar('datecreated', \XOBJ_DTYPE_INT); |
||
104 | $this->initVar('submitter', \XOBJ_DTYPE_INT); |
||
105 | } |
||
106 | |||
107 | /** |
||
108 | * @static function &getInstance |
||
109 | * |
||
110 | */ |
||
111 | public static function getInstance() |
||
116 | } |
||
117 | } |
||
118 | |||
119 | /** |
||
120 | * The new inserted $Id |
||
121 | * @return int |
||
122 | */ |
||
123 | public function getNewInsertedId() |
||
126 | } |
||
127 | |||
128 | /** |
||
129 | * @public function getForm |
||
130 | * @param bool $action |
||
131 | * @return \XoopsThemeForm |
||
132 | */ |
||
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 | $form->addElement(new \XoopsFormText(\_MA_WGEVENTS_EVENT_EMAIL, 'email', 50, 255, $this->getVar('email'))); |
||
256 | // Form Text evUrl |
||
257 | $form->addElement(new \XoopsFormText(\_MA_WGEVENTS_EVENT_URL, 'url', 50, 255, $this->getVar('url'))); |
||
258 | // Location |
||
259 | // Form Editor TextArea evLocation |
||
260 | $evLocation = $this->isNew() ? '' : $this->getVar('location', 'e'); |
||
261 | $form->addElement(new \XoopsFormTextArea(\_MA_WGEVENTS_EVENT_LOCATION, 'location', $evLocation, 4, 50)); |
||
262 | |||
263 | if ($helper->getConfig('use_gmaps')) { |
||
264 | $gmapsTray = new Forms\FormElementTray('', '<br>'); |
||
265 | // Form Text evLocgmlat |
||
266 | $evLocgmlat = $this->isNew() ? '0.00' : $this->getVar('locgmlat'); |
||
267 | $gmapsTray->addElement(new \XoopsFormText(\_MA_WGEVENTS_EVENT_LOCGMLAT, 'locgmlat', 20, 50, $evLocgmlat)); |
||
268 | // Form Text evLocgmlon |
||
269 | $evLocgmlon = $this->isNew() ? '0.00' : $this->getVar('locgmlon'); |
||
270 | $gmapsTray->addElement(new \XoopsFormText(\_MA_WGEVENTS_EVENT_LOCGMLON, 'locgmlon', 20, 50, $evLocgmlon)); |
||
271 | // Form Text evLocgmzoom |
||
272 | $evLocgmzoom = $this->isNew() ? '10' : $this->getVar('locgmzoom'); |
||
273 | $gmapsTray->addElement(new \XoopsFormText(\_MA_WGEVENTS_EVENT_LOCGMZOOM, 'locgmzoom', 5, 50, $evLocgmzoom)); |
||
274 | // Form label |
||
275 | $locLabel = '<div class="row"><div class="col-sm-6">'; |
||
276 | $locLabel .= $gmapsTray->render(); |
||
277 | $locLabel .= '</div>'; |
||
278 | $locLabel .= '<div class="col-sm-6">'; |
||
279 | $locLabel .= "<button id='btnGetCoords' type='button' class='btn btn-primary' data-toggle='modal' data-target='#modalCoordsPicker'>" . \_MA_WGEVENTS_EVENT_GM_GETCOORDS . '</button>'; |
||
280 | $locLabel .= '</div></div>'; |
||
281 | $form->addElement(new \XoopsFormLabel('', $locLabel)); |
||
282 | } |
||
283 | // Form Text evFee |
||
284 | $default0 = '0' . $helper->getConfig('sep_comma') . '00'; |
||
285 | $evFeeArr = []; |
||
286 | if ($this->isNew()) { |
||
287 | $evFeeArr = [[$default0, '', 'placeholder' => \_MA_WGEVENTS_EVENT_FEE_DESC_PH]]; |
||
288 | } else { |
||
289 | $evFee = \json_decode($this->getVar('fee'), true); |
||
290 | foreach($evFee as $fee) { |
||
291 | $evFeeArr[] = [Utility::FloatToString((float)$fee[0]), $fee[1], 'placeholder' => \_MA_WGEVENTS_EVENT_FEE_DESC_PH]; |
||
292 | } |
||
293 | if (0 === \count($evFeeArr)) { |
||
294 | $evFeeArr = [[$default0, '', 'placeholder' => \_MA_WGEVENTS_EVENT_FEE_DESC_PH]]; |
||
295 | } |
||
296 | } |
||
297 | $evFeeTray = new Forms\FormElementTray(\_MA_WGEVENTS_EVENT_FEE, '<br>'); |
||
298 | $evFeeType = $this->isNew() ? Constants::FEETYPE_DECLARED : (int)$this->getVar('fee_type'); |
||
299 | $evFeeTypeRadio = new \XoopsFormRadio('', 'fee_type', $evFeeType); |
||
300 | $evFeeTypeRadio->addOption(Constants::FEETYPE_DECLARED, \_MA_WGEVENTS_EVENT_FEETYPE_DECLARED); |
||
301 | $evFeeTypeRadio->addOption(Constants::FEETYPE_FREE, \_MA_WGEVENTS_EVENT_FEETYPE_FREE); |
||
302 | $evFeeTypeRadio->addOption(Constants::FEETYPE_NONDECL, \_MA_WGEVENTS_EVENT_FEETYPE_NONDECL); |
||
303 | $evFeeTypeRadio->setExtra(" onchange='toggleFeeFields()' "); |
||
304 | $evFeeTray->addElement($evFeeTypeRadio); |
||
305 | $evFeeGroup = new Forms\FormTextDouble('', 'fee', 0, 0, ''); |
||
306 | $evFeeGroup->setElements($evFeeArr); |
||
307 | $evFeeGroup->setPlaceholder1(\_MA_WGEVENTS_EVENT_FEE_VAL_PH); |
||
308 | $evFeeGroup->setPlaceholder2(\_MA_WGEVENTS_EVENT_FEE_DESC_PH); |
||
309 | $evFeeGroup->setVisible(Constants::FEETYPE_DECLARED === $evFeeType); |
||
310 | $evFeeTray->addElement($evFeeGroup); |
||
311 | $form->addElement($evFeeTray); |
||
312 | // Form TextArea evPaymentinfo |
||
313 | $editorConfigs2 = []; |
||
314 | $editorConfigs2['name'] = 'paymentinfo'; |
||
315 | $editorConfigs2['value'] = $this->getVar('paymentinfo', 'e'); |
||
316 | $editorConfigs2['rows'] = 5; |
||
317 | $editorConfigs2['cols'] = 40; |
||
318 | $editorConfigs2['width'] = '100%'; |
||
319 | $editorConfigs2['height'] = '400px'; |
||
320 | $editorConfigs2['editor'] = $editor; |
||
321 | $form->addElement(new \XoopsFormEditor(\_MA_WGEVENTS_EVENT_PAYMENTINFO, 'paymentinfo', $editorConfigs2)); |
||
322 | |||
323 | // Start block registration options |
||
324 | $evRegister_use = $this->isNew() ? 0 : $this->getVar('register_use'); |
||
325 | if ($helper->getConfig('use_register')) { |
||
326 | // Form Radio Yes/No evRegister_use |
||
327 | $evRegisterUseRadio = new \XoopsFormRadioYN(\_MA_WGEVENTS_EVENT_REGISTER_USE, 'register_use', $evRegister_use); |
||
328 | $evRegisterUseRadio->setExtra(" onclick='toggleRegistrationOpts()' "); |
||
329 | $form->addElement($evRegisterUseRadio); |
||
330 | $evReservUseTray = new \XoopsFormElementTray('', '<br>'); //double element tray is necessary for proper toggle |
||
331 | $evRegisterOptsTray = new Forms\FormElementTray('', '<br>', 'registeropttray'); |
||
332 | $evRegisterOptsTray->setClass('col-xs-12 col-sm-5 col-lg-5'); |
||
333 | if (!$evRegister_use) { |
||
334 | $evRegisterOptsTray->setHidden(); |
||
335 | } |
||
336 | // Form Text Date Select evRegisterfrom |
||
337 | $evRegisterfrom = $this->isNew() ? \time() : $this->getVar('register_from'); |
||
338 | $evRegisterOptsTray->addElement(new \XoopsFormDateTime(\_MA_WGEVENTS_EVENT_REGISTER_FROM, 'register_from', '', $evRegisterfrom)); |
||
339 | // Form Text Date Select evRegisterto |
||
340 | $evRegisterto = $this->isNew() ? \time() : $this->getVar('register_to'); |
||
341 | $evRegisterOptsTray->addElement(new \XoopsFormDateTime(\_MA_WGEVENTS_EVENT_REGISTER_TO, 'register_to', '', $evRegisterto)); |
||
342 | // Form Text evRegisterMax |
||
343 | $evRegisterMax = $this->isNew() ? 0 : $this->getVar('register_max'); |
||
344 | $captionRegisterMax = \_MA_WGEVENTS_EVENT_REGISTER_MAX . \sprintf($imgInfo, \_MA_WGEVENTS_EVENT_REGISTER_MAX_DESC); |
||
345 | $evRegisterOptsTray->addElement(new \XoopsFormText($captionRegisterMax, 'register_max', 5, 50, $evRegisterMax)); |
||
346 | // Form Radio Yes/No evRegisterListwait |
||
347 | $evRegisterListwait = $this->isNew() ? 0 : $this->getVar('register_listwait'); |
||
348 | $captionRegisterListwait = \_MA_WGEVENTS_EVENT_REGISTER_LISTWAIT . \sprintf($imgInfo, \_MA_WGEVENTS_EVENT_REGISTER_LISTWAIT_DESC); |
||
349 | $evRegisterOptsTray->addElement(new \XoopsFormRadioYN($captionRegisterListwait, 'register_listwait', $evRegisterListwait)); |
||
350 | // Form Select User evRegisterAutoaccept |
||
351 | $evRegisterAutoaccept = $this->isNew() ? 0 : $this->getVar('register_autoaccept'); |
||
352 | $captionRegisterAutoaccept = \_MA_WGEVENTS_EVENT_REGISTER_AUTOACCEPT . \sprintf($imgInfo, \_MA_WGEVENTS_EVENT_REGISTER_AUTOACCEPT_DESC); |
||
353 | $evRegisterOptsTray->addElement(new \XoopsFormRadioYN($captionRegisterAutoaccept, 'register_autoaccept', $evRegisterAutoaccept)); |
||
354 | // Form Editor TextArea evRegisterNotify |
||
355 | $evRegisterNotify = $this->isNew() ? $userEmail : $this->getVar('register_notify', 'e'); |
||
356 | $captionRegisterNotify = \_MA_WGEVENTS_EVENT_REGISTER_NOTIFY . \sprintf($imgInfo, \_MA_WGEVENTS_EVENT_REGISTER_NOTIFY_DESC); |
||
357 | $evRegisterOptsTray->addElement(new \XoopsFormTextArea($captionRegisterNotify, 'register_notify', $evRegisterNotify, 4, 30)); |
||
358 | // Form Text evRegisterSendermail |
||
359 | $evRegisterSendermail = $this->isNew() ? $userEmail : $this->getVar('register_sendermail'); |
||
360 | $captionRegisterSendermail = \_MA_WGEVENTS_EVENT_REGISTER_SENDERMAIL . \sprintf($imgInfo, \_MA_WGEVENTS_EVENT_REGISTER_SENDERMAIL_DESC); |
||
361 | $evRegisterOptsTray->addElement(new \XoopsFormText($captionRegisterSendermail, 'register_sendermail', 35, 255, $evRegisterSendermail)); |
||
362 | // Form Text evRegisterSendername |
||
363 | $evRegisterSendername = $this->isNew() ? $userName : $this->getVar('register_sendername'); |
||
364 | $captionRegisterSendername = \_MA_WGEVENTS_EVENT_REGISTER_SENDERNAME . \sprintf($imgInfo, \_MA_WGEVENTS_EVENT_REGISTER_SENDERNAME_DESC); |
||
365 | $evRegisterOptsTray->addElement(new \XoopsFormText($captionRegisterSendername, 'register_sendername', 35, 255, $evRegisterSendername)); |
||
366 | // Form Editor TextArea evRegisterSignature |
||
367 | $evRegisterSignature = $this->isNew() ? '' : $this->getVar('register_signature', 'e'); |
||
368 | $captionRegisterSignature = \_MA_WGEVENTS_EVENT_REGISTER_SIGNATURE . \sprintf($imgInfo, \_MA_WGEVENTS_EVENT_REGISTER_SIGNATURE_DESC); |
||
369 | $evRegisterOptsTray->addElement(new \XoopsFormTextArea($captionRegisterSignature, 'register_signature', $evRegisterSignature, 4, 30)); |
||
370 | // Form Radio Yes/No evRegisterListwait |
||
371 | $evRegisterForceverif = $this->isNew() ? 1 : $this->getVar('register_forceverif'); |
||
372 | $captionRegisterForceverif = \_MA_WGEVENTS_EVENT_REGISTER_FORCEVERIF . \sprintf($imgInfo, \_MA_WGEVENTS_EVENT_REGISTER_FORCEVERIF_DESC); |
||
373 | $evRegisterOptsTray->addElement(new \XoopsFormRadioYN($captionRegisterForceverif, 'register_forceverif', $evRegisterForceverif)); |
||
374 | |||
375 | $evReservUseTray->addElement($evRegisterOptsTray); |
||
376 | $form->addElement($evReservUseTray); |
||
377 | //$form->addElement(new \XoopsFormLabel('', $evReservUseTray)); |
||
378 | // End block registration options |
||
379 | } |
||
380 | if ($helper->getConfig('use_urlregistration')) { |
||
381 | // Form Text urlRegistration |
||
382 | $evUrlregistration = $this->getVar('url_registration'); |
||
383 | $evUrlregText = new Forms\FormText(\_MA_WGEVENTS_EVENT_URL_REGISTRATION, 'url_registration', 50, 255, $evUrlregistration); |
||
384 | $evUrlregText->setPlaceholder(\_MA_WGEVENTS_EVENT_URL_REGISTRATION_PH); |
||
385 | if ($evRegister_use) { |
||
386 | $evUrlregText->setExtra('disabled'); |
||
387 | } |
||
388 | $form->addElement($evUrlregText); |
||
389 | } |
||
390 | // Form Select evGalid |
||
391 | if ($helper->getConfig('use_wggallery') && \class_exists('WggalleryCorePreload')) { |
||
392 | $helperGallery = \XoopsModules\Wggallery\Helper::getInstance(); |
||
393 | $albumsHandler = $helperGallery->getHandler('Albums'); |
||
394 | $evGalidSelect = new \XoopsFormSelect(\_MA_WGEVENTS_EVENT_GALID, 'galid', $this->getVar('galid')); |
||
395 | $evGalidSelect->addOption(0, ' '); |
||
396 | $evGalidSelect->addOptionArray($albumsHandler->getList()); |
||
397 | $form->addElement($evGalidSelect); |
||
398 | } |
||
399 | // Form Select evGroups |
||
400 | if ($helper->getConfig('use_groups')) { |
||
401 | if ($this->isNew()) { |
||
402 | $groups = ['00000']; |
||
403 | } else { |
||
404 | $groups = \explode('|', $this->getVar('groups')); |
||
405 | } |
||
406 | $evGroupsSelect = new \XoopsFormSelect(\_MA_WGEVENTS_EVENT_GROUPS, 'groups', $groups, 5, true); |
||
407 | $evGroupsSelect->addOption('00000', \_MA_WGEVENTS_EVENT_GROUPS_ALL); |
||
408 | // Get groups |
||
409 | $memberHandler = \xoops_getHandler('member'); |
||
410 | $xoopsGroups = $memberHandler->getGroupList(); |
||
411 | foreach ($xoopsGroups as $key => $group) { |
||
412 | if (3 !== (int)$key) { |
||
413 | $evGroupsSelect->addOption(substr('00000' . $key, -5), $group); |
||
414 | } |
||
415 | } |
||
416 | $form->addElement($evGroupsSelect, true); |
||
417 | } else { |
||
418 | $form->addElement(new \XoopsFormHidden('groups', '00000')); |
||
419 | } |
||
420 | // Form Select Status evStatus |
||
421 | // Form Text Date Select evDatecreated |
||
422 | // Form Select User evSubmitter |
||
423 | $permEventsApprove = $permissionsHandler->getPermEventsApprove(); |
||
424 | $permEventsApproveAuto = $permissionsHandler->getPermEventsApproveAuto(); |
||
425 | if ($this->isNew()) { |
||
426 | $evStatus = $permEventsApproveAuto ? Constants::STATUS_APPROVED : Constants::STATUS_SUBMITTED; |
||
427 | } else { |
||
428 | $evStatus = $this->getVar('status'); |
||
429 | } |
||
430 | $evDatecreated = $this->isNew() ? \time() : (int)$this->getVar('datecreated'); |
||
431 | $evSubmitter = $this->isNew() ? $userUid : (int)$this->getVar('submitter'); |
||
432 | if ($isAdmin) { |
||
433 | $evStatusSelect = new \XoopsFormSelect(\_MA_WGEVENTS_STATUS, 'status', $evStatus); |
||
434 | $evStatusSelect->addOption(Constants::STATUS_NONE, \_MA_WGEVENTS_STATUS_NONE); |
||
435 | $evStatusSelect->addOption(Constants::STATUS_OFFLINE, \_MA_WGEVENTS_STATUS_OFFLINE); |
||
436 | $evStatusSelect->addOption(Constants::STATUS_SUBMITTED, \_MA_WGEVENTS_STATUS_SUBMITTED); |
||
437 | $evStatusSelect->addOption(Constants::STATUS_APPROVED, \_MA_WGEVENTS_STATUS_APPROVED); |
||
438 | $evStatusSelect->addOption(Constants::STATUS_LOCKED, \_MA_WGEVENTS_STATUS_LOCKED); |
||
439 | $evStatusSelect->addOption(Constants::STATUS_CANCELED, \_MA_WGEVENTS_STATUS_CANCELED); |
||
440 | $form->addElement($evStatusSelect, true); |
||
441 | $form->addElement(new \XoopsFormTextDateSelect(\_MA_WGEVENTS_DATECREATED, 'datecreated', '', $evDatecreated)); |
||
442 | $form->addElement(new \XoopsFormSelectUser(\_MA_WGEVENTS_SUBMITTER, 'submitter', false, $evSubmitter)); |
||
443 | } else { |
||
444 | $form->addElement(new \XoopsFormHidden('status', $evStatus)); |
||
445 | $form->addElement(new \XoopsFormHidden('datecreated_int', $evDatecreated)); |
||
446 | $form->addElement(new \XoopsFormHidden('submitter', $evSubmitter)); |
||
447 | if (!$this->isNew() && $permEventsApprove) { |
||
448 | $evStatusSelect = new \XoopsFormSelect(\_MA_WGEVENTS_STATUS, 'status', $evStatus); |
||
449 | $evStatusSelect->addOption(Constants::STATUS_NONE, \_MA_WGEVENTS_STATUS_NONE); |
||
450 | $evStatusSelect->addOption(Constants::STATUS_OFFLINE, \_MA_WGEVENTS_STATUS_OFFLINE); |
||
451 | $evStatusSelect->addOption(Constants::STATUS_SUBMITTED, \_MA_WGEVENTS_STATUS_SUBMITTED); |
||
452 | $evStatusSelect->addOption(Constants::STATUS_APPROVED, \_MA_WGEVENTS_STATUS_APPROVED); |
||
453 | $form->addElement($evStatusSelect, true); |
||
454 | $form->addElement(new \XoopsFormLabel(\_MA_WGEVENTS_DATECREATED, \formatTimestamp($evDatecreated, 's'))); |
||
455 | $form->addElement(new \XoopsFormLabel(\_MA_WGEVENTS_SUBMITTER, \XoopsUser::getUnameFromId($evSubmitter))); |
||
456 | } |
||
457 | } |
||
458 | if ($this->idSource > 0 && $helper->getConfig('use_register')) { |
||
459 | $form->addElement(new \XoopsFormRadioYN(\_MA_WGEVENTS_EVENT_CLONE_QUESTION, 'clone_question', 1)); |
||
460 | $form->addElement(new \XoopsFormHidden('id_source', $this->idSource)); |
||
461 | } |
||
462 | if (!$this->isNew() && 0 === $this->idSource) { |
||
463 | $informModif = new \XoopsFormRadioYN(\_MA_WGEVENTS_EVENT_INFORM_MODIF, 'informModif', 0); |
||
464 | $informModif->setDescription(\_MA_WGEVENTS_EVENT_INFORM_MODIF_DESC); |
||
465 | $form->addElement($informModif); |
||
466 | } |
||
467 | // To Save |
||
468 | $form->addElement(new \XoopsFormHidden('op', 'save')); |
||
469 | $form->addElement(new \XoopsFormHidden('start', $this->start)); |
||
470 | $form->addElement(new \XoopsFormHidden('limit', $this->limit)); |
||
471 | $form->addElement(new \XoopsFormHidden('cats', $this->cats)); |
||
472 | // button tray |
||
473 | $buttonTray = new \XoopsFormElementTray(''); |
||
474 | $buttonBack = new Forms\FormButton('', 'confirm_back', \_CANCEL, 'button'); |
||
475 | $buttonBack->setExtra('onclick="history.go(-1);return true;"'); |
||
476 | $buttonBack->setClass('btn-danger'); |
||
477 | $buttonTray->addElement($buttonBack); |
||
478 | |||
479 | $buttonReset = new Forms\FormButton('', 'reset', \_RESET, 'reset'); |
||
480 | $buttonReset->setClass('btn-warning'); |
||
481 | $buttonTray->addElement($buttonReset); |
||
482 | |||
483 | $buttonSubmit = new Forms\FormButton('', '_submit', \_MA_WGEVENTS_SAVE, 'submit'); |
||
484 | $buttonSubmit->setClass('btn-primary'); |
||
485 | $buttonTray->addElement($buttonSubmit); |
||
486 | |||
487 | $buttonNext = new Forms\FormButton('', 'continue_questions', \_MA_WGEVENTS_CONTINUE_QUESTIONY, 'submit'); |
||
488 | $buttonNext->setClass('btn-primary'); |
||
489 | if (!$evRegister_use) { |
||
490 | $buttonNext->setHidden(); |
||
491 | } |
||
492 | $buttonTray->addElement($buttonNext); |
||
493 | $form->addElement($buttonTray); |
||
494 | |||
495 | return $form; |
||
496 | } |
||
497 | |||
498 | /** |
||
499 | * @public function getFormContactAll |
||
500 | * @param string $mailFrom |
||
501 | * @param string $mailSubject |
||
502 | * @param string $mailBody |
||
503 | * @param int $mailCopy |
||
504 | * @param bool $action |
||
505 | * @return \XoopsThemeForm |
||
506 | */ |
||
507 | public function getFormContactAll($mailFrom, $mailSubject, $mailBody = '', $mailCopy = 1, $action = false) |
||
508 | { |
||
509 | $helper = \XoopsModules\Wgevents\Helper::getInstance(); |
||
510 | $registrationHandler = $helper->getHandler('Registration'); |
||
511 | if (!$action) { |
||
512 | $action = $_SERVER['REQUEST_URI']; |
||
513 | } |
||
514 | // Get Theme Form |
||
515 | \xoops_load('XoopsFormLoader'); |
||
516 | $form = new \XoopsThemeForm(\_MA_WGEVENTS_CONTACT_ALL, 'formContactAll', $action, 'post', true); |
||
517 | $form->setExtra('enctype="multipart/form-data"'); |
||
518 | // Form Text mailFrom |
||
519 | $emailTray = new Forms\FormElementTray(\_MA_WGEVENTS_CONTACT_MAILFROM, '<br>'); |
||
520 | $email = new Forms\FormText('', 'mail_from', 50, 255, $mailFrom); |
||
521 | $email->setPlaceholder(\_MA_WGEVENTS_REGISTRATION_EMAIL_PLACEHOLDER); |
||
522 | $emailTray->addElement($email, true); |
||
523 | // Form select mailCopy |
||
524 | $emailRadio = new \XoopsFormRadioYN(\_MA_WGEVENTS_CONTACT_MAILCOPY, 'mail_copy', $mailCopy); |
||
525 | $emailTray->addElement($emailRadio); |
||
526 | $form->addElement($emailTray); |
||
527 | // Form Editor TextArea mailTo |
||
528 | $crRegistration = new \CriteriaCompo(); |
||
529 | $crRegistration->add(new \Criteria('evid', $this->getVar('id'))); |
||
530 | $numberRegCurr = $registrationHandler->getCount($crRegistration); |
||
531 | $mailToArr = []; |
||
532 | $mailTo = ''; |
||
533 | if ($numberRegCurr > 0) { |
||
534 | $registrationsAll = $registrationHandler->getAll($crRegistration); |
||
535 | foreach (\array_keys($registrationsAll) as $i) { |
||
536 | $mailToArr[$registrationsAll[$i]->getVar('email')] = $registrationsAll[$i]->getVar('email'); |
||
537 | } |
||
538 | } |
||
539 | foreach ($mailToArr as $mail) { |
||
540 | $mailTo .= $mail . PHP_EOL; |
||
541 | } |
||
542 | $mailToTextarea = new \XoopsFormTextArea(\_MA_WGEVENTS_CONTACT_MAILTO, 'mail_to', $mailTo, 5, 47); |
||
543 | $mailToTextarea->setExtra(" disabled='disabled'"); |
||
544 | $form->addElement($mailToTextarea); |
||
545 | // From Text Subject |
||
546 | $subject = \sprintf(\_MA_WGEVENTS_CONTACT_ALL_MAILSUBJECT_TEXT, $mailSubject); |
||
547 | $form->addElement(new \XoopsFormText(\_MA_WGEVENTS_CONTACT_MAILSUBJECT, 'mail_subject', 50, 255, $subject), true); |
||
548 | // Form Editor DhtmlTextArea mailBody |
||
549 | $editorConfigs = []; |
||
550 | $editor = $helper->getConfig('editor_user'); |
||
551 | $editorConfigs['name'] = 'mail_body'; |
||
552 | $editorConfigs['value'] = $mailBody; |
||
553 | $editorConfigs['rows'] = 10; |
||
554 | $editorConfigs['cols'] = 40; |
||
555 | $editorConfigs['width'] = '100%'; |
||
556 | $editorConfigs['height'] = '400px'; |
||
557 | $editorConfigs['editor'] = $editor; |
||
558 | $form->addElement(new \XoopsFormEditor(\_MA_WGEVENTS_CONTACT_MAILBODY, 'mail_body', $editorConfigs)); |
||
559 | // To Save |
||
560 | $form->addElement(new \XoopsFormHidden('evid', $this->getVar('id'))); |
||
561 | $form->addElement(new \XoopsFormHidden('op', 'exec_contactall')); |
||
562 | $form->addElement(new \XoopsFormButtonTray('', \_MA_WGEVENTS_SEND_ALL, 'submit', '', false)); |
||
563 | $form->addElement(new \XoopsFormButton(\_MA_WGEVENTS_CONTACT_ALL_TEST, 'exec_contactall_test', \sprintf(\_MA_WGEVENTS_CONTACT_ALL_TEST_BTN , $mailFrom), 'submit')); |
||
564 | return $form; |
||
565 | } |
||
566 | |||
567 | /** |
||
568 | * Get Values |
||
569 | * @param null $keys |
||
570 | * @param null $format |
||
571 | * @param null $maxDepth |
||
572 | * @return array |
||
573 | */ |
||
574 | public function getValuesEvents($keys = null, $format = null, $maxDepth = null) |
||
736 | } |
||
737 | |||
738 | /** function to get day name |
||
739 | * @param $eventDayname (= module preference 'event_dayname') |
||
740 | * @param $day (= weekday of date) |
||
741 | * @return string |
||
742 | */ |
||
743 | private function getDayname ($eventDayname, $day) { |
||
787 |
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: