[ticket/11103] UCP Notification Options can now be set

PHPBB3-11103
This commit is contained in:
Nathan Guse 2012-09-27 18:25:37 -05:00
parent f062087f30
commit 48ccc9eb93
6 changed files with 80 additions and 19 deletions

View file

@ -5021,6 +5021,7 @@ function page_header($page_title = '', $display_online_list = true, $item_id = 0
'PRIVATE_MESSAGE_INFO' => $l_privmsgs_text,
'PRIVATE_MESSAGE_INFO_UNREAD' => $l_privmsgs_text_unread,
'NUM_UNREAD_NOTIFICATIONS' => $notifications['unread_count'],
'NOTIFICATIONS_CNT' => $user->lang('NOTIFICATIONS_CNT', $notifications['unread_count']),
'S_USER_NEW_PRIVMSG' => $user->data['user_new_privmsg'],
'S_USER_UNREAD_PRIVMSG' => $user->data['user_unread_privmsg'],

View file

@ -502,6 +502,46 @@ class phpbb_notifications_service
return $subscription_methods;
}
/**
* Get subscriptions
*
* @param bool|int $user_id The user_id to add the subscription for (bool false for current user)
* @param bool $only_global True to select only global subscription options (item_id = 0)
*
* @return array Subscriptions
*/
public function get_subscriptions($user_id = false, $only_global = false)
{
$user_id = ($user_id === false) ? $this->phpbb_container->get('user')->data['user_id'] : $user_id;
$subscriptions = array();
$sql = 'SELECT *
FROM ' . USER_NOTIFICATIONS_TABLE . '
WHERE user_id = ' . (int) $user_id .
(($only_global) ? ' AND item_id = 0' : '');
$result = $this->db->sql_query($sql);
while ($row = $this->db->sql_fetchrow($result))
{
if ($only_global)
{
if (!isset($subscriptions[$row['item_type']]))
{
$subscriptions[$row['item_type']] = array();
}
$subscriptions[$row['item_type']][] = $row['method'];
}
else
{
$subscriptions[] = $row;
}
}
$this->db->sql_freeresult($result);
return $subscriptions;
}
/**
* Add a subscription
*
@ -510,7 +550,7 @@ class phpbb_notifications_service
* @param string $method The method of the notification e.g. '', 'email', or 'jabber'
* @param bool|int $user_id The user_id to add the subscription for (bool false for current user)
*/
public function add_subscription($item_type, $item_id, $method = '', $user_id = false)
public function add_subscription($item_type, $item_id = 0, $method = '', $user_id = false)
{
$this->get_item_type_class_name($item_type);
@ -534,7 +574,7 @@ class phpbb_notifications_service
* @param string $method The method of the notification e.g. '', 'email', or 'jabber'
* @param bool|int $user_id The user_id to add the subscription for (bool false for current user)
*/
public function delete_subscription($item_type, $item_id, $method = '', $user_id = false)
public function delete_subscription($item_type, $item_id = 0, $method = '', $user_id = false)
{
$this->get_item_type_class_name($item_type);

View file

@ -28,29 +28,37 @@ class ucp_notifications
$user = $phpbb_container->get('user');
$request = $phpbb_container->get('request');
$subscriptions = $phpbb_notifications->get_subscriptions(false, true);
// Add/remove subscriptions
if ($request->is_set_post('submit'))
{
$notification_methods = $phpbb_notifications->get_subscription_methods();
foreach($phpbb_notifications->get_subscription_types() as $type)
foreach($phpbb_notifications->get_subscription_types() as $type => $data)
{
if ($request->is_set_post($type . '_notification'))
if ($request->is_set_post($type . '_notification') && !isset($subscriptions[$type]))
{
// add
$phpbb_notifications->add_subscription($type);
}
else
else if (!$request->is_set_post($type . '_notification') && isset($subscriptions[$type]))
{
// remove
$phpbb_notifications->delete_subscription($type);
}
foreach($notification_methods as $method)
{
if ($request->is_set_post($type . '_' . $method))
if ($request->is_set_post($type . '_' . $method) && (!isset($subscriptions[$type]) || !in_array($method, $subscriptions[$type])))
{
// add
$phpbb_notifications->add_subscription($type, 0, $method);
}
else
else if (!$request->is_set_post($type . '_' . $method) && isset($subscriptions[$type]) && in_array($method, $subscriptions[$type]))
{
// remove
$phpbb_notifications->delete_subscription($type, 0, $method);
}
}
}
@ -76,15 +84,29 @@ class ucp_notifications
*/
public function output_notification_types($block = 'notification_types', phpbb_notifications_service $phpbb_notifications, phpbb_template $template, phpbb_user $user)
{
$notification_methods = $phpbb_notifications->get_subscription_methods();
$subscriptions = $phpbb_notifications->get_subscriptions(false, true);
foreach($phpbb_notifications->get_subscription_types() as $type => $data)
{
$template->assign_block_vars($block, array(
'TYPE' => $type,
'NAME' => (isset($data['lang'])) ? $user->lang($data['lang']) : $user->lang('NOTIFICATION_TYPE_' . strtoupper($type)),
'NAME' => (is_array($data) && isset($data['lang'])) ? $user->lang($data['lang']) : $user->lang('NOTIFICATION_TYPE_' . strtoupper($type)),
'SUBSCRIBED' => (isset($subscriptions[$type])) ? true : false,
));
$this->output_notification_methods($block . '.notification_methods', $phpbb_notifications, $template, $user);
foreach($notification_methods as $method)
{
$template->assign_block_vars($block . '.notification_methods', array(
'METHOD' => $method,
'NAME' => $user->lang('NOTIFICATION_METHOD_' . strtoupper($method)),
'SUBSCRIBED' => (isset($subscriptions[$type]) && in_array($method, $subscriptions[$type])) ? true : false,
));
}
}
}
@ -98,12 +120,7 @@ class ucp_notifications
*/
public function output_notification_methods($block = 'notification_methods', phpbb_notifications_service $phpbb_notifications, phpbb_template $template, phpbb_user $user)
{
static $notification_methods = false;
if ($notification_methods === false)
{
$notification_methods = $phpbb_notifications->get_subscription_methods();
}
$notification_methods = $phpbb_notifications->get_subscription_methods();
foreach($notification_methods as $method)
{

View file

@ -386,7 +386,10 @@ $lang = array_merge($lang, array(
'NOT_AUTHORISED' => 'You are not authorised to access this area.',
'NOT_WATCHING_FORUM' => 'You are no longer subscribed to updates on this forum.',
'NOT_WATCHING_TOPIC' => 'You are no longer subscribed to this topic.',
'NOTIFICATIONS' => 'Notifications',
'NOTIFICATIONS_CNT' => array(
1 => '%d Notification',
2 => '%d 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_POST' => '%1$s replied to the topic "%2$s".',

View file

@ -131,7 +131,7 @@
<!-- IF not S_IS_BOT and S_USER_LOGGED_IN -->
<ul class="linklist leftside">
<li>
[ <a href="#" id="notification_list_button" title="{L_NOTIFICATIONS}">{NUM_UNREAD_NOTIFICATIONS} {L_NOTIFICATIONS}</a> ] &bull;
[ <a href="#" id="notification_list_button" title="{NOTIFICATIONS_CNT}">{NOTIFICATIONS_CNT}</a> ] &bull;
<div id="notification_list">
<ul class="topiclist forums">
<!-- BEGIN notifications -->

View file

@ -24,9 +24,9 @@
{notification_types.NAME}
</dt>
<!-- BEGIN notification_methods -->
<dd class="mark"><input type="checkbox" name="{notification_types.TYPE}_{notification_methods.METHOD}" /> <dfn>{notification_methods.NAME}</dfn></dd>
<dd class="mark"><input type="checkbox" name="{notification_types.TYPE}_{notification_methods.METHOD}"<!-- IF notification_methods.SUBSCRIBED --> checked="checked"<!-- ENDIF --> /> <dfn>{notification_methods.NAME}</dfn></dd>
<!-- END notification_methods -->
<dd class="mark"><input type="checkbox" name="{notification_types.TYPE}_notification" /> <dfn>{notification_methods.NAME}</dfn></dd>
<dd class="mark"><input type="checkbox" name="{notification_types.TYPE}_notification"<!-- IF notification_types.SUBSCRIBED --> checked="checked"<!-- ENDIF --> /> <dfn>{notification_methods.NAME}</dfn></dd>
</dl>
</li>
<!-- END notification_types -->