mirror of
https://github.com/phpbb/phpbb.git
synced 2025-06-28 06:08:52 +00:00
[ticket/11103] Add/Update/Mark Read functions accept an array for the type
This saves a lot of code in some areas (where the same data is sent, just for different types) Notifications for bookmarks PHPBB3-11103
This commit is contained in:
parent
1ab0c469e2
commit
ed1ec8e720
8 changed files with 178 additions and 76 deletions
|
@ -1351,8 +1351,7 @@ function markread($mode, $forum_id = false, $topic_id = false, $post_time = 0, $
|
||||||
}
|
}
|
||||||
$db->sql_freeresult($result);
|
$db->sql_freeresult($result);
|
||||||
|
|
||||||
$notifications->mark_notifications_read_by_parent('post', $topic_ids, $user->data['user_id'], $post_time);
|
$notifications->mark_notifications_read_by_parent(array('quote', 'bookmark', 'post'), $topic_ids, $user->data['user_id'], $post_time);
|
||||||
$notifications->mark_notifications_read_by_parent('quote', $topic_ids, $user->data['user_id'], $post_time);
|
|
||||||
|
|
||||||
// Add 0 to forums array to mark global announcements correctly
|
// Add 0 to forums array to mark global announcements correctly
|
||||||
// $forum_id[] = 0;
|
// $forum_id[] = 0;
|
||||||
|
@ -1450,8 +1449,7 @@ function markread($mode, $forum_id = false, $topic_id = false, $post_time = 0, $
|
||||||
|
|
||||||
// Mark post notifications read for this user in this topic
|
// Mark post notifications read for this user in this topic
|
||||||
$notifications = $phpbb_container->get('notifications');
|
$notifications = $phpbb_container->get('notifications');
|
||||||
$notifications->mark_notifications_read_by_parent('post', $topic_id, $user->data['user_id'], $post_time);
|
$notifications->mark_notifications_read_by_parent(array('quote', 'bookmark', 'post'), $topic_id, $user->data['user_id'], $post_time);
|
||||||
$notifications->mark_notifications_read_by_parent('quote', $topic_id, $user->data['user_id'], $post_time);
|
|
||||||
|
|
||||||
if ($config['load_db_lastread'] && $user->data['is_registered'])
|
if ($config['load_db_lastread'] && $user->data['is_registered'])
|
||||||
{
|
{
|
||||||
|
|
|
@ -2227,20 +2227,14 @@ function submit_post($mode, $subject, $username, $topic_type, &$poll, &$data, $u
|
||||||
switch ($mode)
|
switch ($mode)
|
||||||
{
|
{
|
||||||
case 'post' :
|
case 'post' :
|
||||||
$notifications->add_notifications('topic', array_merge($data, array(
|
$notifications->add_notifications(array('topic', 'quote'), array_merge($data, array(
|
||||||
'post_username' => $username,
|
|
||||||
)));
|
|
||||||
$notifications->add_notifications('quote', array_merge($data, array(
|
|
||||||
'post_username' => $username,
|
'post_username' => $username,
|
||||||
)));
|
)));
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'reply' :
|
case 'reply' :
|
||||||
case 'quote' :
|
case 'quote' :
|
||||||
$notifications->add_notifications('post', array_merge($data, array(
|
$notifications->add_notifications(array('quote', 'bookmark', 'post'), array_merge($data, array(
|
||||||
'post_username' => $username,
|
|
||||||
)));
|
|
||||||
$notifications->add_notifications('quote', array_merge($data, array(
|
|
||||||
'post_username' => $username,
|
'post_username' => $username,
|
||||||
)));
|
)));
|
||||||
break;
|
break;
|
||||||
|
@ -2253,10 +2247,8 @@ function submit_post($mode, $subject, $username, $topic_type, &$poll, &$data, $u
|
||||||
'post_username' => $username,
|
'post_username' => $username,
|
||||||
'topic_title' => $subject,
|
'topic_title' => $subject,
|
||||||
)));
|
)));
|
||||||
$notifications->update_notifications('post', array_merge($data, array(
|
|
||||||
'post_username' => $username,
|
$notifications->update_notifications(array('quote', 'bookmark', 'post'), array_merge($data, array(
|
||||||
)));
|
|
||||||
$notifications->update_notifications('quote', array_merge($data, array(
|
|
||||||
'post_username' => $username,
|
'post_username' => $username,
|
||||||
)));
|
)));
|
||||||
break;
|
break;
|
||||||
|
|
|
@ -646,7 +646,7 @@ function approve_post($post_id_list, $id, $mode)
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// Topic Notifications
|
// Topic Notifications
|
||||||
$notifications->add_notifications('post', $post_data);
|
$notifications->add_notifications(array('quote', 'bookmark', 'post'), $post_data);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -109,13 +109,23 @@ class phpbb_notifications_service
|
||||||
/**
|
/**
|
||||||
* Mark notifications read
|
* Mark notifications read
|
||||||
*
|
*
|
||||||
* @param string $item_type item type
|
* @param string|array $item_type Type identifier or array of item types (only acceptable if the $data is identical for the specified types)
|
||||||
* @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 $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|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)
|
* @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)
|
public function mark_notifications_read($item_type, $item_id, $user_id, $time = false)
|
||||||
{
|
{
|
||||||
|
if (is_array($item_type))
|
||||||
|
{
|
||||||
|
foreach ($item_type as $type)
|
||||||
|
{
|
||||||
|
$this->mark_notifications_read($type, $item_id, $user_id, $time);
|
||||||
|
}
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
$time = ($time) ?: time();
|
$time = ($time) ?: time();
|
||||||
|
|
||||||
$this->get_item_type_class_name($item_type);
|
$this->get_item_type_class_name($item_type);
|
||||||
|
@ -132,13 +142,23 @@ class phpbb_notifications_service
|
||||||
/**
|
/**
|
||||||
* Mark notifications read from a parent identifier
|
* Mark notifications read from a parent identifier
|
||||||
*
|
*
|
||||||
* @param string $item_type item type
|
* @param string|array $item_type Type identifier or array of item types (only acceptable if the $data is identical for the specified types)
|
||||||
* @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 $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|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)
|
* @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)
|
public function mark_notifications_read_by_parent($item_type, $item_parent_id, $user_id, $time = false)
|
||||||
{
|
{
|
||||||
|
if (is_array($item_type))
|
||||||
|
{
|
||||||
|
foreach ($item_type as $type)
|
||||||
|
{
|
||||||
|
$this->mark_notifications_read($type, $item_id, $user_id, $time);
|
||||||
|
}
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
$time = ($time) ?: time();
|
$time = ($time) ?: time();
|
||||||
|
|
||||||
$item_type_class_name = $this->get_item_type_class_name($item_type);
|
$item_type_class_name = $this->get_item_type_class_name($item_type);
|
||||||
|
@ -155,11 +175,21 @@ class phpbb_notifications_service
|
||||||
/**
|
/**
|
||||||
* Add a notification
|
* Add a notification
|
||||||
*
|
*
|
||||||
* @param string $item_type Type identifier
|
* @param string|array $item_type Type identifier or array of item types (only acceptable if the $data is identical for the specified types)
|
||||||
* @param array $data Data specific for this type that will be inserted
|
* @param array $data Data specific for this type that will be inserted
|
||||||
*/
|
*/
|
||||||
public function add_notifications($item_type, $data)
|
public function add_notifications($item_type, $data)
|
||||||
{
|
{
|
||||||
|
if (is_array($item_type))
|
||||||
|
{
|
||||||
|
foreach ($item_type as $type)
|
||||||
|
{
|
||||||
|
$this->add_notifications($type, $data);
|
||||||
|
}
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
$item_type_class_name = $this->get_item_type_class_name($item_type);
|
$item_type_class_name = $this->get_item_type_class_name($item_type);
|
||||||
|
|
||||||
$item_id = $item_type_class_name::get_item_id($data);
|
$item_id = $item_type_class_name::get_item_id($data);
|
||||||
|
@ -173,12 +203,22 @@ class phpbb_notifications_service
|
||||||
/**
|
/**
|
||||||
* Add a notification for specific users
|
* Add a notification for specific users
|
||||||
*
|
*
|
||||||
* @param string $item_type Type identifier
|
* @param string|array $item_type Type identifier or array of item types (only acceptable if the $data is identical for the specified types)
|
||||||
* @param array $data Data specific for this type that will be inserted
|
* @param array $data Data specific for this type that will be inserted
|
||||||
* @param array $notify_users User list to notify
|
* @param array $notify_users User list to notify
|
||||||
*/
|
*/
|
||||||
public function add_notifications_for_users($item_type, $data, $notify_users)
|
public function add_notifications_for_users($item_type, $data, $notify_users)
|
||||||
{
|
{
|
||||||
|
if (is_array($item_type))
|
||||||
|
{
|
||||||
|
foreach ($item_type as $type)
|
||||||
|
{
|
||||||
|
$this->add_notifications($type, $data);
|
||||||
|
}
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
$item_type_class_name = $this->get_item_type_class_name($item_type);
|
$item_type_class_name = $this->get_item_type_class_name($item_type);
|
||||||
|
|
||||||
$item_id = $item_type_class_name::get_item_id($data);
|
$item_id = $item_type_class_name::get_item_id($data);
|
||||||
|
@ -255,11 +295,21 @@ class phpbb_notifications_service
|
||||||
/**
|
/**
|
||||||
* Update a notification
|
* Update a notification
|
||||||
*
|
*
|
||||||
* @param string $item_type Type identifier
|
* @param string|array $item_type Type identifier or array of item types (only acceptable if the $data is identical for the specified types)
|
||||||
* @param array $data Data specific for this type that will be updated
|
* @param array $data Data specific for this type that will be updated
|
||||||
*/
|
*/
|
||||||
public function update_notifications($item_type, $data)
|
public function update_notifications($item_type, $data)
|
||||||
{
|
{
|
||||||
|
if (is_array($item_type))
|
||||||
|
{
|
||||||
|
foreach ($item_type as $type)
|
||||||
|
{
|
||||||
|
$this->add_notifications($type, $data);
|
||||||
|
}
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
$item_type_class_name = $this->get_item_type_class_name($item_type);
|
$item_type_class_name = $this->get_item_type_class_name($item_type);
|
||||||
|
|
||||||
// Allow the notifications class to over-ride the update_notifications functionality
|
// Allow the notifications class to over-ride the update_notifications functionality
|
||||||
|
|
92
phpBB/includes/notifications/type/bookmark.php
Normal file
92
phpBB/includes/notifications/type/bookmark.php
Normal file
|
@ -0,0 +1,92 @@
|
||||||
|
<?php
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @package notifications
|
||||||
|
* @copyright (c) 2012 phpBB Group
|
||||||
|
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @ignore
|
||||||
|
*/
|
||||||
|
if (!defined('IN_PHPBB'))
|
||||||
|
{
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Bookmark updating notifications class
|
||||||
|
* This class handles notifications for replies to a bookmarked topic
|
||||||
|
*
|
||||||
|
* @package notifications
|
||||||
|
*/
|
||||||
|
class phpbb_notifications_type_bookmark extends phpbb_notifications_type_post
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Language key used to output the text
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
protected $language_key = 'NOTIFICATION_BOOKMARK';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the type of notification this is
|
||||||
|
* phpbb_notifications_type_
|
||||||
|
*/
|
||||||
|
public static function get_item_type()
|
||||||
|
{
|
||||||
|
return 'bookmark';
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Find the users who want to receive notifications
|
||||||
|
*
|
||||||
|
* @param ContainerBuilder $phpbb_container
|
||||||
|
* @param array $post Data from
|
||||||
|
*
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public static function find_users_for_notification(ContainerBuilder $phpbb_container, $post)
|
||||||
|
{
|
||||||
|
$db = $phpbb_container->get('dbal.conn');
|
||||||
|
|
||||||
|
$users = array();
|
||||||
|
|
||||||
|
/* todo
|
||||||
|
* find what type of notification they'd like to receive
|
||||||
|
*/
|
||||||
|
$sql = 'SELECT user_id
|
||||||
|
FROM ' . BOOKMARKS_TABLE . '
|
||||||
|
WHERE ' . $db->sql_in_set('topic_id', $post['topic_id']);
|
||||||
|
$result = $db->sql_query($sql);
|
||||||
|
while ($row = $db->sql_fetchrow($result))
|
||||||
|
{
|
||||||
|
$users[$row['user_id']] = array('');
|
||||||
|
}
|
||||||
|
$db->sql_freeresult($result);
|
||||||
|
|
||||||
|
if (empty($users))
|
||||||
|
{
|
||||||
|
return array();
|
||||||
|
}
|
||||||
|
|
||||||
|
$auth_read = $phpbb_container->get('auth')->acl_get_list(array_keys($users), 'f_read', $post['forum_id']);
|
||||||
|
|
||||||
|
if (empty($auth_read))
|
||||||
|
{
|
||||||
|
return array();
|
||||||
|
}
|
||||||
|
|
||||||
|
$notify_users = array();
|
||||||
|
|
||||||
|
foreach ($auth_read[$post['forum_id']]['f_read'] as $user_id)
|
||||||
|
{
|
||||||
|
$notify_users[$user_id] = $users[$user_id];
|
||||||
|
}
|
||||||
|
|
||||||
|
return $notify_users;
|
||||||
|
}
|
||||||
|
}
|
|
@ -25,6 +25,13 @@ if (!defined('IN_PHPBB'))
|
||||||
*/
|
*/
|
||||||
class phpbb_notifications_type_post extends phpbb_notifications_type_base
|
class phpbb_notifications_type_post extends phpbb_notifications_type_base
|
||||||
{
|
{
|
||||||
|
/**
|
||||||
|
* Language key used to output the text
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
protected $language_key = 'NOTIFICATION_POST';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the type of notification this is
|
* Get the type of notification this is
|
||||||
* phpbb_notifications_type_
|
* phpbb_notifications_type_
|
||||||
|
@ -136,7 +143,7 @@ class phpbb_notifications_type_post extends phpbb_notifications_type_base
|
||||||
}
|
}
|
||||||
|
|
||||||
return $this->phpbb_container->get('user')->lang(
|
return $this->phpbb_container->get('user')->lang(
|
||||||
'NOTIFICATION_POST',
|
$this->language_key,
|
||||||
$username,
|
$username,
|
||||||
censor_text($this->get_data('topic_title'))
|
censor_text($this->get_data('topic_title'))
|
||||||
);
|
);
|
||||||
|
@ -161,7 +168,7 @@ class phpbb_notifications_type_post extends phpbb_notifications_type_base
|
||||||
}
|
}
|
||||||
|
|
||||||
return $this->phpbb_container->get('user')->lang(
|
return $this->phpbb_container->get('user')->lang(
|
||||||
'NOTIFICATION_POST',
|
$this->language_key,
|
||||||
$username,
|
$username,
|
||||||
censor_text($this->get_data('topic_title'))
|
censor_text($this->get_data('topic_title'))
|
||||||
);
|
);
|
||||||
|
|
|
@ -18,15 +18,27 @@ if (!defined('IN_PHPBB'))
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Post tagging notifications class
|
* Post quoting notifications class
|
||||||
* This class handles notifications for tagging users in a post (ex: @EXreaction)
|
* This class handles notifications for quoting users in a post
|
||||||
*
|
*
|
||||||
* @package notifications
|
* @package notifications
|
||||||
*/
|
*/
|
||||||
class phpbb_notifications_type_quote extends phpbb_notifications_type_post
|
class phpbb_notifications_type_quote extends phpbb_notifications_type_post
|
||||||
{
|
{
|
||||||
|
/**
|
||||||
|
* regular expression to match to find usernames
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
protected static $regular_expression_match = '#\[quote="(.+?)":#';
|
protected static $regular_expression_match = '#\[quote="(.+?)":#';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Language key used to output the text
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
protected $language_key = 'NOTIFICATION_QUOTE';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the type of notification this is
|
* Get the type of notification this is
|
||||||
* phpbb_notifications_type_
|
* phpbb_notifications_type_
|
||||||
|
@ -97,56 +109,6 @@ class phpbb_notifications_type_quote extends phpbb_notifications_type_post
|
||||||
return $notify_users;
|
return $notify_users;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Get the HTML formatted title of this notification
|
|
||||||
*
|
|
||||||
* @return string
|
|
||||||
*/
|
|
||||||
public function get_formatted_title()
|
|
||||||
{
|
|
||||||
if ($this->get_data('post_username'))
|
|
||||||
{
|
|
||||||
$username = $this->get_data('post_username');
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
$user_data = $this->service->get_user($this->get_data('poster_id'));
|
|
||||||
|
|
||||||
$username = get_username_string('no_profile', $user_data['user_id'], $user_data['username'], $user_data['user_colour']);
|
|
||||||
}
|
|
||||||
|
|
||||||
return $this->phpbb_container->get('user')->lang(
|
|
||||||
'NOTIFICATION_QUOTE',
|
|
||||||
$username,
|
|
||||||
censor_text($this->get_data('topic_title'))
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get the title of this notification
|
|
||||||
*
|
|
||||||
* @return string
|
|
||||||
*/
|
|
||||||
public function get_title()
|
|
||||||
{
|
|
||||||
if ($this->get_data('post_username'))
|
|
||||||
{
|
|
||||||
$username = $this->get_data('post_username');
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
$user_data = $this->service->get_user($this->get_data('poster_id'));
|
|
||||||
|
|
||||||
$username = $user_data['username'];
|
|
||||||
}
|
|
||||||
|
|
||||||
return $this->phpbb_container->get('user')->lang(
|
|
||||||
'NOTIFICATION_QUOTE',
|
|
||||||
$username,
|
|
||||||
censor_text($this->get_data('topic_title'))
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Update a notification
|
* Update a notification
|
||||||
*
|
*
|
||||||
|
|
|
@ -386,6 +386,7 @@ $lang = array_merge($lang, array(
|
||||||
'NOT_WATCHING_FORUM' => 'You are no longer subscribed to updates on this forum.',
|
'NOT_WATCHING_FORUM' => 'You are no longer subscribed to updates on this forum.',
|
||||||
'NOT_WATCHING_TOPIC' => 'You are no longer subscribed to this topic.',
|
'NOT_WATCHING_TOPIC' => 'You are no longer subscribed to this topic.',
|
||||||
'NOTIFICATIONS' => '[ Notifications ]',
|
'NOTIFICATIONS' => '[ Notifications ]',
|
||||||
|
'NOTIFICATION_BOOKMARK' => '%1$s replied to the topic "%2$s" you have bookmarked.',
|
||||||
'NOTIFICATION_PM' => '%1$s sent you a Private Message "%2$s".',
|
'NOTIFICATION_PM' => '%1$s sent you a Private Message "%2$s".',
|
||||||
'NOTIFICATION_POST' => '%1$s replied to the topic "%2$s".',
|
'NOTIFICATION_POST' => '%1$s replied to the topic "%2$s".',
|
||||||
'NOTIFICATION_QUOTE' => '%1$s quoted you in the post "%2$s".',
|
'NOTIFICATION_QUOTE' => '%1$s quoted you in the post "%2$s".',
|
||||||
|
|
Loading…
Add table
Reference in a new issue