Elgg  Version 2.3
Notification.php
Go to the documentation of this file.
1 <?php
2 namespace Elgg\Notifications;
3 
11 class Notification {
12 
13  const ORIGIN_SUBSCRIPTIONS = 'subscriptions_service';
14  const ORIGIN_INSTANT = 'instant_notifications';
15 
17  protected $from;
18 
20  protected $to;
21 
23  public $summary;
24 
26  public $subject;
27 
29  public $body;
30 
32  public $language;
33 
35  public $params;
36 
49  public function __construct(\ElggEntity $from, \ElggEntity $to, $language, $subject, $body, $summary = '', array $params = array()) {
50  if (!$from) {
51  throw new \InvalidArgumentException('$from is not a valid \ElggEntity');
52  }
53  if (!$to) {
54  throw new \InvalidArgumentException('$to is not a valid \ElggEntity');
55  }
56  $this->from = $from;
57  $this->to = $to;
58  $this->language = $language;
59  $this->subject = $subject;
60  $this->body = $body;
61  $this->summary = $summary;
62  $this->params = $params;
63  }
64 
70  public function getSender() {
71  return $this->from;
72  }
73 
79  public function getSenderGUID() {
80  return $this->from->guid;
81  }
82 
88  public function getRecipient() {
89  return $this->to;
90  }
91 
97  public function getRecipientGUID() {
98  return $this->to->guid;
99  }
100 
105  public function toObject() {
106  $obj = new \stdClass();
107  $vars = get_object_vars($this);
108  $vars = array_merge($this->params, $vars);
109  unset($vars['params']);
110  unset($vars['sender']);
111  unset($vars['recipient']);
112  unset($vars['subscriptions']);
113  unset($vars['action']);
114  unset($vars['object']);
115  foreach ($vars as $key => $value) {
116  if (is_object($value) && is_callable([$value, 'toObject'])) {
117  $obj->$key = $value->toObject();
118  } else {
119  $obj->$key = $value;
120  }
121  }
122  return $obj;
123  }
124 }
125 
getRecipient()
Get the recipient entity.
toObject()
Export notification.
$value
Definition: longtext.php:42
$vars['entity']
$key
Definition: summary.php:34
getRecipientGUID()
Get the recipient entity guid.
getSender()
Get the sender entity.
__construct(\ElggEntity $from,\ElggEntity $to, $language, $subject, $body, $summary= '', array $params=array())
Create a notification.
getSenderGUID()
Get the sender entity guid.
$CONFIG language
The current language for either the site or the user.
Definition: config.php:51
body
Definition: admin.css.php:36