Elgg  Version 3.0
ElggExtender.php
Go to the documentation of this file.
1 <?php
26 abstract class ElggExtender extends \ElggData {
27 
28  protected $int_columns = [
29  'id',
30  'entity_guid',
31  'owner_guid',
32  'time_created',
33  'access_id',
34  ];
35 
39  protected function initializeAttributes() {
40  parent::initializeAttributes();
41 
42  $this->attributes['type'] = null;
43  $this->attributes['id'] = null;
44  $this->attributes['entity_guid'] = null;
45  $this->attributes['owner_guid'] = null;
46  $this->attributes['access_id'] = ACCESS_PRIVATE;
47  $this->attributes['enabled'] = 'yes';
48  }
49 
57  public function __set($name, $value) {
58  if ($name === 'access_id' && $this instanceof ElggMetadata) {
60  }
61  if (isset($value) && in_array($name, $this->int_columns)) {
62  $value = (int) $value;
63  }
64  $this->attributes[$name] = $value;
65  if ($name == 'value') {
66  if (is_bool($value)) {
67  $value = (int) $value;
68  }
69  $this->attributes['value_type'] = self::detectValueType($value);
70  }
71  }
72 
81  public function setValue($value, $value_type = '') {
82  $this->attributes['value'] = $value;
83  $this->attributes['value_type'] = self::detectValueType($value, $value_type);
84  }
85 
92  public function __get($name) {
93  if (array_key_exists($name, $this->attributes)) {
94  if ($name == 'value') {
95  switch ($this->attributes['value_type']) {
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 
153  abstract public function canEdit($user_guid = 0);
154 
158  public function toObject(array $params = []) {
159 
160  $object = new \Elgg\Export\Extender();
161  $object->id = $this->id;
162  $object->entity_guid = $this->entity_guid;
163  $object->owner_guid = $this->owner_guid;
164  $object->name = $this->name;
165  $object->value = $this->value;
166  $object->time_created = date('c', $this->getTimeCreated());
167  $object->read_access = $this->access_id;
168 
169  $params[$this->getSubtype()] = $this; // deprecated use
170  $params[$this->getType()] = $this;
171 
172  // deprecated toObject hook
173  $deprecated_msg = "Triggering 'to:object' hook by extender name '{$this->getSubtype()}' has been deprecated. "
174  . "Use the generic 'to:object','{$this->getType()}' hook instead.";
175  $object = _elgg_services()->hooks->triggerDeprecated('to:object', $this->getSubtype(), $params, $object, $deprecated_msg, '2.3');
176 
177  return _elgg_services()->hooks->trigger('to:object', $this->getType(), $params, $object);
178  }
179 
180  /*
181  * SYSTEM LOG INTERFACE
182  */
183 
190  public function getSystemLogID() {
191  return $this->id;
192  }
193 
199  public function getType() {
200  return $this->type;
201  }
202 
209  public function getSubtype() {
210  return $this->name;
211  }
212 
221  public function getURL() {
222 
223  $params = ['extender' => $this];
224  $url = _elgg_services()->hooks->trigger('extender:url', $this->getType(), $params, '');
225 
226  return elgg_normalize_url($url);
227  }
228 
238  public static function detectValueType($value, $value_type = "") {
239  if ($value_type === 'integer' || $value_type === 'text') {
240  return $value_type;
241  }
242 
243  return is_int($value) ? 'integer' : 'text';
244  }
245 }
getType()
Return a type of extension.
if(!$item instanceof ElggRiverItem) $object
Definition: responses.php:23
if(!$user||!$user->canDelete()) $name
Definition: delete.php:22
getTimeCreated()
Returns the UNIX epoch time that this entity was created.
Definition: ElggData.php:106
initializeAttributes()
{}
$params
Saves global plugin settings.
Definition: save.php:13
getEntity()
Get the entity this describes.
elgg_normalize_url($url)
Definition: output.php:186
__get($name)
Gets an attribute.
canEdit($user_guid=0)
Returns if a user can edit this entity extender.
$access_id
Definition: access.php:11
static detectValueType($value, $value_type="")
Detect the value_type for a value to be stored as metadata or an annotation.
$type
Definition: delete.php:21
__set($name, $value)
Set an attribute.
$entity_guid
Definition: save.php:9
$user_guid
Validate a user.
Definition: validate.php:6
$owner_guid
$id
River item delete action.
Definition: delete.php:6
const ACCESS_PRIVATE
Definition: constants.php:12
$url
Definition: default.php:33
toObject(array $params=[])
{}
getOwnerEntity()
Get the entity that owns this extender.
getOwnerGUID()
Get the GUID of the extender&#39;s owner entity.
$value
Definition: debugging.php:7
getSystemLogID()
Return an identification for the object for storage in the system log.
_elgg_services()
Get the global service provider.
Definition: elgglib.php:1292
const ACCESS_PUBLIC
Definition: constants.php:14
getSubtype()
Return a subtype.
setValue($value, $value_type= '')
Set the value of the extender.
getURL()
Get a url for this extender.
$comment owner_guid
Definition: save.php:45
get_entity($guid)
Loads and returns an entity object from a guid.
Definition: entities.php:87