SiteNotificationFactory.php 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. <?php
  2. abstract class SiteNotificationFactory {
  3. /**
  4. * Create a site notification
  5. *
  6. * @param ElggUser $recipient Recipient of the notification
  7. * @param string $message Notification message
  8. * @param ElggUser $actor User who caused the notification event
  9. * @param ElggData $object Optional object involved in the notification event
  10. * @return SiteNotification|null
  11. */
  12. public static function create($recipient, $message, $actor, $object = null) {
  13. $note = new SiteNotification();
  14. $note->owner_guid = $recipient->guid;
  15. $note->container_guid = $recipient->guid;
  16. $note->access_id = ACCESS_PRIVATE;
  17. $note->description = $message;
  18. if ($object) {
  19. // TODO Add support for setting an URL for a notification about a new relationship
  20. switch ($object->getType()) {
  21. case 'annotation':
  22. // Annotations do not have an URL so we use the entity URL
  23. $note->setURL($object->getEntity()->getURL());
  24. break;
  25. default:
  26. $note->setURL($object->getURL());
  27. }
  28. }
  29. $note->setRead(false);
  30. if ($note->save()) {
  31. $note->setActor($actor);
  32. return $note;
  33. } else {
  34. return null;
  35. }
  36. }
  37. }