enable_group.php 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. <?php
  2. /**
  3. * Enables notification method for a batch of group members
  4. */
  5. $methods = get_input('methods');
  6. $offset = get_input('offset');
  7. if (empty($methods)) {
  8. register_error(elgg_echo('notification_tools:error:no_methods'));
  9. forward(REFERER);
  10. }
  11. $methods = explode(' ', $methods);
  12. // TODO Verify that notification methods are valid
  13. $limit = 10;
  14. $dbprefix = elgg_get_config('dbprefix');
  15. $query = "SELECT r.guid_one as user_guid, r.guid_two as group_guid
  16. FROM {$dbprefix}entity_relationships r
  17. INNER JOIN {$dbprefix}entities ue ON ue.guid = r.guid_one
  18. INNER JOIN {$dbprefix}entities ge ON ge.guid = r.guid_two
  19. WHERE r.relationship = 'member'
  20. AND ue.type = 'user'
  21. AND ge.type = 'group'
  22. LIMIT {$offset}, {$limit}";
  23. // Get all group memberships
  24. $memberships = get_data($query);
  25. foreach ($memberships as $membership) {
  26. foreach ($methods as $method) {
  27. add_entity_relationship($membership->user_guid, "notify{$method}", $membership->group_guid);
  28. }
  29. }
  30. // Return the amount of processed items
  31. $result = new stdClass;
  32. $result->count = $limit;
  33. echo json_encode($result);