Elgg  Version 2.2
 All Classes Namespaces Files Functions Variables Pages
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 
149  public function getOwnerEntity() {
150  return get_entity($this->owner_guid);
151  }
152 
158  public function getEntity() {
159  return get_entity($this->entity_guid);
160  }
161 
171  abstract public function canEdit($user_guid = 0);
172 
176  public function toObject() {
177  $object = new \stdClass();
178  $object->id = $this->id;
179  $object->entity_guid = $this->entity_guid;
180  $object->owner_guid = $this->owner_guid;
181  $object->name = $this->name;
182  $object->value = $this->value;
183  $object->time_created = date('c', $this->getTimeCreated());
184  $object->read_access = $this->access_id;
185  $params = array($this->getSubtype() => $this);
186  return _elgg_services()->hooks->trigger('to:object', $this->getSubtype(), $params, $object);
187  }
188 
189  /*
190  * EXPORTABLE INTERFACE
191  */
192 
199  public function getExportableValues() {
200  elgg_deprecated_notice(__METHOD__ . ' has been deprecated by toObject()', 1.9);
201  return array(
202  'id',
203  'entity_guid',
204  'name',
205  'value',
206  'value_type',
207  'owner_guid',
208  'type',
209  );
210  }
211 
218  public function export() {
219  elgg_deprecated_notice(__METHOD__ . ' has been deprecated', 1.9);
220  $uuid = get_uuid_from_object($this);
221 
222  $meta = new ODDMetaData($uuid, guid_to_uuid($this->entity_guid), $this->attributes['name'],
223  $this->attributes['value'], $this->attributes['type'], guid_to_uuid($this->owner_guid));
224  $meta->setAttribute('published', date("r", $this->time_created));
225 
226  return $meta;
227  }
228 
229  /*
230  * SYSTEM LOG INTERFACE
231  */
232 
239  public function getSystemLogID() {
240  return $this->id;
241  }
242 
248  public function getType() {
249  return $this->type;
250  }
251 
258  public function getSubtype() {
259  return $this->name;
260  }
261 
270  public function getURL() {
271 
272  $url = "";
273  $type = $this->getType();
274  $subtype = $this->getSubtype();
275 
276  // @todo remove when elgg_register_extender_url_handler() has been removed
277  if ($this->id) {
278  global $CONFIG;
279 
280  $function = "";
281  if (isset($CONFIG->extender_url_handler[$type][$subtype])) {
282  $function = $CONFIG->extender_url_handler[$type][$subtype];
283  }
284  if (isset($CONFIG->extender_url_handler[$type]['all'])) {
285  $function = $CONFIG->extender_url_handler[$type]['all'];
286  }
287  if (isset($CONFIG->extender_url_handler['all']['all'])) {
288  $function = $CONFIG->extender_url_handler['all']['all'];
289  }
290  if (is_callable($function)) {
291  $url = call_user_func($function, $this);
292  }
293 
294  if ($url) {
296  }
297  }
298 
299  $params = array('extender' => $this);
300  $url = _elgg_services()->hooks->trigger('extender:url', $type, $params, $url);
301 
302  return elgg_normalize_url($url);
303  }
304 
305 }
getType()
Return a type of extension.
$object
These two snippets demonstrates triggering an event and how to register for that event.
Definition: trigger.php:7
getTimeCreated()
Returns the UNIX epoch time that this entity was created.
Definition: ElggData.php:110
initializeAttributes()
(non-PHPdoc)
getEntity()
Get the entity this describes.
elgg_normalize_url($url)
Definition: output.php:290
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.
$value
Definition: longtext.php:26
$subtype
Definition: delete.php:28
__set($name, $value)
Set an attribute.
getExportableValues()
Return an array of fields which can be exported.
set($name, $value, $value_type= '')
Set an attribute.
$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
$comment owner_guid
Definition: save.php:58
global $CONFIG
const ACCESS_PRIVATE
Definition: elgglib.php:1988
elgg_deprecated_notice($msg, $dep_version, $backtrace_level=1)
Log a notice about deprecated use of a function, view, etc.
Definition: elgglib.php:1070
_elgg_services(\Elgg\Di\ServiceProvider $services=null)
Get the global service provider.
Definition: autoloader.php:17
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's owner entity.
getSystemLogID()
Return an identification for the object for storage in the system log.
$user_guid
Avatar remove action.
Definition: remove.php:6
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:204
if(!$display_name) $type
Definition: delete.php:27