Elgg  Version 3.0
EventSerialization.php
Go to the documentation of this file.
1 <?php
2 
3 namespace Elgg\Notifications;
4 
5 use ElggData;
6 use ElggEntity;
7 use stdClass;
8 
12 trait EventSerialization {
13 
18  public function serialize() {
19  $data = new stdClass();
20  $data->action = $this->action;
21  if ($this->object instanceof ElggData) {
22  if ($this->object instanceof ElggEntity) {
23  $data->object_id = $this->object->guid;
24  } else {
25  $data->object_id = $this->object->id;
26  }
27  $data->object_type = $this->object->getType();
28  $data->object_subtype = $this->object->getSubtype();
29  }
30  if ($this->actor) {
31  $data->actor_guid = $this->actor->guid;
32  }
33  return serialize($data);
34  }
35 
42  public function unserialize($serialized) {
43  $data = unserialize($serialized);
44  if (isset($data->action)) {
45  $this->action = $data->action;
46  }
47  if (isset($data->object_id) && isset($data->object_type)) {
48  switch ($data->object_type) {
49  case 'object' :
50  case 'user' :
51  case 'group' :
52  case 'site' :
53  $this->object = get_entity($data->object_id);
54  break;
55  case 'annotation' :
56  $this->object = elgg_get_annotation_from_id($data->object_id);
57  break;
58  case 'metadata' :
59  $this->object = elgg_get_metadata_from_id($data->object_id);
60  break;
61  case 'relationship' :
62  $this->object = get_relationship($data->object_id);
63  }
64  }
65 
66  if (isset($data->actor_guid)) {
67  $this->actor = get_entity($data->actor_guid);
68  }
69  }
70 
71 }
$action
Definition: full.php:111
get_relationship($id)
Get a relationship by its ID.
if(elgg_trigger_plugin_hook('usersettings:save', 'user', $hooks_params, true)) foreach($request->validation() ->all() as $item) $data
Definition: save.php:57
elgg_get_metadata_from_id($id)
Get a specific metadata object by its id.
Definition: metadata.php:19
elgg_get_annotation_from_id($id)
Elgg annotations Functions to manage object annotations.
Definition: annotations.php:16
elgg action
Definition: ajax.js:200
elgg ElggEntity
Definition: ElggEntity.js:15
get_entity($guid)
Loads and returns an entity object from a guid.
Definition: entities.php:87