groupsave.php 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. <?php
  2. /**
  3. * Elgg notifications group save
  4. *
  5. * @package ElggNotifications
  6. */
  7. $current_user = elgg_get_logged_in_user_entity();
  8. $guid = (int) get_input('guid', 0);
  9. if (!$guid || !($user = get_entity($guid))) {
  10. forward();
  11. }
  12. if (($user->guid != $current_user->guid) && !$current_user->isAdmin()) {
  13. forward();
  14. }
  15. // Get group memberships and condense them down to an array of guids
  16. $groups = array();
  17. $options = array(
  18. 'relationship' => 'member',
  19. 'relationship_guid' => $user->guid,
  20. 'type' => 'group',
  21. 'limit' => false,
  22. );
  23. if ($groupmemberships = elgg_get_entities_from_relationship($options)) {
  24. foreach ($groupmemberships as $groupmembership) {
  25. $groups[] = $groupmembership->guid;
  26. }
  27. }
  28. if (!empty($groups)) {
  29. $NOTIFICATION_HANDLERS = _elgg_services()->notifications->getMethodsAsDeprecatedGlobal();
  30. foreach ($NOTIFICATION_HANDLERS as $method => $foo) {
  31. $subscriptions[$method] = get_input($method.'subscriptions', array());
  32. foreach ($groups as $group) {
  33. if (in_array($group, $subscriptions[$method])) {
  34. elgg_add_subscription($user->guid, $method, $group);
  35. } else {
  36. elgg_remove_subscription($user->guid, $method, $group);
  37. }
  38. }
  39. }
  40. }
  41. system_message(elgg_echo('notifications:subscriptions:success'));
  42. forward(REFERER);