Elgg  Version 2.3
EventSerialization.php
Go to the documentation of this file.
1 <?php
2 
3 namespace Elgg\Notifications;
4 
8 
9 trait EventSerialization {
10 
15  public function serialize() {
16  $data = new stdClass();
17  $data->action = $this->action;
18  if ($this->object instanceof ElggData) {
19  if ($this->object instanceof ElggEntity) {
20  $data->object_id = $this->object->guid;
21  } else {
22  $data->object_id = $this->object->id;
23  }
24  $data->object_type = $this->object->getType();
25  $data->object_subtype = $this->object->getSubtype();
26  }
27  if ($this->actor) {
28  $data->actor_guid = $this->actor->guid;
29  }
30  return serialize($data);
31  }
32 
39  public function unserialize($serialized) {
40  $data = unserialize($serialized);
41  if (isset($data->action)) {
42  $this->action = $data->action;
43  }
44  if (isset($data->object_id) && isset($data->object_type)) {
45  switch ($data->object_type) {
46  case 'object' :
47  case 'user' :
48  case 'group' :
49  case 'site' :
50  $this->object = get_entity($data->object_id);
51  break;
52  case 'annotation' :
53  $this->object = elgg_get_annotation_from_id($data->object_id);
54  break;
55  case 'metadata' :
56  $this->object = elgg_get_metadata_from_id($data->object_id);
57  break;
58  case 'relationship' :
59  $this->object = get_relationship($data->object_id);
60  }
61  }
62 
63  if (isset($data->actor_guid)) {
64  $this->actor = get_entity($data->actor_guid);
65  }
66  }
67 
68 }
$action
Definition: full.php:133
get_relationship($id)
Get a relationship by its ID.
$data
Definition: opendd.php:13
elgg_get_metadata_from_id($id)
Get a specific metadata object by its id.
Definition: metadata.php:35
elgg_get_annotation_from_id($id)
Get a specific annotation by its id.
Definition: annotations.php:36
elgg ElggEntity
Definition: ElggEntity.js:16
http free of to any person obtaining a copy of this software and associated documentation to deal in the Software without including without limitation the rights to use
Definition: MIT-LICENSE.txt:5
get_entity($guid)
Loads and returns an entity object from a guid.
Definition: entities.php:204
elgg action
Definition: ajax.js:200