2010071002.php 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. <?php
  2. /**
  3. * Update the notifications based on all friends and access collections
  4. */
  5. // loop through all users checking collections and notifications
  6. global $ENTITY_CACHE, $CONFIG;
  7. $NOTIFICATION_HANDLERS = _elgg_services()->notifications->getMethodsAsDeprecatedGlobal();
  8. $users = mysql_query("SELECT guid, username FROM {$CONFIG->dbprefix}users_entity
  9. WHERE username != ''");
  10. while ($user = mysql_fetch_object($users)) {
  11. $ENTITY_CACHE = array();
  12. $user = get_entity($user->guid);
  13. foreach ($NOTIFICATION_HANDLERS as $method => $foo) {
  14. $notify = "notify$method";
  15. $metaname = "collections_notifications_preferences_$method";
  16. $collections_preferences = $user->$metaname;
  17. if (!$collections_preferences) {
  18. continue;
  19. }
  20. if (!is_array($collections_preferences)) {
  21. $collections_preferences = array($collections_preferences);
  22. }
  23. foreach ($collections_preferences as $collection_id) {
  24. // check the all friends notifications
  25. if ($collection_id == -1) {
  26. $options = array(
  27. 'relationship' => 'friend',
  28. 'relationship_guid' => $user->guid,
  29. 'limit' => 0
  30. );
  31. $friends = elgg_get_entities_from_relationship($options);
  32. foreach ($friends as $friend) {
  33. if (!check_entity_relationship($user->guid, $notify, $friend->guid)) {
  34. add_entity_relationship($user->guid, $notify, $friend->guid);
  35. }
  36. }
  37. } else {
  38. $members = get_members_of_access_collection($collection_id, TRUE);
  39. foreach ($members as $member) {
  40. if (!check_entity_relationship($user->guid, $notify, $members)) {
  41. add_entity_relationship($user->guid, $notify, $member);
  42. }
  43. }
  44. }
  45. }
  46. }
  47. }