SiteNotification.php 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. <?php
  2. /**
  3. * Site notification class
  4. */
  5. class SiteNotification extends ElggObject {
  6. const HAS_ACTOR = "hasActor";
  7. /**
  8. * Initialize an instance
  9. */
  10. protected function initializeAttributes() {
  11. parent::initializeAttributes();
  12. $this->attributes['subtype'] = 'site_notification';
  13. }
  14. /**
  15. * Get the actor involved in the notification
  16. *
  17. * @return ElggEntity|null
  18. */
  19. public function getActor() {
  20. $actor = $this->getEntitiesFromRelationship(array('relationship' => self::HAS_ACTOR));
  21. if ($actor) {
  22. $actor = $actor[0];
  23. }
  24. return $actor;
  25. }
  26. /**
  27. * Set the actor involved in the notification
  28. *
  29. * @param ElggEntity $entity Actor
  30. */
  31. public function setActor($entity) {
  32. $this->addRelationship($entity->guid, self::HAS_ACTOR);
  33. }
  34. /**
  35. * Get the url for this notification
  36. *
  37. * @return string
  38. */
  39. public function getURL() {
  40. return (string)$this->url;
  41. }
  42. /**
  43. * Set the url for the notification
  44. *
  45. * @param string $url The URL for the notification link
  46. */
  47. public function setURL($url) {
  48. if ($url) {
  49. $this->url = $url;
  50. }
  51. }
  52. /**
  53. * Set the read status
  54. *
  55. * @param bool $read Has the notification been read
  56. */
  57. public function setRead($read) {
  58. $this->read = $read;
  59. }
  60. /**
  61. * Has the notification been read?
  62. *
  63. * @return bool
  64. */
  65. public function isRead() {
  66. return (bool)$this->read;
  67. }
  68. }