Elgg  Version 1.11
Event.php
Go to the documentation of this file.
1 <?php
9 class Event {
10  /* @var string The name of the action/event */
11  protected $action;
12 
13  /* @var string The type of the action's object */
14  protected $object_type;
15 
16  /* @var string the subtype of the action's object */
17  protected $object_subtype;
18 
19  /* @var int The identifier of the object (GUID for entity) */
20  protected $object_id;
21 
22  /* @var int The GUID of the user who triggered the event */
23  protected $actor_guid;
24 
25 
35  public function __construct(\ElggData $object, $action, \ElggEntity $actor = null) {
36  if (elgg_instanceof($object)) {
37  $this->object_type = $object->getType();
38  $this->object_subtype = $object->getSubtype();
39  $this->object_id = $object->getGUID();
40  } else {
41  $this->object_type = $object->getType();
42  $this->object_subtype = $object->getSubtype();
43  $this->object_id = $object->id;
44  }
45 
46  if ($actor == null) {
47  $this->actor_guid = _elgg_services()->session->getLoggedInUserGuid();
48  } else {
49  $this->actor_guid = $actor->getGUID();
50  }
51 
52  $this->action = $action;
53  }
54 
60  public function getActor() {
61  return get_entity($this->actor_guid);
62  }
63 
69  public function getActorGUID() {
70  return $this->actor_guid;
71  }
72 
78  public function getObject() {
79  switch ($this->object_type) {
80  case 'object':
81  case 'user':
82  case 'site':
83  case 'group':
84  return get_entity($this->object_id);
85  break;
86  case 'relationship':
87  return get_relationship($this->object_id);
88  break;
89  case 'annotation':
90  return elgg_get_annotation_from_id($this->object_id);
91  break;
92  }
93  return null;
94  }
95 
101  public function getAction() {
102  return $this->action;
103  }
104 
110  public function getDescription() {
111  return "{$this->action}:{$this->object_type}:{$this->object_subtype}";
112  }
113 }
114 
123 
__construct(\ElggData $object, $action,\ElggEntity $actor=null)
Create a notification event.
Definition: Event.php:35
get_relationship($id)
Get a relationship by its ID.
getAction()
Get the name of the action.
Definition: Event.php:101
getSubtype()
Return a subtype.
$object
Definition: upgrade.php:12
getActorGUID()
Get the GUID of the actor.
Definition: Event.php:69
elgg_instanceof($entity, $type=null, $subtype=null, $class=null)
Checks if $entity is an and optionally for type and subtype.
Definition: entities.php:922
elgg_get_annotation_from_id($id)
Get a specific annotation by its id.
Definition: annotations.php:36
_elgg_services()
Definition: autoloader.php:14
getType()
Return the type of the object - eg.
getActor()
Get the actor of the event.
Definition: Event.php:60
getDescription()
Get a description of the event.
Definition: Event.php:110
get_entity($guid)
Loads and returns an entity object from a guid.
Definition: entities.php:382
getObject()
Get the object of the event.
Definition: Event.php:78
elgg action
Definition: ajax.js:197