adjustment to sorting of the notifications array
Showing
1 changed file
with
37 additions
and
9 deletions
| ... | @@ -21,10 +21,23 @@ const OPTION_NAME = "notif_options"; | ... | @@ -21,10 +21,23 @@ const OPTION_NAME = "notif_options"; |
| 21 | }); | 21 | }); |
| 22 | 22 | ||
| 23 | 23 | ||
| 24 | function subval_sort($a,$subkey,$sort) { | ||
| 25 | foreach($a as $k=>$v) { | ||
| 26 | $b[$k] = strtolower($v[$subkey]); | ||
| 27 | } | ||
| 28 | $sort($b); | ||
| 29 | foreach($b as $key=>$val) { | ||
| 30 | $c[] = $a[$key]; | ||
| 31 | } | ||
| 32 | return $c; | ||
| 33 | } | ||
| 34 | |||
| 24 | function get_user_notices($uid) { | 35 | function get_user_notices($uid) { |
| 25 | $notices = get_user_meta($uid,'notices',true); | 36 | $notices = get_user_meta($uid,'notices',true); |
| 26 | if(!empty($notices)) { | 37 | if(!empty($notices)) { |
| 27 | $notices = array_reverse($notices); | 38 | |
| 39 | $notices = subval_sort($notices,'sent_date',arsort); | ||
| 40 | |||
| 28 | Vars::$notices = $notices; | 41 | Vars::$notices = $notices; |
| 29 | } | 42 | } |
| 30 | } | 43 | } |
| ... | @@ -32,6 +45,8 @@ function get_user_notices($uid) { | ... | @@ -32,6 +45,8 @@ function get_user_notices($uid) { |
| 32 | function print_user_notices($show_more = true) { | 45 | function print_user_notices($show_more = true) { |
| 33 | 46 | ||
| 34 | get_user_notices(Tools\getCurrentUser()->ID); | 47 | get_user_notices(Tools\getCurrentUser()->ID); |
| 48 | |||
| 49 | |||
| 35 | if (CBV\on_page('/dashboard')) { | 50 | if (CBV\on_page('/dashboard')) { |
| 36 | $limit = 5; | 51 | $limit = 5; |
| 37 | } else { | 52 | } else { |
| ... | @@ -223,12 +238,8 @@ function send_triggered_notification($uid,$trigger="NO_TRIGGER",$args = array(), | ... | @@ -223,12 +238,8 @@ function send_triggered_notification($uid,$trigger="NO_TRIGGER",$args = array(), |
| 223 | send_email($uid,$email,$args,$send_override); | 238 | send_email($uid,$email,$args,$send_override); |
| 224 | } | 239 | } |
| 225 | 240 | ||
| 226 | 241 | ||
| 227 | 242 | } | |
| 228 | |||
| 229 | } else { | ||
| 230 | die('no notification'); | ||
| 231 | } | ||
| 232 | // if the system notification has set current user than get current user otherwise loop through the users needed. | 243 | // if the system notification has set current user than get current user otherwise loop through the users needed. |
| 233 | } | 244 | } |
| 234 | 245 | ||
| ... | @@ -237,7 +248,24 @@ function send_email($uid, $contents,$args) { | ... | @@ -237,7 +248,24 @@ function send_email($uid, $contents,$args) { |
| 237 | 248 | ||
| 238 | if ($uid > 0) { | 249 | if ($uid > 0) { |
| 239 | $user = new WP_User($uid); | 250 | $user = new WP_User($uid); |
| 240 | $to_email = $user->user_email; | 251 | |
| 252 | |||
| 253 | $preference = get_user_meta($uid, 'email_address_preference',true); | ||
| 254 | |||
| 255 | if ($preference == "Home") { | ||
| 256 | $to_email = get_user_meta($uid,'home_email',true); | ||
| 257 | } elseif ($preference == "Work") { | ||
| 258 | $to_email = get_user_meta($uid,'company_email',true); | ||
| 259 | } else { | ||
| 260 | $to_email = $user->user_email; | ||
| 261 | } | ||
| 262 | |||
| 263 | if (!(boolean)filter_var($to_email, FILTER_VALIDATE_EMAIL)) { | ||
| 264 | $to_email = $user->user_email; | ||
| 265 | } | ||
| 266 | |||
| 267 | |||
| 268 | |||
| 241 | } elseif (isset($args['email']) && !empty($args['email'])) { | 269 | } elseif (isset($args['email']) && !empty($args['email'])) { |
| 242 | $to_email = $args['email']; | 270 | $to_email = $args['email']; |
| 243 | } else { | 271 | } else { | ... | ... |
-
Please register or sign in to post a comment