Elgg  Version master
EventSerialization.php
Go to the documentation of this file.
1 <?php
2 
4 
10 trait EventSerialization {
11 
17  public function __serialize() {
18  $data = [];
19 
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 
28  $data['object_type'] = $this->object->getType();
29  $data['object_subtype'] = $this->object->getSubtype();
30  }
31 
32  if ($this->actor) {
33  $data['actor_guid'] = $this->actor->guid;
34  }
35 
36  return $data;
37  }
38 
46  public function __unserialize($data) {
47  if (isset($data['action'])) {
48  $this->action = $data['action'];
49  }
50 
51  if (isset($data['object_id']) && isset($data['object_type'])) {
52  $object_id = $data['object_id'];
53  switch ($data['object_type']) {
54  case 'object':
55  case 'user':
56  case 'group':
57  case 'site':
58  $this->object = get_entity($object_id);
59  break;
60  case 'annotation':
61  $this->object = elgg_get_annotation_from_id($object_id);
62  break;
63  case 'metadata':
64  $this->object = elgg_get_metadata_from_id($object_id);
65  break;
66  case 'relationship':
67  $this->object = elgg_get_relationship($object_id);
68  break;
69  }
70  }
71 
72  if (isset($data['actor_guid'])) {
73  $this->actor = get_entity($data['actor_guid']);
74  }
75  }
76 }
getSubtype()
Get the entity subtype.
Definition: ElggEntity.php:504
elgg_get_metadata_from_id(int $id)
Elgg metadata Functions to manage entity metadata.
Definition: metadata.php:16
if(!$entity instanceof\ElggUser) $data
Definition: attributes.php:13
get_entity(int $guid)
Loads and returns an entity object from a guid.
Definition: entities.php:70
elgg_get_relationship(int $id)
Get a relationship by its ID.
A generic class that contains shared code among , , and .
Definition: ElggData.php:10
$action
Definition: subscribe.php:11
getType()
Returns the entity type.
Definition: ElggEntity.php:478
elgg_get_annotation_from_id(int $id)
Elgg annotations Functions to manage object annotations.
Definition: annotations.php:16