Membership.php 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. <?php
  2. namespace ColdTrick\GroupTools;
  3. class Membership {
  4. /**
  5. * Listen to the delete of a membership request
  6. *
  7. * @param stirng $event the name of the event
  8. * @param stirng $type the type of the event
  9. * @param \ElggRelationship $relationship the relationship
  10. *
  11. * @return void
  12. */
  13. public static function deleteRequest($event, $type, $relationship) {
  14. if (!($relationship instanceof \ElggRelationship)) {
  15. return;
  16. }
  17. if ($relationship->relationship !== 'membership_request') {
  18. // not a membership request
  19. return;
  20. }
  21. $action_pattern = '/action\/groups\/killrequest/i';
  22. if (!preg_match($action_pattern, current_page_url())) {
  23. // not in the action, so do nothing
  24. return;
  25. }
  26. $group = get_entity($relationship->guid_two);
  27. $user = get_user($relationship->guid_one);
  28. if (empty($user) || !($group instanceof \ElggGroup)) {
  29. return;
  30. }
  31. if ($user->getGUID() === elgg_get_logged_in_user_guid()) {
  32. // user kills own request
  33. return;
  34. }
  35. $reason = get_input('reason');
  36. if (empty($reason)) {
  37. $body = elgg_echo('group_tools:notify:membership:declined:message', array(
  38. $user->name,
  39. $group->name,
  40. $group->getURL(),
  41. ));
  42. } else {
  43. $body = elgg_echo('group_tools:notify:membership:declined:message:reason', array(
  44. $user->name,
  45. $group->name,
  46. $reason,
  47. $group->getURL(),
  48. ));
  49. }
  50. $subject = elgg_echo('group_tools:notify:membership:declined:subject', array(
  51. $group->name,
  52. ));
  53. $params = array(
  54. 'object' => $group,
  55. 'action' => 'delete',
  56. );
  57. notify_user($user->getGUID(), $group->getGUID(), $subject, $body, $params);
  58. }
  59. }