From bafb5b0ecad7266c9641624bae2de2f3c7efe500 Mon Sep 17 00:00:00 2001 From: Nathan Guse Date: Fri, 5 Oct 2012 18:12:48 -0500 Subject: [PATCH] [ticket/11103] Starting work on combining notifications Just for posts currently and not yet outputted. PHPBB3-11103 --- phpBB/includes/notification/manager.php | 6 +++ phpBB/includes/notification/type/base.php | 2 +- phpBB/includes/notification/type/post.php | 58 +++++++++++++++++++++++ 3 files changed, 65 insertions(+), 1 deletion(-) diff --git a/phpBB/includes/notification/manager.php b/phpBB/includes/notification/manager.php index c1ae61e08a..c5fd41c901 100644 --- a/phpBB/includes/notification/manager.php +++ b/phpBB/includes/notification/manager.php @@ -660,6 +660,12 @@ class phpbb_notification_manager */ public function get_item_type_class($item_type, $data = array()) { + if (!strpos($item_type, 'notification_type_')) + { + $item_class = $this->get_item_type_class_name($item_type); + $item_type = $item_class; + } + $item = new $item_type($this, $this->db, $this->cache, $this->template, $this->extension_manager, $this->user, $this->auth, $this->config, $this->phpbb_root_path, $this->php_ext); $item->set_initial_data($data); diff --git a/phpBB/includes/notification/type/base.php b/phpBB/includes/notification/type/base.php index 2ba0dd3bf7..b72875fb85 100644 --- a/phpBB/includes/notification/type/base.php +++ b/phpBB/includes/notification/type/base.php @@ -104,7 +104,7 @@ abstract class phpbb_notification_type_base implements phpbb_notification_type_i */ protected function get_data($name) { - return (isset($this->data['data'][$name])) ? $this->data['data'][$name] : null; + return ($name === false) ? $this->data['data'] : ((isset($this->data['data'][$name])) ? $this->data['data'][$name] : null); } /** diff --git a/phpBB/includes/notification/type/post.php b/phpBB/includes/notification/type/post.php index d83ecf4fae..65b0c1adf2 100644 --- a/phpBB/includes/notification/type/post.php +++ b/phpBB/includes/notification/type/post.php @@ -132,6 +132,28 @@ class phpbb_notification_type_post extends phpbb_notification_type_base } $this->db->sql_freeresult($result); + // Try to find the users who already have been notified about replies and have not read the topic since and just update their notifications + $update_notifications = array(); + $sql = 'SELECT * + FROM ' . NOTIFICATIONS_TABLE . " + WHERE item_type = '" . self::get_item_type() . "' + AND item_parent_id = " . (int) self::get_item_parent_id($post) . ' + AND unread = 1'; + $result = $this->db->sql_query($sql); + while ($row = $this->db->sql_fetchrow($result)) + { + // Do not create a new notification + unset($notify_users[$row['user_id']]); + + $notification = $this->notification_manager->get_item_type_class(self::get_item_type(), $row); + $sql = 'UPDATE ' . NOTIFICATIONS_TABLE . ' + SET ' . $this->db->sql_build_array('UPDATE', $notification->add_responders($post)) . ' + WHERE notification_id = ' . $row['notification_id']; + echo $sql; + $this->db->sql_query($sql); + } + $this->db->sql_freeresult($result); + return $notify_users; } @@ -234,4 +256,40 @@ class phpbb_notification_type_post extends phpbb_notification_type_base return parent::create_insert_array($post); } + + /** + * Add responders to the notification + * + * @param mixed $post + */ + public function add_responders($post) + { + // Do not add them as a responder if they were the original poster that created the notification + if ($this->get_data('poster_id') == $post['poster_id']) + { + return array('data' => serialize($this->get_data(false))); + } + + $responders = $this->get_data('responders'); + + $responders = ($responders === null) ? array() : $responders; + + foreach ($responders as $responder) + { + // Do not add them as a responder multiple times + if ($responder['poster_id'] == $post['poster_id']) + { + return array('data' => serialize($this->get_data(false))); + } + } + + $responders[] = array( + 'poster_id' => $post['poster_id'], + 'username' => (($post['poster_id'] == ANONYMOUS) ? $post['post_username'] : ''), + ); + + $this->set_data('responders', $responders); + + return array('data' => serialize($this->get_data(false))); + } }