Elgg
Version 4.x
Main Page
Related Pages
Namespaces
Classes
Files
Examples
File List
File Members
engine
classes
ElggExtender.php
Go to the documentation of this file.
1
<?php
24
abstract
class
ElggExtender
extends
\ElggData
{
25
29
protected
const
INTEGER_ATTR_NAMES
= [
30
'id'
,
31
'entity_guid'
,
32
'owner_guid'
,
33
'access_id'
,
34
'time_created'
,
35
];
36
40
protected
function
initializeAttributes
() {
41
parent::initializeAttributes();
42
43
$this->attributes[
'type'
] = null;
44
$this->attributes[
'id'
] = null;
45
$this->attributes[
'entity_guid'
] = null;
46
$this->attributes[
'owner_guid'
] = null;
47
$this->attributes[
'access_id'
] =
ACCESS_PRIVATE
;
48
$this->attributes[
'enabled'
] =
'yes'
;
49
}
50
58
public
function
__set
(
$name
,
$value
) {
59
if
(
$name
===
'access_id'
&& $this instanceof
ElggMetadata
) {
60
$value
=
ACCESS_PUBLIC
;
61
}
62
if
(isset(
$value
) && in_array(
$name
, static::INTEGER_ATTR_NAMES)) {
63
$value
= (int)
$value
;
64
}
65
$this->attributes[
$name
] =
$value
;
66
if
(
$name
==
'value'
) {
67
$this->attributes[
'value_type'
] = self::detectValueType(
$value
);
68
}
69
}
70
79
public
function
setValue
(
$value
, $value_type =
''
) {
80
$this->attributes[
'value'
] =
$value
;
81
$this->attributes[
'value_type'
] = self::detectValueType(
$value
, $value_type);
82
}
83
90
public
function
__get
(
$name
) {
91
if
(array_key_exists(
$name
, $this->attributes)) {
92
if
(
$name
==
'value'
) {
93
switch
($this->attributes[
'value_type'
]) {
94
case
'bool'
:
95
return
(
bool
) $this->attributes[
'value'
];
96
case
'integer'
:
97
return
(
int
) $this->attributes[
'value'
];
98
case
'text'
:
99
return
$this->attributes[
'value'
];
100
default
:
101
$msg =
"{$this->attributes['value_type']} is not a supported \ElggExtender value type."
;
102
throw
new \UnexpectedValueException($msg);
103
break
;
104
}
105
}
106
107
if
(
$name
===
'access_id'
&& $this instanceof
ElggMetadata
) {
108
return
ACCESS_PUBLIC
;
109
}
110
111
return
$this->attributes[
$name
];
112
}
113
114
return
null;
115
}
116
122
public
function
getOwnerGUID
() {
123
return
$this->owner_guid
;
124
}
125
131
public
function
getOwnerEntity
() {
132
return
get_entity
($this->owner_guid);
133
}
134
140
public
function
getEntity
() {
141
return
get_entity
($this->entity_guid);
142
}
143
152
abstract
public
function
canEdit
(
$user_guid
= 0);
153
157
public
function
toObject
(array
$params
= []) {
158
159
$object
= new \Elgg\Export\Extender();
160
$object
->id =
$this->id
;
161
$object
->entity_guid =
$this->entity_guid
;
162
$object
->owner_guid =
$this->owner_guid
;
163
$object
->name =
$this->name
;
164
$object
->value =
$this->value
;
165
$object
->time_created = date(
'c'
, $this->
getTimeCreated
());
166
$object
->read_access =
$this->access_id
;
167
168
$params
[$this->
getType
()] = $this;
169
170
return
_elgg_services
()->hooks->trigger(
'to:object'
, $this->
getType
(),
$params
,
$object
);
171
}
172
173
/*
174
* SYSTEM LOG INTERFACE
175
*/
176
183
public
function
getSystemLogID
() {
184
return
$this->id
;
185
}
186
192
public
function
getType
() {
193
return
$this->type
;
194
}
195
202
public
function
getSubtype
() {
203
return
$this->name
;
204
}
205
214
public
function
getURL
() {
215
216
$params
= [
'extender'
=> $this];
217
$url
=
_elgg_services
()->hooks->trigger(
'extender:url'
, $this->
getType
(),
$params
,
''
);
218
219
return
elgg_normalize_url
(
$url
);
220
}
221
231
public
static
function
detectValueType
(
$value
,
string
$value_type =
''
): string {
232
if
(in_array($value_type, [
'integer'
,
'text'
,
'bool'
])) {
233
return
$value_type;
234
}
235
236
if
(is_int(
$value
)) {
237
return
'integer'
;
238
}
elseif
(is_bool(
$value
)) {
239
return
'bool'
;
240
}
241
242
return
'text'
;
243
}
244
}
ElggExtender\getType
getType()
Return a type of extension.
Definition:
ElggExtender.php:192
$user_guid
$user_guid
Definition:
login_as.php:10
$name
if(!$user||!$user->canDelete()) $name
Definition:
delete.php:22
ElggData\getTimeCreated
getTimeCreated()
Returns the UNIX epoch time that this entity was created.
Definition:
ElggData.php:100
ElggExtender\initializeAttributes
initializeAttributes()
{}
Definition:
ElggExtender.php:40
$params
$params
Saves global plugin settings.
Definition:
save.php:13
ElggExtender\getEntity
getEntity()
Get the entity this describes.
Definition:
ElggExtender.php:140
elgg_normalize_url
elgg_normalize_url($url)
Definition:
output.php:152
ElggExtender
Definition:
ElggExtender.php:24
ElggExtender\__get
__get($name)
Gets an attribute.
Definition:
ElggExtender.php:90
ElggExtender\canEdit
canEdit($user_guid=0)
Returns if a user can edit this entity extender.
$access_id
$access_id
Definition:
access.php:11
ElggExtender\INTEGER_ATTR_NAMES
const INTEGER_ATTR_NAMES
Definition:
ElggExtender.php:29
$type
$type
Definition:
delete.php:21
ElggExtender\__set
__set($name, $value)
Set an attribute.
Definition:
ElggExtender.php:58
ElggMetadata
$value
$value
Definition:
generic.php:51
$entity_guid
$entity_guid
Action for adding and editing comments.
Definition:
save.php:6
$owner_guid
$owner_guid
Definition:
comments_block.php:23
ACCESS_PRIVATE
const ACCESS_PRIVATE
Definition:
constants.php:12
ElggExtender\detectValueType
static detectValueType($value, string $value_type= '')
Detect the value_type for a value to be stored as metadata or an annotation.
Definition:
ElggExtender.php:231
ElggExtender\toObject
toObject(array $params=[])
{}
Definition:
ElggExtender.php:157
ElggData
A generic class that contains shared code among , , and .
Definition:
ElggData.php:10
ElggExtender\getOwnerEntity
getOwnerEntity()
Get the entity that owns this extender.
Definition:
ElggExtender.php:131
ElggExtender\getOwnerGUID
getOwnerGUID()
Get the GUID of the extender's owner entity.
Definition:
ElggExtender.php:122
$object
if($email instanceof\Elgg\Email) $object
Definition:
body.php:24
elseif
if($item instanceof\ElggEntity) elseif($item instanceof\ElggRiverItem) elseif($item instanceof ElggRelationship) elseif(is_callable([$item, 'getType']))
Definition:
item.php:48
$url
foreach($plugin_guids as $guid) if(empty($deactivated_plugins)) $url
Definition:
deactivate.php:39
ElggExtender\getSystemLogID
getSystemLogID()
Return an identification for the object for storage in the system log.
Definition:
ElggExtender.php:183
_elgg_services
_elgg_services()
Get the global service provider.
Definition:
elgglib.php:777
ACCESS_PUBLIC
const ACCESS_PUBLIC
Definition:
constants.php:14
$id
$id
Generic annotation delete action.
Definition:
delete.php:6
ElggExtender\getSubtype
getSubtype()
Return a subtype.
Definition:
ElggExtender.php:202
ElggExtender\setValue
setValue($value, $value_type= '')
Set the value of the extender.
Definition:
ElggExtender.php:79
ElggExtender\getURL
getURL()
Get a url for this extender.
Definition:
ElggExtender.php:214
get_entity
get_entity($guid)
Loads and returns an entity object from a guid.
Definition:
entities.php:69
Generated on Thu Jul 7 2022 00:00:18 for Elgg by
1.8.11