Elgg  Version 6.2
ElggExtender.php
Go to the documentation of this file.
1 <?php
2 
3 use Elgg\Exceptions\UnexpectedValueException as ElggUnexpectedValueException;
4 
27 abstract class ElggExtender extends \ElggData {
28 
32  protected const INTEGER_ATTR_NAMES = [
33  'id',
34  'entity_guid',
35  'owner_guid',
36  'access_id',
37  'time_created',
38  ];
39 
43  protected function initializeAttributes() {
44  parent::initializeAttributes();
45 
46  $this->attributes['type'] = null;
47  $this->attributes['id'] = null;
48  $this->attributes['entity_guid'] = null;
49  $this->attributes['owner_guid'] = null;
50  $this->attributes['access_id'] = ACCESS_PRIVATE;
51  $this->attributes['enabled'] = 'yes';
52  }
53 
61  public function __set($name, $value) {
62  if ($name === 'access_id' && $this instanceof ElggMetadata) {
64  }
65 
66  if (isset($value) && in_array($name, static::INTEGER_ATTR_NAMES)) {
67  $value = (int) $value;
68  }
69 
70  $this->attributes[$name] = $value;
71  if ($name == 'value') {
72  $this->attributes['value_type'] = self::detectValueType($value);
73  }
74  }
75 
84  public function setValue($value, string $value_type = ''): void {
85  $this->attributes['value'] = $value;
86  $this->attributes['value_type'] = self::detectValueType($value, $value_type);
87  }
88 
97  public function __get($name) {
98  if (array_key_exists($name, $this->attributes)) {
99  if ($name == 'value') {
100  switch ($this->attributes['value_type']) {
101  case 'bool':
102  return (bool) $this->attributes['value'];
103  case 'integer':
104  return (int) $this->attributes['value'];
105  case 'text':
106  return $this->attributes['value'];
107  default:
108  $msg = "{$this->attributes['value_type']} is not a supported \ElggExtender value type.";
109  throw new ElggUnexpectedValueException($msg);
110  }
111  }
112 
113  if ($name === 'access_id' && $this instanceof ElggMetadata) {
114  return ACCESS_PUBLIC;
115  }
116 
117  return $this->attributes[$name];
118  }
119 
120  return null;
121  }
122 
128  public function getOwnerGUID(): int {
129  return $this->owner_guid;
130  }
131 
137  public function getOwnerEntity(): ?\ElggEntity {
138  return $this->owner_guid ? get_entity($this->owner_guid) : null;
139  }
140 
146  public function getEntity(): ?\ElggEntity {
147  return $this->entity_guid ? get_entity($this->entity_guid) : null;
148  }
149 
158  abstract public function canEdit(int $user_guid = 0): bool;
159 
163  public function toObject(array $params = []) {
164 
165  $object = new \Elgg\Export\Extender();
166  $object->id = $this->id;
167  $object->entity_guid = $this->entity_guid;
168  $object->owner_guid = $this->owner_guid;
169  $object->name = $this->name;
170  $object->value = $this->value;
171  $object->time_created = date('c', $this->getTimeCreated());
172  $object->read_access = $this->access_id;
173 
174  $params[$this->getType()] = $this;
175 
176  return _elgg_services()->events->triggerResults('to:object', $this->getType(), $params, $object);
177  }
178 
179  /*
180  * SYSTEM LOG INTERFACE
181  */
182 
186  public function getSystemLogID(): int {
187  return (int) $this->id;
188  }
189 
195  public function getType(): string {
196  return $this->type;
197  }
198 
205  public function getSubtype(): string {
206  return $this->name;
207  }
208 
217  public function getURL(): string {
218 
219  $params = ['extender' => $this];
220  $url = _elgg_services()->events->triggerResults('extender:url', $this->getType(), $params, '');
221 
222  return elgg_normalize_url($url);
223  }
224 
234  public static function detectValueType($value, string $value_type = ''): string {
235  if (in_array($value_type, ['integer', 'text', 'bool'])) {
236  return $value_type;
237  }
238 
239  if (is_int($value)) {
240  return 'integer';
241  } elseif (is_bool($value)) {
242  return 'bool';
243  }
244 
245  return 'text';
246  }
247 }
$site name
Definition: settings.php:15
if(! $user||! $user->canDelete()) $name
Definition: delete.php:22
$id
Generic annotation delete action.
Definition: delete.php:6
$entity_guid
Action for adding and editing comments.
Definition: save.php:6
$params
Saves global plugin settings.
Definition: save.php:13
return[ 'admin/delete_admin_notices'=>['access'=> 'admin'], 'admin/menu/save'=>['access'=> 'admin'], 'admin/plugins/activate'=>['access'=> 'admin'], 'admin/plugins/activate_all'=>['access'=> 'admin'], 'admin/plugins/deactivate'=>['access'=> 'admin'], 'admin/plugins/deactivate_all'=>['access'=> 'admin'], 'admin/plugins/set_priority'=>['access'=> 'admin'], 'admin/security/security_txt'=>['access'=> 'admin'], 'admin/security/settings'=>['access'=> 'admin'], 'admin/security/regenerate_site_secret'=>['access'=> 'admin'], 'admin/site/cache/invalidate'=>['access'=> 'admin'], 'admin/site/flush_cache'=>['access'=> 'admin'], 'admin/site/icons'=>['access'=> 'admin'], 'admin/site/set_maintenance_mode'=>['access'=> 'admin'], 'admin/site/set_robots'=>['access'=> 'admin'], 'admin/site/theme'=>['access'=> 'admin'], 'admin/site/unlock_upgrade'=>['access'=> 'admin'], 'admin/site/settings'=>['access'=> 'admin'], 'admin/upgrade'=>['access'=> 'admin'], 'admin/upgrade/reset'=>['access'=> 'admin'], 'admin/user/ban'=>['access'=> 'admin'], 'admin/user/bulk/ban'=>['access'=> 'admin'], 'admin/user/bulk/delete'=>['access'=> 'admin'], 'admin/user/bulk/unban'=>['access'=> 'admin'], 'admin/user/bulk/validate'=>['access'=> 'admin'], 'admin/user/change_email'=>['access'=> 'admin'], 'admin/user/delete'=>['access'=> 'admin'], 'admin/user/login_as'=>['access'=> 'admin'], 'admin/user/logout_as'=>[], 'admin/user/makeadmin'=>['access'=> 'admin'], 'admin/user/resetpassword'=>['access'=> 'admin'], 'admin/user/removeadmin'=>['access'=> 'admin'], 'admin/user/unban'=>['access'=> 'admin'], 'admin/user/validate'=>['access'=> 'admin'], 'annotation/delete'=>[], 'avatar/upload'=>[], 'comment/save'=>[], 'diagnostics/download'=>['access'=> 'admin'], 'entity/chooserestoredestination'=>[], 'entity/delete'=>[], 'entity/mute'=>[], 'entity/restore'=>[], 'entity/subscribe'=>[], 'entity/trash'=>[], 'entity/unmute'=>[], 'entity/unsubscribe'=>[], 'login'=>['access'=> 'logged_out'], 'logout'=>[], 'notifications/mute'=>['access'=> 'public'], 'plugins/settings/remove'=>['access'=> 'admin'], 'plugins/settings/save'=>['access'=> 'admin'], 'plugins/usersettings/save'=>[], 'register'=>['access'=> 'logged_out', 'middleware'=>[\Elgg\Router\Middleware\RegistrationAllowedGatekeeper::class,],], 'river/delete'=>[], 'settings/notifications'=>[], 'settings/notifications/subscriptions'=>[], 'user/changepassword'=>['access'=> 'public'], 'user/requestnewpassword'=>['access'=> 'public'], 'useradd'=>['access'=> 'admin'], 'usersettings/save'=>[], 'widgets/add'=>[], 'widgets/delete'=>[], 'widgets/move'=>[], 'widgets/save'=>[],]
Definition: actions.php:73
A generic class that contains shared code among \ElggExtender, \ElggEntity, and \ElggRelationship.
Definition: ElggData.php:12
initializeAttributes()
{Initialize the attributes array.This is vital to distinguish between metadata and base parameters....
getType()
Return a type of extension.
getOwnerGUID()
Get the GUID of the extender's owner entity.
__get($name)
Gets an attribute.
getOwnerEntity()
Get the entity that owns this extender.
canEdit(int $user_guid=0)
Returns if a user can edit this entity extender.
const INTEGER_ATTR_NAMES
getSystemLogID()
{Return an identification for the object for storage in the system log.This id must be an integer....
toObject(array $params=[])
{Get a plain old object copy for public consumption.Export parameters\Elgg\Export\Data}
__set($name, $value)
Set an attribute.
getEntity()
Get the entity this describes.
static detectValueType($value, string $value_type='')
Detect the value_type for a value to be stored as metadata or an annotation.
getSubtype()
Return a subtype.
getURL()
Get a url for this extender.
setValue($value, string $value_type='')
Set the value of the extender.
ElggMetadata.
Exception thrown if a value does not match with a set of values.
$owner_guid
const ACCESS_PRIVATE
Definition: constants.php:10
const ACCESS_PUBLIC
Definition: constants.php:12
foreach($plugin_guids as $guid) if(empty($deactivated_plugins)) $url
Definition: deactivate.php:39
if($email instanceof \Elgg\Email) $object
Definition: body.php:24
if($item instanceof \ElggEntity) elseif($item instanceof \ElggRiverItem) elseif($item instanceof \ElggRelationship) elseif(is_callable([ $item, 'getType']))
Definition: item.php:48
_elgg_services()
Get the global service provider.
Definition: elgglib.php:353
get_entity(int $guid)
Loads and returns an entity object from a guid.
Definition: entities.php:70
$value
Definition: generic.php:51
$user_guid
Definition: login_as.php:10
elgg_normalize_url(string $url)
Definition: output.php:163
if(parse_url(elgg_get_site_url(), PHP_URL_PATH) !=='/') if(file_exists(elgg_get_root_path() . 'robots.txt'))
Set robots.txt.
Definition: robots.php:10
$access_id
Definition: access.php:10