aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNathan Guse <nathaniel.guse@gmail.com>2012-10-05 18:12:48 -0500
committerNathan Guse <nathaniel.guse@gmail.com>2012-10-05 18:12:48 -0500
commitbafb5b0ecad7266c9641624bae2de2f3c7efe500 (patch)
tree8b9e2373ace5fa257ee3d778058d4e308f178704
parent6ca2256f77f6795c2c5895e45fd366eccd160da6 (diff)
downloadforums-bafb5b0ecad7266c9641624bae2de2f3c7efe500.tar
forums-bafb5b0ecad7266c9641624bae2de2f3c7efe500.tar.gz
forums-bafb5b0ecad7266c9641624bae2de2f3c7efe500.tar.bz2
forums-bafb5b0ecad7266c9641624bae2de2f3c7efe500.tar.xz
forums-bafb5b0ecad7266c9641624bae2de2f3c7efe500.zip
[ticket/11103] Starting work on combining notifications
Just for posts currently and not yet outputted. PHPBB3-11103
-rw-r--r--phpBB/includes/notification/manager.php6
-rw-r--r--phpBB/includes/notification/type/base.php2
-rw-r--r--phpBB/includes/notification/type/post.php58
3 files changed, 65 insertions, 1 deletions
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)));
+ }
}