diff options
author | Dhruv <dhruv.goel92@gmail.com> | 2014-06-07 01:34:20 +0530 |
---|---|---|
committer | Dhruv <dhruv.goel92@gmail.com> | 2014-06-07 01:34:20 +0530 |
commit | f5415619ebc49e370a4ec06cd6b664fb2456ccfe (patch) | |
tree | ab40824e9487c83e3c8d9f64e05e9d81a10bbc18 /phpBB | |
parent | ac74dc876ce215b3cc2c13f497cdd6c574bf65bc (diff) | |
download | forums-f5415619ebc49e370a4ec06cd6b664fb2456ccfe.tar forums-f5415619ebc49e370a4ec06cd6b664fb2456ccfe.tar.gz forums-f5415619ebc49e370a4ec06cd6b664fb2456ccfe.tar.bz2 forums-f5415619ebc49e370a4ec06cd6b664fb2456ccfe.tar.xz forums-f5415619ebc49e370a4ec06cd6b664fb2456ccfe.zip |
[ticket/11445] Move get user's notification code into its own method
PHPBB3-11445
Diffstat (limited to 'phpBB')
-rw-r--r-- | phpBB/phpbb/notification/manager.php | 43 |
1 files changed, 29 insertions, 14 deletions
diff --git a/phpBB/phpbb/notification/manager.php b/phpBB/phpbb/notification/manager.php index ad9cd9a3ff..b787b624f6 100644 --- a/phpBB/phpbb/notification/manager.php +++ b/phpBB/phpbb/notification/manager.php @@ -574,49 +574,64 @@ class manager return $subscription_methods; } + /** - * Get global subscriptions (item_id = 0) + * Get user's notification data * - * @param bool|int $user_id The user_id to add the subscription for (bool false for current user) + * @param int $user_id The user_id of the user to get the notifications for * - * @return array Subscriptions + * @return array User's notification */ - public function get_global_subscriptions($user_id = false) + protected function get_user_notifications($user_id) { - $user_id = ($user_id === false) ? $this->user->data['user_id'] : $user_id; - - $subscriptions = array(); - $sql = 'SELECT method, notify, item_type FROM ' . $this->user_notifications_table . ' WHERE user_id = ' . (int) $user_id . ' AND item_id = 0'; $result = $this->db->sql_query($sql); - $rows = array(); + $user_notifications = array(); while ($row = $this->db->sql_fetchrow($result)) { - $rows[$row['item_type']][] = $row; + $user_notifications[$row['item_type']][] = $row; } $this->db->sql_freeresult($result); + return $user_notifications; + } + + /** + * Get global subscriptions (item_id = 0) + * + * @param bool|int $user_id The user_id to add the subscription for (bool false for current user) + * + * @return array Subscriptions + */ + public function get_global_subscriptions($user_id = false) + { + $user_id = ($user_id === false) ? $this->user->data['user_id'] : $user_id; + + $subscriptions = array(); + + $user_notifications = $this->get_user_notifications($user_id); + foreach ($this->get_subscription_types() as $types) { foreach ($types as $id => $type) { - if (empty($rows[$id])) + if (empty($user_notifications[$id])) { // No rows at all, default to '' $subscriptions[$id] = array(''); } else { - foreach ($rows[$id] as $row) + foreach ($user_notifications[$id] as $user_notification) { - if (!$row['notify']) + if (!$user_notification['notify']) { continue; } @@ -626,7 +641,7 @@ class manager $subscriptions[$id] = array(); } - $subscriptions[$id][] = $row['method']; + $subscriptions[$id][] = $user_notification['method']; } } } |