Elgg  Version 1.11
ElggExtender.php
Go to the documentation of this file.
1 <?php
26 abstract class ElggExtender extends \ElggData {
27 
35  protected function initializeAttributes() {
36  parent::initializeAttributes();
37 
38  $this->attributes['type'] = null;
39  $this->attributes['id'] = null;
40  $this->attributes['entity_guid'] = null;
41  $this->attributes['owner_guid'] = null;
42  $this->attributes['access_id'] = ACCESS_PRIVATE;
43  $this->attributes['enabled'] = 'yes';
44  }
45 
53  public function __set($name, $value) {
54  $this->attributes[$name] = $value;
55  if ($name == 'value') {
56  $this->attributes['value_type'] = detect_extender_valuetype($value);
57  }
58  }
59 
68  public function setValue($value, $value_type = '') {
69  $this->attributes['value'] = $value;
70  $this->attributes['value_type'] = detect_extender_valuetype($value, $value_type);
71  }
72 
83  protected function set($name, $value, $value_type = '') {
84  elgg_deprecated_notice("Use -> instead of set()", 1.9);
85  if ($name == 'value') {
86  $this->setValue($value, $value_type);
87  } else {
88  $this->__set($name, $value);
89  }
90 
91  return true;
92  }
93 
100  public function __get($name) {
101  if (array_key_exists($name, $this->attributes)) {
102  if ($name == 'value') {
103  switch ($this->attributes['value_type']) {
104  case 'integer' :
105  return (int)$this->attributes['value'];
106  break;
107  case 'text' :
108  return $this->attributes['value'];
109  break;
110  default :
111  $msg = "{$this->attributes['value_type']} is not a supported \ElggExtender value type.";
112  throw new \UnexpectedValueException($msg);
113  break;
114  }
115  }
116 
117  return $this->attributes[$name];
118  }
119 
120  return null;
121  }
122 
130  protected function get($name) {
131  elgg_deprecated_notice("Use -> instead of get()", 1.9);
132  return $this->__get($name);
133  }
134 
140  public function getOwnerGUID() {
141  return $this->owner_guid;
142  }
143 
150  public function getOwner() {
151  elgg_deprecated_notice("\ElggExtender::getOwner deprecated for \ElggExtender::getOwnerGUID", 1.8);
152  return $this->getOwnerGUID();
153  }
154 
160  public function getOwnerEntity() {
161  return get_entity($this->owner_guid);
162  }
163 
169  public function getEntity() {
170  return get_entity($this->entity_guid);
171  }
172 
182  abstract public function canEdit($user_guid = 0);
183 
187  public function toObject() {
188  $object = new \stdClass();
189  $object->id = $this->id;
190  $object->entity_guid = $this->entity_guid;
191  $object->owner_guid = $this->owner_guid;
192  $object->name = $this->name;
193  $object->value = $this->value;
194  $object->time_created = date('c', $this->getTimeCreated());
195  $object->read_access = $this->access_id;
196  $params = array($this->getSubtype() => $this);
197  return _elgg_services()->hooks->trigger('to:object', $this->getSubtype(), $params, $object);
198  }
199 
200  /*
201  * EXPORTABLE INTERFACE
202  */
203 
210  public function getExportableValues() {
211  elgg_deprecated_notice(__METHOD__ . ' has been deprecated by toObject()', 1.9);
212  return array(
213  'id',
214  'entity_guid',
215  'name',
216  'value',
217  'value_type',
218  'owner_guid',
219  'type',
220  );
221  }
222 
229  public function export() {
230  elgg_deprecated_notice(__METHOD__ . ' has been deprecated', 1.9);
231  $uuid = get_uuid_from_object($this);
232 
233  $meta = new ODDMetaData($uuid, guid_to_uuid($this->entity_guid), $this->attributes['name'],
234  $this->attributes['value'], $this->attributes['type'], guid_to_uuid($this->owner_guid));
235  $meta->setAttribute('published', date("r", $this->time_created));
236 
237  return $meta;
238  }
239 
240  /*
241  * SYSTEM LOG INTERFACE
242  */
243 
250  public function getSystemLogID() {
251  return $this->id;
252  }
253 
259  public function getType() {
260  return $this->type;
261  }
262 
269  public function getSubtype() {
270  return $this->name;
271  }
272 
281  public function getURL() {
282 
283  $url = "";
284  $type = $this->getType();
285  $subtype = $this->getSubtype();
286 
287  // @todo remove when elgg_register_extender_url_handler() has been removed
288  if ($this->id) {
289  global $CONFIG;
290 
291  $function = "";
292  if (isset($CONFIG->extender_url_handler[$type][$subtype])) {
293  $function = $CONFIG->extender_url_handler[$type][$subtype];
294  }
295  if (isset($CONFIG->extender_url_handler[$type]['all'])) {
296  $function = $CONFIG->extender_url_handler[$type]['all'];
297  }
298  if (isset($CONFIG->extender_url_handler['all']['all'])) {
299  $function = $CONFIG->extender_url_handler['all']['all'];
300  }
301  if (is_callable($function)) {
302  $url = call_user_func($function, $this);
303  }
304 
305  if ($url) {
307  }
308  }
309 
310  $params = array('extender' => $this);
311  $url = _elgg_services()->hooks->trigger('extender:url', $type, $params, $url);
312 
313  return elgg_normalize_url($url);
314  }
315 
316 }
getType()
Return a type of extension.
getTimeCreated()
Returns the UNIX epoch time that this entity was created.
Definition: ElggData.php:131
initializeAttributes()
(non-PHPdoc)
getEntity()
Get the entity this describes.
elgg_normalize_url($url)
Definition: output.php:311
get_uuid_from_object($object)
Get a UUID from a given object.
if($guid==elgg_get_logged_in_user_guid()) $name
Definition: delete.php:21
__get($name)
Gets an attribute.
canEdit($user_guid=0)
Returns if a user can edit this entity extender.
$object
Definition: upgrade.php:12
$value
Definition: longtext.php:26
__set($name, $value)
Set an attribute.
getExportableValues()
Return an array of fields which can be exported.
$url
Definition: exceptions.php:24
$params
Definition: login.php:72
$entity_guid
Definition: save.php:9
detect_extender_valuetype($value, $value_type="")
Detect the value_type for a given value.
Definition: extender.php:21
export()
Export this object.
$owner_guid
$filehandler owner_guid
Definition: crop.php:21
_elgg_services()
Definition: autoloader.php:14
global $CONFIG
const ACCESS_PRIVATE
Definition: elgglib.php:1954
elgg_deprecated_notice($msg, $dep_version, $backtrace_level=1)
Log a notice about deprecated use of a function, view, etc.
Definition: elgglib.php:1006
elgg global
Pointer to the global context.
Definition: elgglib.js:12
$type
Definition: add.php:8
getOwnerEntity()
Get the entity that owns this extender.
guid_to_uuid($guid)
Generate a UUID from a given GUID.
getOwnerGUID()
Get the GUID of the extender&#39;s owner entity.
getSystemLogID()
Return an identification for the object for storage in the system log.
getOwner()
Return the guid of the entity&#39;s owner.
$user_guid
Avatar remove action.
Definition: remove.php:6
$subtype
Definition: river.php:12
if(!$collection_name) $id
Definition: add.php:17
getSubtype()
Return a subtype.
setValue($value, $value_type= '')
Set the value of the extender.
getURL()
Get a url for this extender.
get_entity($guid)
Loads and returns an entity object from a guid.
Definition: entities.php:382