Browse Source

! Let's go really crazy and let the get function actually do processing of default values as well.

Peter Spicer 11 years ago
parent
commit
7279db9588

+ 12 - 3
Sources/Subs-Notify.php

@@ -20,9 +20,10 @@ if (!defined('SMF'))
  *
  * @param mixed $members A user id or an array of (integer) user ids to load preferences for
  * @param mixed $prefs An empty string to load all preferences, or a string (or array) of preference name(s) to load
+ * @param mixed $process_default Whether to apply the default values to the members' values or not.
  * @return array An array of user ids => array (pref name -> value), with user id 0 representing the defaults
  */
-function getNotifyPrefs($members, $prefs = '')
+function getNotifyPrefs($members, $prefs = '', $process_default = false)
 {
 	global $smcFunc;
 
@@ -52,8 +53,16 @@ function getNotifyPrefs($members, $prefs = '')
 		$result[$row['id_member']][$row['alert_pref']] = $row['alert_value'];
 	}
 
-	// Let's not bother to reduplicate the default value for all the other values,
-	// no point splurging on potentially a lot of memory unnecessarily.
+	// We may want to keep the default values separate from a given user's. Or we might not.
+	if ($process_default && isset($result[0]))
+	{
+		foreach ($members as $member)
+			if (!isset($result[$member]))
+				$result[$member] = $result[0];
+
+		unset ($result[0]);
+	}
+
 	return $result;
 }
 

+ 1 - 5
Sources/tasks/GroupReq-Notify.php

@@ -45,15 +45,11 @@ class GroupReq_Notify_Background extends SMF_BackgroundTask
 			$data = array('alert' => array(), 'email' => array());
 
 			require_once($sourcedir . '/Subs-Notify.php');
-			$prefs = getNotifyPrefs($moderators, 'request_group');
+			$prefs = getNotifyPrefs($moderators, 'request_group', true);
 
 			// Bitwise comparisons are fun...
 			foreach ($moderators as $mod)
 			{
-				// Do we have any defaults?
-				if (isset($prefs[0]) && !isset($prefs[$mod]))
-					$prefs[$mod] = $prefs[0];
-
 				if (!empty($prefs[$mod]))
 				{
 					if ($prefs[$mod] & 0x01)

+ 2 - 6
Sources/tasks/Likes-Notify.php

@@ -69,16 +69,12 @@ class Likes_Notify_Background extends SMF_BackgroundTask
 			return true;
 
 		require_once($sourcedir . '/Subs-Notify.php');
-		$prefs = getNotifyPrefs($author, $this->_details['content_type'] . '_like');
+		$prefs = getNotifyPrefs($author, $this->_details['content_type'] . '_like', true);
 
 		// The likes setup doesn't support email notifications because that would be too many emails.
 		// As a result, the value should really just be non empty.
 
-		// First, grab the default if there is one.
-		if (!isset($prefs[$author]) && isset($prefs[0]))
-			$prefs[$author] = $prefs[0];
-
-		// Second, check the value. If no value or it's empty, they didn't want alerts, oh well.
+		// Check the value. If no value or it's empty, they didn't want alerts, oh well.
 		if (empty($prefs[$author][$this->_details['content_type'] . '_like']))
 			return true;
 

+ 1 - 11
Sources/tasks/MsgReport-Notify.php

@@ -60,17 +60,7 @@ class MsgReport_Notify_Background extends SMF_BackgroundTask
 
 		// Having successfully figured this out, now let's get the preferences of everyone.
 		require_once($sourcedir . '/Subs-Notify.php');
-		$prefs = getNotifyPrefs($members, 'msg_report');
-
-		// Apply defaults if we got some.
-		if (isset($prefs[0]))
-		{
-			foreach ($members as $member)
-				if (!isset($prefs[$member]))
-					$prefs[$member] = $prefs[0];
-
-			unset ($prefs[0]); // Don't need this any more.
-		}
+		$prefs = getNotifyPrefs($members, 'msg_report', true);
 
 		// So now we find out who wants what.
 		$alert_bits = array(

+ 1 - 11
Sources/tasks/Register-Notify.php

@@ -25,17 +25,7 @@ class Register_Notify_Background extends SMF_BackgroundTask
 
 		// Having successfully figured this out, now let's get the preferences of everyone.
 		require_once($sourcedir . '/Subs-Notify.php');
-		$prefs = getNotifyPrefs($members, 'member_register');
-
-		// Apply defaults if we got some.
-		if (isset($prefs[0]))
-		{
-			foreach ($members as $member)
-				if (!isset($prefs[$member]))
-					$prefs[$member] = $prefs[0];
-
-			unset ($prefs[0]); // Don't need this any more.
-		}
+		$prefs = getNotifyPrefs($members, 'member_register', true);
 
 		// So now we find out who wants what.
 		$alert_bits = array(