Elgg  Version 3.0
Event.php
Go to the documentation of this file.
1 <?php
2 
4 
5 use ElggData;
6 use ElggEntity;
8 use stdClass;
9 
17 class Event implements NotificationEvent {
18 
20 
24  protected $action;
25 
29  protected $object;
30 
34  protected $actor;
35 
45  public function __construct(ElggData $object, $action, ElggEntity $actor = null) {
46  if (get_class($this) == Event::class) {
47  _elgg_services()->deprecation->sendNotice(__CLASS__ . ' is deprecated. '
48  . 'Use ' . SubscriptionNotificationEvent::class . ' instead', '2.3');
49  }
50  if (!$action) {
51  throw new InvalidArgumentException(__METHOD__ . ' expects a valid action name');
52  }
53 
54  $this->object = $object;
55 
56  $this->actor = $actor;
57  if (!isset($actor)) {
58  $this->actor = _elgg_services()->session->getLoggedInUser();
59  }
60 
61  $this->action = $action;
62  }
63 
73  public function getActor() {
74  return $this->actor;
75  }
76 
86  public function getActorGUID() {
87  return $this->actor ? $this->actor->guid : 0;
88  }
89 
99  public function getObject() {
100  return $this->object;
101  }
102 
108  public function getAction() {
109  return $this->action;
110  }
111 
117  public function getDescription() {
118  return implode(':', [
119  $this->action,
120  $this->object->getType(),
121  $this->object->getSubtype(),
122  ]);
123  }
124 
131  public function toObject() {
132  $obj = new stdClass();
133  $vars = get_object_vars($this);
134  foreach ($vars as $key => $value) {
135  if (is_object($value) && is_callable([$value, 'toObject'])) {
136  $obj->$key = $value->toObject();
137  } else {
138  $obj->$key = $value;
139  }
140  }
141  return $obj;
142  }
143 }
$action
Definition: full.php:111
if(!$item instanceof ElggRiverItem) $object
Definition: responses.php:23
__construct(ElggData $object, $action, ElggEntity $actor=null)
Create a notification event.
Definition: Event.php:45
getAction()
Get the name of the action.
Definition: Event.php:108
getActorGUID()
Get the GUID of the actor.
Definition: Event.php:86
Models an event passed to event handlers.
Definition: Event.php:11
toObject()
Export the notification event into a serializable object This method is mainly used for logging purpo...
Definition: Event.php:131
getActor()
Get the actor of the event.
Definition: Event.php:73
if($container instanceof ElggGroup &&$container->guid!=elgg_get_page_owner_guid()) $key
Definition: summary.php:55
$value
Definition: debugging.php:7
$vars['type']
Definition: save.php:11
class
Definition: placeholder.php:21
getDescription()
Get a description of the event.
Definition: Event.php:117
_elgg_services()
Get the global service provider.
Definition: elgglib.php:1292
elgg action
Definition: ajax.js:200
elgg ElggEntity
Definition: ElggEntity.js:15
getObject()
Get the object of the event.
Definition: Event.php:99