1
|
|
|
<?php declare(strict_types=1); |
2
|
|
|
|
3
|
|
|
namespace XoopsModules\Wgevents; |
4
|
|
|
|
5
|
|
|
/* |
6
|
|
|
You may not change or alter any portion of this comment or credits |
7
|
|
|
of supporting developers from this source code or any supporting source code |
8
|
|
|
which is considered copyrighted (c) material of the original comment or credit authors. |
9
|
|
|
|
10
|
|
|
This program is distributed in the hope that it will be useful, |
11
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of |
12
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
13
|
|
|
*/ |
14
|
|
|
|
15
|
|
|
/** |
16
|
|
|
* wgEvents module for xoops |
17
|
|
|
* |
18
|
|
|
* @copyright 2021 XOOPS Project (https://xoops.org) |
19
|
|
|
* @license GPL 2.0 or later |
20
|
|
|
* @package wgevents |
21
|
|
|
* @since 1.0.0 |
22
|
|
|
* @min_xoops 2.5.11 Beta1 |
23
|
|
|
* @author Goffy - Wedega - Email:[email protected] - Website:https://xoops.wedega.com |
24
|
|
|
*/ |
25
|
|
|
|
26
|
|
|
use XoopsModules\Wgevents; |
27
|
|
|
use XoopsModules\Wgevents\{ |
28
|
|
|
Forms, |
29
|
|
|
Utility |
|
|
|
|
30
|
|
|
}; |
31
|
|
|
|
32
|
|
|
\defined('XOOPS_ROOT_PATH') || die('Restricted access'); |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* Class Object Field |
36
|
|
|
*/ |
37
|
|
|
class Field extends \XoopsObject |
38
|
|
|
{ |
39
|
|
|
/** |
40
|
|
|
* @var int |
41
|
|
|
*/ |
42
|
|
|
public $start = 0; |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* @var int |
46
|
|
|
*/ |
47
|
|
|
public $limit = 0; |
48
|
|
|
|
49
|
|
|
/** |
50
|
|
|
* Constructor |
51
|
|
|
* |
52
|
|
|
*/ |
53
|
|
|
public function __construct() |
54
|
|
|
{ |
55
|
|
|
$this->initVar('id', \XOBJ_DTYPE_INT); |
56
|
|
|
$this->initVar('caption', \XOBJ_DTYPE_TXTBOX); |
57
|
|
|
$this->initVar('type', \XOBJ_DTYPE_INT); |
58
|
|
|
$this->initVar('desc', \XOBJ_DTYPE_OTHER); |
59
|
|
|
$this->initVar('values', \XOBJ_DTYPE_OTHER); |
60
|
|
|
$this->initVar('placeholder', \XOBJ_DTYPE_TXTBOX); |
61
|
|
|
$this->initVar('required', \XOBJ_DTYPE_INT); |
62
|
|
|
$this->initVar('default', \XOBJ_DTYPE_INT); |
63
|
|
|
$this->initVar('print', \XOBJ_DTYPE_INT); |
64
|
|
|
$this->initVar('display_desc', \XOBJ_DTYPE_INT); |
65
|
|
|
$this->initVar('display_values', \XOBJ_DTYPE_INT); |
66
|
|
|
$this->initVar('display_placeholder', \XOBJ_DTYPE_INT); |
67
|
|
|
$this->initVar('weight', \XOBJ_DTYPE_INT); |
68
|
|
|
$this->initVar('custom', \XOBJ_DTYPE_INT); |
69
|
|
|
$this->initVar('status', \XOBJ_DTYPE_INT); |
70
|
|
|
$this->initVar('datecreated', \XOBJ_DTYPE_INT); |
71
|
|
|
$this->initVar('submitter', \XOBJ_DTYPE_INT); |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
/** |
75
|
|
|
* @static function &getInstance |
76
|
|
|
* |
77
|
|
|
*/ |
78
|
|
|
public static function getInstance() |
79
|
|
|
{ |
80
|
|
|
static $instance = false; |
81
|
|
|
if (!$instance) { |
82
|
|
|
$instance = new self(); |
83
|
|
|
} |
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
/** |
87
|
|
|
* The new inserted $Id |
88
|
|
|
* @return inserted id |
|
|
|
|
89
|
|
|
*/ |
90
|
|
|
public function getNewInsertedId() |
91
|
|
|
{ |
92
|
|
|
return $GLOBALS['xoopsDB']->getInsertId(); |
93
|
|
|
} |
94
|
|
|
|
95
|
|
|
/** |
96
|
|
|
* @public function getForm |
97
|
|
|
* @param bool $action |
98
|
|
|
* @return \XoopsThemeForm |
99
|
|
|
*/ |
100
|
|
|
public function getForm($action = false) |
101
|
|
|
{ |
102
|
|
|
$helper = \XoopsModules\Wgevents\Helper::getInstance(); |
103
|
|
|
|
104
|
|
|
$fieldHandler = $helper->getHandler('Field'); |
105
|
|
|
|
106
|
|
|
if (!$action) { |
107
|
|
|
$action = $_SERVER['REQUEST_URI']; |
108
|
|
|
} |
109
|
|
|
$isAdmin = (\is_object($GLOBALS['xoopsUser']) && \is_object($GLOBALS['xoopsModule'])) ? $GLOBALS['xoopsUser']->isAdmin($GLOBALS['xoopsModule']->mid()) : false; |
|
|
|
|
110
|
|
|
// Title |
111
|
|
|
$title = $this->isNew() ? \_AM_WGEVENTS_FIELD_ADD : \_AM_WGEVENTS_FIELD_EDIT; |
112
|
|
|
// Get Theme Form |
113
|
|
|
\xoops_load('XoopsFormLoader'); |
114
|
|
|
$form = new \XoopsThemeForm($title, 'form', $action, 'post', true); |
115
|
|
|
$form->setExtra('enctype="multipart/form-data"'); |
116
|
|
|
// Form Text fdCaption |
117
|
|
|
$form->addElement(new \XoopsFormText(\_AM_WGEVENTS_FIELD_CAPTION, 'caption', 50, 255, $this->getVar('caption')), true); |
|
|
|
|
118
|
|
|
// Form Editor TextArea fdDesc |
119
|
|
|
$form->addElement(new \XoopsFormTextArea(\_AM_WGEVENTS_FIELD_DESC, 'desc', $this->getVar('desc', 'e'), 10, 47)); |
|
|
|
|
120
|
|
|
// Form Select fdType |
121
|
|
|
$formelementsHandler = new Forms\FormelementsHandler(); |
122
|
|
|
$atTypeSelect = new \XoopsFormSelect(\_AM_WGEVENTS_FIELD_TYPE, 'type', $this->getVar('type'), 5); |
123
|
|
|
$atTypeSelect->addOptionArray($formelementsHandler->getElementsCollection()); |
124
|
|
|
$form->addElement($atTypeSelect); |
125
|
|
|
// Form Editor TextArea fdValues |
126
|
|
|
$atValuesText = ''; |
127
|
|
|
if (!$this->isNew()) { |
128
|
|
|
$fdValues = (string)$this->getVar('values'); |
129
|
|
|
if ('' !== $fdValues) { |
130
|
|
|
$atValuesText = \implode("\n", \unserialize($fdValues, ['allowed_classes' => false])); |
131
|
|
|
} |
132
|
|
|
} |
133
|
|
|
$form->addElement(new \XoopsFormTextArea(\_AM_WGEVENTS_FIELD_VALUE, 'values', $atValuesText, 5, 47)); |
134
|
|
|
// Form Text fdPlaceholder |
135
|
|
|
$form->addElement(new \XoopsFormText(\_AM_WGEVENTS_FIELD_PLACEHOLDER, 'placeholder', 50, 255, $this->getVar('placeholder'))); |
136
|
|
|
// Form Radio Yes/No fdRequired |
137
|
|
|
$fdRequired = $this->isNew() ? 0 : $this->getVar('required'); |
138
|
|
|
$form->addElement(new \XoopsFormRadioYN(\_AM_WGEVENTS_FIELD_REQUIRED, 'required', $fdRequired)); |
|
|
|
|
139
|
|
|
// Form Radio Yes/No fdDefault |
140
|
|
|
$fdDefault = $this->isNew() ? 0 : $this->getVar('default'); |
141
|
|
|
$form->addElement(new \XoopsFormRadioYN(\_AM_WGEVENTS_FIELD_DEFAULT, 'default', $fdDefault)); |
142
|
|
|
// Form Radio Yes/No fdPrint |
143
|
|
|
$fdPrint = $this->isNew() ? 0 : $this->getVar('print'); |
144
|
|
|
$form->addElement(new \XoopsFormRadioYN(\_MA_WGEVENTS_PRINT, 'print', $fdPrint)); |
145
|
|
|
// Form Radio Yes/No fdDisplayDesc |
146
|
|
|
$fdDisplayDesc = $this->isNew() ? 1 : $this->getVar('display_desc'); |
147
|
|
|
$form->addElement(new \XoopsFormRadioYN(\_AM_WGEVENTS_FIELD_DISPLAY_DESC, 'display_desc', $fdDisplayDesc)); |
148
|
|
|
// Form Radio Yes/No fdDisplayValues |
149
|
|
|
$fdDisplayValues = $this->isNew() ? 1 : $this->getVar('display_values'); |
150
|
|
|
$form->addElement(new \XoopsFormRadioYN(\_AM_WGEVENTS_FIELD_DISPLAY_VALUES, 'display_values', $fdDisplayValues)); |
151
|
|
|
// Form Radio Yes/No fdDisplayPlaceholder |
152
|
|
|
$fdDisplayPlaceholder = $this->isNew() ? 1 : $this->getVar('display_placeholder'); |
153
|
|
|
$form->addElement(new \XoopsFormRadioYN(\_AM_WGEVENTS_FIELD_DISPLAY_PLACEHOLDER, 'display_placeholder', $fdDisplayPlaceholder)); |
154
|
|
|
// Form Text fdWeight |
155
|
|
|
$fdWeight = $this->isNew() ? $fieldHandler->getNextWeight() : $this->getVar('weight'); |
156
|
|
|
$form->addElement(new \XoopsFormText(\_MA_WGEVENTS_WEIGHT, 'weight', 50, 255, $fdWeight)); |
157
|
|
|
// Form Select Status fdStatus |
158
|
|
|
$fdStatus = $this->isNew() ? Constants::STATUS_OFFLINE : $this->getVar('status'); |
159
|
|
|
$atStatusSelect = new \XoopsFormRadio(\_MA_WGEVENTS_STATUS, 'status', $fdStatus); |
|
|
|
|
160
|
|
|
$atStatusSelect->addOption(Constants::STATUS_OFFLINE, \_MA_WGEVENTS_STATUS_OFFLINE); |
161
|
|
|
$atStatusSelect->addOption(Constants::STATUS_ONLINE, \_MA_WGEVENTS_STATUS_ONLINE); |
162
|
|
|
$form->addElement($atStatusSelect); |
163
|
|
|
// Form Text Date Select fdDatecreated |
164
|
|
|
$fdDatecreated = $this->isNew() ? \time() : $this->getVar('datecreated'); |
165
|
|
|
$form->addElement(new \XoopsFormTextDateSelect(\_MA_WGEVENTS_DATECREATED, 'datecreated', '', $fdDatecreated)); |
|
|
|
|
166
|
|
|
// Form Select User fdSubmitter |
167
|
|
|
$uidCurrent = \is_object($GLOBALS['xoopsUser']) ? $GLOBALS['xoopsUser']->uid() : 0; |
168
|
|
|
$fdSubmitter = $this->isNew() ? $uidCurrent : $this->getVar('submitter'); |
169
|
|
|
$form->addElement(new \XoopsFormSelectUser(\_MA_WGEVENTS_SUBMITTER, 'submitter', false, $fdSubmitter)); |
170
|
|
|
// Form Text fdCustom |
171
|
|
|
$fdCustom = $this->isNew() ? 1 : $this->getVar('custom'); |
172
|
|
|
$form->addElement(new \XoopsFormHidden('custom', $fdCustom)); |
|
|
|
|
173
|
|
|
// To Save |
174
|
|
|
$form->addElement(new \XoopsFormHidden('op', 'save')); |
175
|
|
|
$form->addElement(new \XoopsFormHidden('start', $this->start)); |
176
|
|
|
$form->addElement(new \XoopsFormHidden('limit', $this->limit)); |
177
|
|
|
$form->addElement(new \XoopsFormButtonTray('', \_SUBMIT, 'submit', '', false)); |
178
|
|
|
return $form; |
179
|
|
|
} |
180
|
|
|
|
181
|
|
|
/** |
182
|
|
|
* Get Values |
183
|
|
|
* @param null $keys |
|
|
|
|
184
|
|
|
* @param null $format |
|
|
|
|
185
|
|
|
* @param null $maxDepth |
|
|
|
|
186
|
|
|
* @return array |
187
|
|
|
*/ |
188
|
|
|
public function getValuesFields($keys = null, $format = null, $maxDepth = null) |
189
|
|
|
{ |
190
|
|
|
$helper = \XoopsModules\Wgevents\Helper::getInstance(); |
191
|
|
|
$utility = new \XoopsModules\Wgevents\Utility(); |
|
|
|
|
192
|
|
|
$editorMaxchar = $helper->getConfig('admin_maxchar'); |
|
|
|
|
193
|
|
|
$formelementsHandler = new Forms\FormelementsHandler(); |
194
|
|
|
$fieldsAll = $formelementsHandler->getElementsCollection(); |
195
|
|
|
$ret = $this->getValues($keys, $format, $maxDepth); |
196
|
|
|
$ret['type_text'] = $fieldsAll[$this->getVar('type')]; |
197
|
|
|
$fdValues = $this->getVar('values'); |
198
|
|
|
$ret['value_text'] = ''; |
199
|
|
|
$ret['value_list'] = ''; |
200
|
|
|
if ('' !== $fdValues) { |
201
|
|
|
$ret['value_text'] = \implode("\n", \unserialize($fdValues, ['allowed_classes' => false])); |
202
|
|
|
$ret['value_list'] = \implode('<br>', \unserialize($fdValues, ['allowed_classes' => false])); |
203
|
|
|
} |
204
|
|
|
$ret['required_text'] = (int)$this->getVar('required') > 0 ? _YES : _NO; |
205
|
|
|
$ret['default_text'] = (int)$this->getVar('default') > 0 ? _YES : _NO; |
206
|
|
|
$ret['print_text'] = (int)$this->getVar('print') > 0 ? _YES : _NO; |
207
|
|
|
$ret['display_desc_text'] = (int)$this->getVar('display_desc') > 0 ? _YES : _NO; |
208
|
|
|
$ret['display_values_text'] = (int)$this->getVar('display_values') > 0 ? _YES : _NO; |
209
|
|
|
$ret['display_placeholder_text'] = (int)$this->getVar('display_placeholder') > 0 ? _YES : _NO; |
210
|
|
|
$ret['status_text'] = Utility::getStatusText($this->getVar('status')); |
211
|
|
|
$ret['datecreated_text'] = \formatTimestamp($this->getVar('datecreated'), 's'); |
212
|
|
|
$ret['submitter_text'] = \XoopsUser::getUnameFromId($this->getVar('submitter')); |
213
|
|
|
return $ret; |
214
|
|
|
} |
215
|
|
|
|
216
|
|
|
/** |
217
|
|
|
* Returns an array representation of the object |
218
|
|
|
* |
219
|
|
|
* @return array |
220
|
|
|
*/ |
221
|
|
|
/* |
222
|
|
|
public function toArray() |
223
|
|
|
{ |
224
|
|
|
$ret = []; |
225
|
|
|
$vars = $this->getVars(); |
226
|
|
|
foreach (\array_keys($vars) as $var) { |
227
|
|
|
$ret[$var] = $this->getVar($var); |
228
|
|
|
} |
229
|
|
|
return $ret; |
230
|
|
|
} |
231
|
|
|
*/ |
232
|
|
|
} |
233
|
|
|
|
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: