UserSettings.php 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. <?php
  2. namespace ColdTrick\ContentSubscriptions;
  3. class UserSettings {
  4. /**
  5. * Save the content subscriptions preferences for the user
  6. *
  7. * @param string $hook the name of the hook
  8. * @param stirng $type the type of the hook
  9. * @param array $return_value the current return value
  10. * @param array $params supplied values
  11. *
  12. * @return void
  13. */
  14. public static function notificationSettingsSaveAction($hook, $type, $return_value, $params) {
  15. $NOTIFICATION_HANDLERS = _elgg_services()->notifications->getMethods();
  16. if (empty($NOTIFICATION_HANDLERS) || !is_array($NOTIFICATION_HANDLERS)) {
  17. return;
  18. }
  19. $user_guid = (int) get_input('guid');
  20. if (empty($user_guid)) {
  21. return;
  22. }
  23. $user = get_user($user_guid);
  24. if (empty($user) || !$user->canEdit()) {
  25. return;
  26. }
  27. $methods = [];
  28. foreach ($NOTIFICATION_HANDLERS as $method) {
  29. $setting = get_input("content_subscriptions_{$method}");
  30. if (!empty($setting)) {
  31. $methods[] = $method;
  32. }
  33. }
  34. if (!empty($methods)) {
  35. elgg_set_plugin_user_setting('notification_settings', implode(',', $methods), $user->getGUID(), 'content_subscriptions');
  36. } else {
  37. elgg_unset_plugin_user_setting('notification_settings', $user->getGUID(), 'content_subscriptions');
  38. }
  39. // set flag for correct fallback behaviour
  40. elgg_set_plugin_user_setting('notification_settings_saved', '1', $user->getGUID(), 'content_subscriptions');
  41. }
  42. }