Elgg  Version 2.3
Event.php
Go to the documentation of this file.
1 <?php
3 
8 
16 class Event implements NotificationEvent {
17 
19 
20  /* @var string The name of the action/event */
21  protected $action;
22 
23  /* @var string Action's object */
24  protected $object;
25 
26  /* @var ElggEntity User who triggered the event */
27  protected $actor;
28 
38  public function __construct(ElggData $object, $action, ElggEntity $actor = null) {
39  if (get_class($this) == Event::class || get_class($this) == Elgg_Notifications_Event::class) {
40  _elgg_services()->deprecation->sendNotice(__CLASS__ . ' is deprecated. '
41  . 'Use ' . SubscriptionNotificationEvent::class . ' instead', '2.3');
42  }
43  if (!$object instanceof ElggData) {
44  throw new InvalidArgumentException(__METHOD__ . ' expects an object as an instance of ' . ElggData::class);
45  }
46  if (!$action) {
47  throw new InvalidArgumentException(__METHOD__ . ' expects a valid action name');
48  }
49 
50  $this->object = $object;
51 
52  $this->actor = $actor;
53  if (!isset($actor)) {
54  $this->actor = _elgg_services()->session->getLoggedInUser();
55  }
56 
57  $this->action = $action;
58  }
59 
69  public function getActor() {
70  return $this->actor;
71  }
72 
82  public function getActorGUID() {
83  return $this->actor ? $this->actor->guid : 0;
84  }
85 
95  public function getObject() {
96  return $this->object;
97  }
98 
104  public function getAction() {
105  return $this->action;
106  }
107 
113  public function getDescription() {
114  return implode(':', [
115  $this->action,
116  $this->object->getType(),
117  $this->object->getSubtype(),
118  ]);
119  }
120 
127  public function toObject() {
128  $obj = new stdClass();
129  $vars = get_object_vars($this);
130  foreach ($vars as $key => $value) {
131  if (is_object($value) && is_callable([$value, 'toObject'])) {
132  $obj->$key = $value->toObject();
133  } else {
134  $obj->$key = $value;
135  }
136  }
137  return $obj;
138  }
139 }
140 
150 
__construct(ElggData $object, $action, ElggEntity $actor=null)
Create a notification event.
Definition: Event.php:38
getAction()
Get the name of the action.
Definition: Event.php:104
$value
Definition: longtext.php:42
$vars['entity']
getActorGUID()
Get the GUID of the actor.
Definition: Event.php:82
$key
Definition: summary.php:34
toObject()
Export the notification event into a serializable object This method is mainly used for logging purpo...
Definition: Event.php:127
_elgg_services(\Elgg\Di\ServiceProvider $services=null)
Get the global service provider.
Definition: autoloader.php:17
getActor()
Get the actor of the event.
Definition: Event.php:69
class
Definition: placeholder.php:21
getDescription()
Get a description of the event.
Definition: Event.php:113
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
getObject()
Get the object of the event.
Definition: Event.php:95
elgg action
Definition: ajax.js:200