aboutsummaryrefslogtreecommitdiffstats
path: root/phpBB/includes/notifications/service.php
diff options
context:
space:
mode:
authorNathan Guse <nathaniel.guse@gmail.com>2012-09-14 15:59:13 -0500
committerNathan Guse <nathaniel.guse@gmail.com>2012-09-14 15:59:13 -0500
commitfb0ed78c8fffe95d40e47c8dd27d44973eba88ae (patch)
tree663a972c5eb324d14855a4a51579d6aaf154c0ab /phpBB/includes/notifications/service.php
parent44aa773ce07d81d4585f3a24a728f9b445c4c098 (diff)
downloadforums-fb0ed78c8fffe95d40e47c8dd27d44973eba88ae.tar
forums-fb0ed78c8fffe95d40e47c8dd27d44973eba88ae.tar.gz
forums-fb0ed78c8fffe95d40e47c8dd27d44973eba88ae.tar.bz2
forums-fb0ed78c8fffe95d40e47c8dd27d44973eba88ae.tar.xz
forums-fb0ed78c8fffe95d40e47c8dd27d44973eba88ae.zip
[ticket/11103] Store the item's parent id for marking things read
Mark topics/posts read from the markread() function. Identify unread items by a grey background in the header (for now) PHPBB3-11103
Diffstat (limited to 'phpBB/includes/notifications/service.php')
-rw-r--r--phpBB/includes/notifications/service.php51
1 files changed, 48 insertions, 3 deletions
diff --git a/phpBB/includes/notifications/service.php b/phpBB/includes/notifications/service.php
index 10af5b349b..8be8ae2a95 100644
--- a/phpBB/includes/notifications/service.php
+++ b/phpBB/includes/notifications/service.php
@@ -107,6 +107,52 @@ class phpbb_notifications_service
}
/**
+ * Mark notifications read
+ *
+ * @param string $item_type item type
+ * @param bool|int|array $item_id Item id or array of item ids. False to mark read for all item ids
+ * @param bool|int|array $user_id User id or array of user ids. False to mark read for all user ids
+ * @param bool|int $time Time at which to mark all notifications prior to as read. False to mark all as read. (Default: False)
+ */
+ public function mark_notifications_read($item_type, $item_id, $user_id, $time = false)
+ {
+ $time = ($time) ?: time();
+
+ $this->get_item_type_class_name($item_type);
+
+ $sql = 'UPDATE ' . NOTIFICATIONS_TABLE . "
+ SET unread = 0
+ WHERE item_type = '" . $this->db->sql_escape($item_type) . "'
+ AND time <= " . $time .
+ (($item_id !== false) ? ' AND ' . (is_array($item_id) ? $this->db->sql_in_set('item_id', $item_id) : 'item_id = ' . (int) $item_id) : '') .
+ (($user_id !== false) ? ' AND ' . (is_array($user_id) ? $this->db->sql_in_set('user_id', $user_id) : 'user_id = ' . (int) $user_id) : '');
+ $this->db->sql_query($sql);
+ }
+
+ /**
+ * Mark notifications read from a parent identifier
+ *
+ * @param string $item_type item type
+ * @param bool|int|array $item_parent_id Item parent id or array of item parent ids. False to mark read for all item parent ids
+ * @param bool|int|array $user_id User id or array of user ids. False to mark read for all user ids
+ * @param bool|int $time Time at which to mark all notifications prior to as read. False to mark all as read. (Default: False)
+ */
+ public function mark_notifications_read_by_parent($item_type, $item_parent_id, $user_id, $time = false)
+ {
+ $time = ($time) ?: time();
+
+ $item_type_class_name = $this->get_item_type_class_name($item_type);
+
+ $sql = 'UPDATE ' . NOTIFICATIONS_TABLE . "
+ SET unread = 0
+ WHERE item_type = '" . $this->db->sql_escape($item_type) . "'
+ AND time <= " . $time .
+ (($item_parent_id !== false) ? ' AND ' . (is_array($item_parent_id) ? $this->db->sql_in_set('item_parent_id', $item_parent_id) : 'item_parent_id = ' . (int) $item_parent_id) : '') .
+ (($user_id !== false) ? ' AND ' . (is_array($user_id) ? $this->db->sql_in_set('user_id', $user_id) : 'user_id = ' . (int) $user_id) : '');
+ $this->db->sql_query($sql);
+ }
+
+ /**
* Add a notification
*
* @param string $item_type Type identifier
@@ -118,9 +164,6 @@ class phpbb_notifications_service
$item_id = $item_type_class_name::get_item_id($data);
- // Update any existing notifications for this item
- $this->update_notifications($item_type, $data);
-
// find out which users want to receive this type of notification
$notify_users = $item_type_class_name::find_users_for_notification($this->phpbb_container, $data);
@@ -250,6 +293,8 @@ class phpbb_notifications_service
*/
public function delete_notifications($item_type, $item_id)
{
+ $this->get_item_type_class_name($item_type);
+
$sql = 'DELETE FROM ' . NOTIFICATIONS_TABLE . "
WHERE item_type = '" . $this->db->sql_escape($item_type) . "'
AND " . (is_array($item_id) ? $this->db->sql_in_set('item_id', $item_id) : 'item_id = ' . (int) $item_id);