|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* @license LGPLv3, https://opensource.org/licenses/LGPL-3.0 |
|
5
|
|
|
* @copyright Metaways Infosystems GmbH, 2011 |
|
6
|
|
|
* @copyright Aimeos (aimeos.org), 2015-2024 |
|
7
|
|
|
* @package Base |
|
8
|
|
|
* @subpackage Common |
|
9
|
|
|
*/ |
|
10
|
|
|
|
|
11
|
|
|
|
|
12
|
|
|
namespace Aimeos\Base\Criteria\Attribute; |
|
13
|
|
|
|
|
14
|
|
|
|
|
15
|
|
|
/** |
|
16
|
|
|
* Default search attribute class. |
|
17
|
|
|
* |
|
18
|
|
|
* Instances of this class define input fields that can be searched for, how they |
|
19
|
|
|
* should be validated and what type is used by a manager internally when |
|
20
|
|
|
* storing data in the database |
|
21
|
|
|
* |
|
22
|
|
|
* @package Base |
|
23
|
|
|
* @subpackage Common |
|
24
|
|
|
*/ |
|
25
|
|
|
class Standard implements \Aimeos\Base\Criteria\Attribute\Iface |
|
26
|
|
|
{ |
|
27
|
|
|
/* Custom value */ |
|
28
|
|
|
public $value; |
|
29
|
|
|
|
|
30
|
|
|
private array $values; |
|
31
|
|
|
|
|
32
|
|
|
|
|
33
|
|
|
/** |
|
34
|
|
|
* Initializes the search attribute object. |
|
35
|
|
|
* |
|
36
|
|
|
* @param array $params Parameter to be set on initialisation |
|
37
|
|
|
* [code] string |
|
38
|
|
|
* [default] mixed (optional) |
|
39
|
|
|
* [internalcode] string (optional) |
|
40
|
|
|
* [internaltype] string (optional) |
|
41
|
|
|
* [internaldeps] array (optional) |
|
42
|
|
|
* [function] Closure (optional) |
|
43
|
|
|
* [label] string |
|
44
|
|
|
* [public] boolean (optional) |
|
45
|
|
|
* [required] booblean (optional) |
|
46
|
|
|
* [type] string |
|
47
|
|
|
*/ |
|
48
|
|
|
public function __construct( array $params = [] ) |
|
49
|
|
|
{ |
|
50
|
|
|
if( !isset( $params['code'] ) ) { |
|
51
|
|
|
throw new \Aimeos\Base\Exception( sprintf( 'Required parameter "%1$s" is missing', 'code' ) ); |
|
52
|
|
|
} |
|
53
|
|
|
|
|
54
|
|
|
$this->values = $params; |
|
55
|
|
|
} |
|
56
|
|
|
|
|
57
|
|
|
|
|
58
|
|
|
/** |
|
59
|
|
|
* Returns the value of the attribute. |
|
60
|
|
|
* |
|
61
|
|
|
* @param string $name Name of the attribute |
|
62
|
|
|
* @return mixed|null Value of the attribute or NULL if not available |
|
63
|
|
|
*/ |
|
64
|
|
|
public function __get( string $name ) |
|
65
|
|
|
{ |
|
66
|
|
|
return $this->values[$name] ?? null; |
|
67
|
|
|
} |
|
68
|
|
|
|
|
69
|
|
|
|
|
70
|
|
|
/** |
|
71
|
|
|
* Tests if the property name is available. |
|
72
|
|
|
* |
|
73
|
|
|
* @param string $name Name of the attribute |
|
74
|
|
|
* @return bool TRUE if the property is available, FALSE if not |
|
75
|
|
|
*/ |
|
76
|
|
|
public function __isset( string $name ) : bool |
|
77
|
|
|
{ |
|
78
|
|
|
return isset( $this->values[$name] ); |
|
79
|
|
|
} |
|
80
|
|
|
|
|
81
|
|
|
|
|
82
|
|
|
/** |
|
83
|
|
|
* Returns the type of the attribute. |
|
84
|
|
|
* |
|
85
|
|
|
* Can be used in the frontend to create a speacial form for this type |
|
86
|
|
|
* |
|
87
|
|
|
* @return string Available types are "string", "integer", "float", "boolean", "date", "time", "datetime" |
|
88
|
|
|
*/ |
|
89
|
|
|
public function getType() : string |
|
90
|
|
|
{ |
|
91
|
|
|
return $this->values['type'] ?? 'string'; |
|
92
|
|
|
} |
|
93
|
|
|
|
|
94
|
|
|
|
|
95
|
|
|
/** |
|
96
|
|
|
* Returns the type internally used by the manager. |
|
97
|
|
|
* |
|
98
|
|
|
* @return int|string Type used by the manager |
|
99
|
|
|
* @deprecated 2024.01 |
|
100
|
|
|
*/ |
|
101
|
|
|
public function getInternalType() |
|
102
|
|
|
{ |
|
103
|
|
|
return $this->values['internaltype'] ?? $this->getType(); |
|
104
|
|
|
} |
|
105
|
|
|
|
|
106
|
|
|
|
|
107
|
|
|
/** |
|
108
|
|
|
* Returns the public code for the search attribute. |
|
109
|
|
|
* |
|
110
|
|
|
* @return string Public code of the search attribute |
|
111
|
|
|
*/ |
|
112
|
|
|
public function getCode() : string |
|
113
|
|
|
{ |
|
114
|
|
|
return $this->values['code']; |
|
115
|
|
|
} |
|
116
|
|
|
|
|
117
|
|
|
|
|
118
|
|
|
/** |
|
119
|
|
|
* Returns the internal code for the search attribute. |
|
120
|
|
|
* |
|
121
|
|
|
* @return array|string Internal code of the search attribute |
|
122
|
|
|
*/ |
|
123
|
|
|
public function getInternalCode() |
|
124
|
|
|
{ |
|
125
|
|
|
return $this->values['internalcode'] ?? $this->getCode(); |
|
126
|
|
|
} |
|
127
|
|
|
|
|
128
|
|
|
|
|
129
|
|
|
/** |
|
130
|
|
|
* Returns the list of internal dependency strings for the search attribute. |
|
131
|
|
|
* |
|
132
|
|
|
* @return array List of internal dependency strings |
|
133
|
|
|
*/ |
|
134
|
|
|
public function getInternalDeps() : array |
|
135
|
|
|
{ |
|
136
|
|
|
return (array) ( $this->values['internaldeps'] ?? [] ); |
|
137
|
|
|
} |
|
138
|
|
|
|
|
139
|
|
|
|
|
140
|
|
|
/** |
|
141
|
|
|
* Returns the helper function if available |
|
142
|
|
|
* |
|
143
|
|
|
* @return \Closure|null Helper function |
|
144
|
|
|
*/ |
|
145
|
|
|
public function getFunction() : ?\Closure |
|
146
|
|
|
{ |
|
147
|
|
|
return $this->values['function'] ?? null; |
|
148
|
|
|
} |
|
149
|
|
|
|
|
150
|
|
|
|
|
151
|
|
|
/** |
|
152
|
|
|
* Returns the human readable label for the search attribute. |
|
153
|
|
|
* |
|
154
|
|
|
* @return string Name of the search attribute |
|
155
|
|
|
*/ |
|
156
|
|
|
public function getLabel() : string |
|
157
|
|
|
{ |
|
158
|
|
|
return $this->values['label'] ?? $this->getCode(); |
|
159
|
|
|
} |
|
160
|
|
|
|
|
161
|
|
|
|
|
162
|
|
|
/** |
|
163
|
|
|
* Returns the default value of the search attribute. |
|
164
|
|
|
* |
|
165
|
|
|
* @return mixed Default value of the search attribute |
|
166
|
|
|
*/ |
|
167
|
|
|
public function getDefault() |
|
168
|
|
|
{ |
|
169
|
|
|
return $this->values['default'] ?? null; |
|
170
|
|
|
} |
|
171
|
|
|
|
|
172
|
|
|
|
|
173
|
|
|
/** |
|
174
|
|
|
* Returns true if the attribute should be publically available. |
|
175
|
|
|
* |
|
176
|
|
|
* @return bool True if the attribute is public, false if not |
|
177
|
|
|
*/ |
|
178
|
|
|
public function isPublic() : bool |
|
179
|
|
|
{ |
|
180
|
|
|
return (bool) ( $this->values['public'] ?? true ); |
|
181
|
|
|
} |
|
182
|
|
|
|
|
183
|
|
|
|
|
184
|
|
|
/** |
|
185
|
|
|
* Returns true if the attribute is required. |
|
186
|
|
|
* |
|
187
|
|
|
* @return bool True if the attribute is required, false if not |
|
188
|
|
|
*/ |
|
189
|
|
|
public function isRequired() : bool |
|
190
|
|
|
{ |
|
191
|
|
|
return (bool) ( $this->values['required'] ?? true ); |
|
192
|
|
|
} |
|
193
|
|
|
|
|
194
|
|
|
|
|
195
|
|
|
/** |
|
196
|
|
|
* Returns the attribute properties as key/value pairs. |
|
197
|
|
|
* |
|
198
|
|
|
* @param bool $private TRUE to return private attributes too, FALSE for public only |
|
199
|
|
|
* @return array Associative list of attribute key/value pairs |
|
200
|
|
|
*/ |
|
201
|
|
|
public function toArray( bool $private = false ) : array |
|
202
|
|
|
{ |
|
203
|
|
|
$list = [ |
|
204
|
|
|
'code' => $this->getCode(), |
|
205
|
|
|
'type' => $this->getType(), |
|
206
|
|
|
'label' => $this->getLabel(), |
|
207
|
|
|
'public' => $this->isPublic(), |
|
208
|
|
|
'default' => $this->getDefault(), |
|
209
|
|
|
'required' => $this->isRequired(), |
|
210
|
|
|
'value' => $this->value |
|
211
|
|
|
]; |
|
212
|
|
|
|
|
213
|
|
|
if( $private ) |
|
214
|
|
|
{ |
|
215
|
|
|
$list['internalcode'] = $this->getInternalCode(); |
|
216
|
|
|
$list['internaldeps'] = $this->getInternalDeps(); |
|
217
|
|
|
$list['internaltype'] = $this->getInternalType(); |
|
218
|
|
|
} |
|
219
|
|
|
|
|
220
|
|
|
return $list; |
|
221
|
|
|
} |
|
222
|
|
|
} |
|
223
|
|
|
|