Notification.php 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. <?php
  2. namespace Elgg\Notifications;
  3. /**
  4. * Notification container
  5. *
  6. * @package Elgg.Core
  7. * @subpackage Notifications
  8. * @since 1.10
  9. */
  10. class Notification {
  11. /** @var \ElggEntity The entity causing or creating the notification */
  12. protected $from;
  13. /** @var \ElggUser The user receiving the notification */
  14. protected $to;
  15. /** @var string A single sentence summary string */
  16. public $summary;
  17. /** @var string The subject of the notification. Email subject is one use. */
  18. public $subject;
  19. /** @var string The body of the notification. Email body is one use. */
  20. public $body;
  21. /** @var string The language of the notification */
  22. public $language;
  23. /** @var array Additional parameters */
  24. public $params;
  25. /**
  26. * Create a notification
  27. *
  28. * @param \ElggEntity $from The entity sending the notification (usually the site)
  29. * @param \ElggEntity $to The entity receiving the notification
  30. * @param string $language The language code for the notification
  31. * @param string $subject The subject of the notification
  32. * @param string $body The body of the notification
  33. * @param string $summary Optional summary of the notification
  34. * @param array $params Optional array of parameters
  35. * @throws \InvalidArgumentException
  36. */
  37. public function __construct(\ElggEntity $from, \ElggEntity $to, $language, $subject, $body, $summary = '', array $params = array()) {
  38. if (!$from) {
  39. throw new \InvalidArgumentException('$from is not a valid \ElggEntity');
  40. }
  41. if (!$to) {
  42. throw new \InvalidArgumentException('$to is not a valid \ElggEntity');
  43. }
  44. $this->from = $from;
  45. $this->to = $to;
  46. $this->language = $language;
  47. $this->subject = $subject;
  48. $this->body = $body;
  49. $this->summary = $summary;
  50. $this->params = $params;
  51. }
  52. /**
  53. * Get the sender entity
  54. *
  55. * @return \ElggEntity
  56. */
  57. public function getSender() {
  58. return $this->from;
  59. }
  60. /**
  61. * Get the sender entity guid
  62. *
  63. * @return int
  64. */
  65. public function getSenderGUID() {
  66. return $this->from->guid;
  67. }
  68. /**
  69. * Get the recipient entity
  70. *
  71. * @return \ElggEntity
  72. */
  73. public function getRecipient() {
  74. return $this->to;
  75. }
  76. /**
  77. * Get the recipient entity guid
  78. *
  79. * @return int
  80. */
  81. public function getRecipientGUID() {
  82. return $this->to->guid;
  83. }
  84. }
  85. /**
  86. * Notification container
  87. *
  88. * @package Elgg.Core
  89. * @subpackage Notifications
  90. * @since 1.9.0
  91. *
  92. * @deprecated 1.10 Use \Elgg\Notifications\Notification instead
  93. */
  94. class Elgg_Notifications_Notification extends \Elgg\Notifications\Notification {}