diff options
Diffstat (limited to 'phpBB/phpbb/notification/manager.php')
-rw-r--r-- | phpBB/phpbb/notification/manager.php | 61 |
1 files changed, 42 insertions, 19 deletions
diff --git a/phpBB/phpbb/notification/manager.php b/phpBB/phpbb/notification/manager.php index c3539e76df..74ef980445 100644 --- a/phpBB/phpbb/notification/manager.php +++ b/phpBB/phpbb/notification/manager.php @@ -13,6 +13,8 @@ namespace phpbb\notification; +use Symfony\Component\DependencyInjection\ContainerInterface; + /** * Notifications service class */ @@ -24,7 +26,7 @@ class manager /** @var array */ protected $notification_methods; - /** @var ContainerBuilder */ + /** @var ContainerInterface */ protected $phpbb_container; /** @var \phpbb\user_loader */ @@ -62,7 +64,7 @@ class manager * * @param array $notification_types * @param array $notification_methods - * @param ContainerBuilder $phpbb_container + * @param ContainerInterface $phpbb_container * @param \phpbb\user_loader $user_loader * @param \phpbb\config\config $config * @param \phpbb\db\driver\driver_interface $db @@ -74,7 +76,7 @@ class manager * @param string $user_notifications_table * @return \phpbb\notification\manager */ - public function __construct($notification_types, $notification_methods, $phpbb_container, \phpbb\user_loader $user_loader, \phpbb\config\config $config, \phpbb\db\driver\driver_interface $db, \phpbb\cache\service $cache, $user, $phpbb_root_path, $php_ext, $notification_types_table, $notifications_table, $user_notifications_table) + public function __construct($notification_types, $notification_methods, ContainerInterface $phpbb_container, \phpbb\user_loader $user_loader, \phpbb\config\config $config, \phpbb\db\driver\driver_interface $db, \phpbb\cache\service $cache, $user, $phpbb_root_path, $php_ext, $notification_types_table, $notifications_table, $user_notifications_table) { $this->notification_types = $notification_types; $this->notification_methods = $notification_methods; @@ -574,6 +576,34 @@ class manager return $subscription_methods; } + + /** + * Get user's notification data + * + * @param int $user_id The user_id of the user to get the notifications for + * + * @return array User's notification + */ + protected function get_user_notifications($user_id) + { + $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); + $user_notifications = array(); + + while ($row = $this->db->sql_fetchrow($result)) + { + $user_notifications[$row['item_type']][] = $row; + } + + $this->db->sql_freeresult($result); + + return $user_notifications; + } + /** * Get global subscriptions (item_id = 0) * @@ -587,28 +617,23 @@ class manager $subscriptions = array(); - foreach ($this->get_subscription_types() as $group_name => $types) + $user_notifications = $this->get_user_notifications($user_id); + + foreach ($this->get_subscription_types() as $types) { foreach ($types as $id => $type) { - $sql = 'SELECT method, notify - FROM ' . $this->user_notifications_table . ' - WHERE user_id = ' . (int) $user_id . " - AND item_type = '" . $this->db->sql_escape($id) . "' - AND item_id = 0"; - $result = $this->db->sql_query($sql); - - $row = $this->db->sql_fetchrow($result); - if (!$row) + + if (empty($user_notifications[$id])) { // No rows at all, default to '' $subscriptions[$id] = array(''); } else { - do + foreach ($user_notifications[$id] as $user_notification) { - if (!$row['notify']) + if (!$user_notification['notify']) { continue; } @@ -618,12 +643,9 @@ class manager $subscriptions[$id] = array(); } - $subscriptions[$id][] = $row['method']; + $subscriptions[$id][] = $user_notification['method']; } - while ($row = $this->db->sql_fetchrow($result)); } - - $this->db->sql_freeresult($result); } } @@ -866,6 +888,7 @@ class manager * * @param string $notification_type_name The name * @return int the notification_type_id + * @throws \phpbb\notification\exception */ public function get_notification_type_id($notification_type_name) { |