Subs-Notify.php 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. <?php
  2. /**
  3. * Simple Machines Forum (SMF)
  4. *
  5. * @package SMF
  6. * @author Simple Machines http://www.simplemachines.org
  7. * @copyright 2013 Simple Machines and individual contributors
  8. * @license http://www.simplemachines.org/about/smf/license.php BSD
  9. *
  10. * @version 2.1 Alpha 1
  11. */
  12. if (!defined('SMF'))
  13. die('No direct access...');
  14. /**
  15. * Fetches the list of preferences (or a single/subset of preferences) for
  16. * notifications for one or more users.
  17. *
  18. * @param mixed $members A user id or an array of (integer) user ids to load preferences for
  19. * @param mixed $prefs An empty string to load all preferences, or a string (or array) of preference name(s) to load
  20. * @return array An array of user ids => array (pref name -> value), with user id 0 representing the defaults
  21. */
  22. function getNotifyPrefs($members, $prefs = '')
  23. {
  24. global $smcFunc;
  25. // We want this as an array whether it is or not.
  26. $members = is_array($members) ? $members : (array) $members;
  27. if (!empty($prefs))
  28. $prefs = is_array($prefs) ? $prefs : (array) $prefs;
  29. $result = array();
  30. // We want to now load the default, which is stored with a member id of 0.
  31. $members[] = 0;
  32. $request = $smcFunc['db_query']('', '
  33. SELECT id_member, alert_pref, alert_value
  34. FROM {db_prefix}user_alerts_prefs
  35. WHERE id_member IN ({array_int:members})' . (!empty($prefs) ? '
  36. AND alert_pref IN ({array_string:prefs})' : ''),
  37. array(
  38. 'members' => $members,
  39. 'prefs' => $prefs,
  40. )
  41. );
  42. while ($row = $smcFunc['db_fetch_assoc']($request))
  43. {
  44. $result[$row['id_member']][$row['alert_pref']] = $row['alert_value'];
  45. }
  46. // Let's not bother to reduplicate the default value for all the other values,
  47. // no point splurging on potentially a lot of memory unnecessarily.
  48. return $result;
  49. }
  50. ?>