1
|
|
|
<?php declare(strict_types=1); |
2
|
|
|
|
3
|
|
|
namespace XoopsModules\Xhelp; |
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
|
|
|
* @copyright {@link https://xoops.org/ XOOPS Project} |
17
|
|
|
* @license {@link https://www.gnu.org/licenses/gpl-2.0.html GNU GPL 2 or later} |
18
|
|
|
* @author Brian Wahoff <[email protected]> |
19
|
|
|
* @author XOOPS Development Team |
20
|
|
|
*/ |
21
|
|
|
|
22
|
|
|
if (!\defined('XHELP_CONSTANTS_INCLUDED')) { |
23
|
|
|
exit(); |
24
|
|
|
} |
25
|
|
|
|
26
|
|
|
// require_once XHELP_CLASS_PATH . '/BaseObjectHandler.php'; |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* Xhelp\TicketField class |
30
|
|
|
* |
31
|
|
|
* Metadata that represents a custom field created for xhelp |
32
|
|
|
* |
33
|
|
|
* @author Brian Wahoff <[email protected]> |
34
|
|
|
*/ |
35
|
|
|
class TicketField extends \XoopsObject |
36
|
|
|
{ |
37
|
|
|
public $departments = []; |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* Class Constructor |
41
|
|
|
* |
42
|
|
|
* @param int|array|null $id null for a new object, hash table for an existing object |
43
|
|
|
*/ |
44
|
|
|
public function __construct($id = null) |
45
|
|
|
{ |
46
|
|
|
$this->initVar('id', \XOBJ_DTYPE_INT, null, false); |
47
|
|
|
$this->initVar('name', \XOBJ_DTYPE_TXTBOX, null, true, 64); |
48
|
|
|
$this->initVar('description', \XOBJ_DTYPE_TXTBOX, '', false, 255); |
49
|
|
|
$this->initVar('fieldname', \XOBJ_DTYPE_TXTBOX, null, true, 64); |
50
|
|
|
$this->initVar('controltype', \XOBJ_DTYPE_INT, \XHELP_CONTROL_TXTBOX, true); |
51
|
|
|
$this->initVar('datatype', \XOBJ_DTYPE_TXTBOX, null, true, 64); |
52
|
|
|
$this->initVar('required', \XOBJ_DTYPE_INT, false, true); |
53
|
|
|
$this->initVar('fieldlength', \XOBJ_DTYPE_INT, 255, true); |
54
|
|
|
$this->initVar('weight', \XOBJ_DTYPE_INT, 0, true); |
55
|
|
|
$this->initVar('fieldvalues', \XOBJ_DTYPE_ARRAY, null, false); |
56
|
|
|
$this->initVar('defaultvalue', \XOBJ_DTYPE_TXTBOX, null, false, 100); |
57
|
|
|
$this->initVar('validation', \XOBJ_DTYPE_TXTBOX, null, false); |
58
|
|
|
|
59
|
|
|
if (null !== $id) { |
60
|
|
|
if (\is_array($id)) { |
61
|
|
|
$this->assignVars($id); |
62
|
|
|
} |
63
|
|
|
} else { |
64
|
|
|
$this->setNew(); |
65
|
|
|
} |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
/** |
69
|
|
|
* Get the array of possible values for this custom field |
70
|
|
|
* @param null $keys |
|
|
|
|
71
|
|
|
* @param string $format |
72
|
|
|
* @param int $maxDepth |
73
|
|
|
*/ |
74
|
|
|
public function getValues($keys = null, $format = 's', $maxDepth = 1) |
75
|
|
|
{ |
76
|
|
|
$this->getVar('fieldvalues'); |
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
/** |
80
|
|
|
* @param Validation\Validator $validator |
81
|
|
|
*/ |
82
|
|
|
public function addValidator(Validation\Validator $validator): void |
|
|
|
|
83
|
|
|
{ |
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
/** |
87
|
|
|
* @param array $val_arr |
88
|
|
|
*/ |
89
|
|
|
public function setValues(array $val_arr): void |
90
|
|
|
{ |
91
|
|
|
$this->setVar('fieldvalues', $val_arr); |
92
|
|
|
} |
93
|
|
|
|
94
|
|
|
/** |
95
|
|
|
* @param array $val_arr |
96
|
|
|
*/ |
97
|
|
|
public function addValues(array $val_arr): void |
98
|
|
|
{ |
99
|
|
|
if (\is_array($val_arr)) { |
|
|
|
|
100
|
|
|
$values = @$this->getVar('fieldvalues'); |
101
|
|
|
if (!\is_array($values)) { |
102
|
|
|
$values = []; |
103
|
|
|
} |
104
|
|
|
foreach ($val_arr as $value => $desc) { |
105
|
|
|
$values[$value] = $desc; |
106
|
|
|
} |
107
|
|
|
$this->setVar('fieldvalues', $values); |
108
|
|
|
} |
109
|
|
|
} |
110
|
|
|
|
111
|
|
|
/** |
112
|
|
|
* @param string $desc |
113
|
|
|
* @param null $value |
|
|
|
|
114
|
|
|
*/ |
115
|
|
|
public function addValue(string $desc, $value = null): void |
116
|
|
|
{ |
117
|
|
|
//Add value to array |
118
|
|
|
$values = $this->getVar('fieldvalues'); |
119
|
|
|
$values[$desc] = $value; |
120
|
|
|
$this->setVar('fieldvalues', $values); |
121
|
|
|
} |
122
|
|
|
|
123
|
|
|
/** |
124
|
|
|
* @param int $dept |
125
|
|
|
*/ |
126
|
|
|
public function addDepartment(int $dept): void |
127
|
|
|
{ |
128
|
|
|
$dept = $dept; |
129
|
|
|
$this->departments[$dept] = $dept; |
130
|
|
|
} |
131
|
|
|
|
132
|
|
|
/** |
133
|
|
|
* @param array $dept_arr |
134
|
|
|
* @return bool |
135
|
|
|
*/ |
136
|
|
|
public function addDepartments(array $dept_arr): ?bool |
137
|
|
|
{ |
138
|
|
|
if (!\is_array($dept_arr) || 0 == \count($dept_arr)) { |
|
|
|
|
139
|
|
|
return false; |
140
|
|
|
} |
141
|
|
|
foreach ($dept_arr as $dept) { |
142
|
|
|
$dept = (int)$dept; |
143
|
|
|
$this->departments[$dept] = $dept; |
144
|
|
|
} |
145
|
|
|
return true; |
146
|
|
|
} |
147
|
|
|
|
148
|
|
|
/** |
149
|
|
|
* @param int $dept |
150
|
|
|
*/ |
151
|
|
|
public function removeDepartment(int $dept): void |
152
|
|
|
{ |
153
|
|
|
$dept = $dept; |
154
|
|
|
$this->departments[$dept] = 0; |
155
|
|
|
} |
156
|
|
|
|
157
|
|
|
/** |
158
|
|
|
* @return array |
159
|
|
|
*/ |
160
|
|
|
public function &getDepartments(): array |
161
|
|
|
{ |
162
|
|
|
return $this->departments; |
163
|
|
|
} |
164
|
|
|
|
165
|
|
|
/** |
166
|
|
|
* @return array |
167
|
|
|
*/ |
168
|
|
|
public function toArray(): array |
169
|
|
|
{ |
170
|
|
|
$arr = []; |
|
|
|
|
171
|
|
|
|
172
|
|
|
$values = $this->getVar('fieldvalues'); |
173
|
|
|
if (\XHELP_CONTROL_YESNO == $this->getVar('controltype')) { |
174
|
|
|
$values = [1 => _YES, 0 => _NO]; |
175
|
|
|
} |
176
|
|
|
|
177
|
|
|
$aValues = []; |
178
|
|
|
foreach ($values as $key => $value) { |
179
|
|
|
$aValues[] = [$key, $value]; |
180
|
|
|
} |
181
|
|
|
|
182
|
|
|
$arr = [ |
183
|
|
|
'id' => $this->getVar('id'), |
184
|
|
|
'name' => $this->getVar('name'), |
185
|
|
|
'desc' => $this->getVar('description'), |
186
|
|
|
'fieldname' => $this->getVar('fieldname'), |
187
|
|
|
'defaultvalue' => $this->getVar('defaultvalue'), |
188
|
|
|
'currentvalue' => '', |
189
|
|
|
'controltype' => $this->getVar('controltype'), |
190
|
|
|
'required' => $this->getVar('required'), |
191
|
|
|
'fieldlength' => $this->getVar('fieldlength'), |
192
|
|
|
'weight' => $this->getVar('weight'), |
193
|
|
|
'fieldvalues' => $aValues, |
194
|
|
|
'datatype' => $this->getVar('datatype'), |
195
|
|
|
'validation' => $this->getVar('validation'), |
196
|
|
|
]; |
197
|
|
|
|
198
|
|
|
return $arr; |
199
|
|
|
} |
200
|
|
|
} |
201
|
|
|
|