Comments.php 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. <?php
  2. namespace ColdTrick\ContentSubscriptions;
  3. class Comments {
  4. /**
  5. * Make sure we can autosubscribe the user to further updates
  6. *
  7. * @param string $event the name of the event
  8. * @param string $type the type of the event
  9. * @param ElggObject $object the created comment
  10. *
  11. * @return void
  12. */
  13. public static function createObject($event, $type, \ElggObject $object) {
  14. if (!($object instanceof \ElggComment)) {
  15. return;
  16. }
  17. $owner = $object->getOwnerEntity();
  18. $entity = $object->getContainerEntity();
  19. // add auto subscription for this user
  20. content_subscriptions_autosubscribe($entity->getGUID(), $owner->getGUID());
  21. }
  22. /**
  23. * Change the default notification message for comments
  24. *
  25. * @param string $hook the name of the hook
  26. * @param stirng $type the type of the hook
  27. * @param \Elgg\Notifications\Notification $return_value the current return value
  28. * @param array $params supplied values
  29. *
  30. * @return void|\Elgg\Notifications\Notification
  31. */
  32. public static function prepareNotification($hook, $type, $return_value, $params) {
  33. if (!($return_value instanceof \Elgg\Notifications\Notification)) {
  34. return;
  35. }
  36. if (empty($params) || !is_array($params)) {
  37. return;
  38. }
  39. $event = elgg_extract('event', $params);
  40. if (empty($event) || !($event instanceof \Elgg\Notifications\Event)) {
  41. return;
  42. }
  43. // ignore access for now
  44. $ia = elgg_set_ignore_access(true);
  45. $comment = $event->getObject();
  46. $actor = $event->getActor();
  47. $object = $comment->getContainerEntity();
  48. $language = elgg_extract('language', $params, get_current_language());
  49. $recipient = elgg_extract('recipient', $params);
  50. $return_value->subject = elgg_echo('content_subscriptions:create:comment:subject', [$object->title], $language);
  51. $return_value->body = elgg_echo('content_subscriptions:create:comment:message', [
  52. $recipient->name,
  53. $actor->name,
  54. $object->title,
  55. $comment->description,
  56. $object->getURL(),
  57. ], $language);
  58. $return_value->summary = elgg_echo('content_subscriptions:create:comment:summary', [$object->title], $language);
  59. // restore access
  60. elgg_set_ignore_access($ia);
  61. return $return_value;
  62. }
  63. }