mirror of
https://github.com/phpbb/phpbb.git
synced 2025-06-28 14:18:52 +00:00
[ticket/11103] UCP Notification List
PHPBB3-11103
This commit is contained in:
parent
441e389123
commit
cb93784126
10 changed files with 213 additions and 46 deletions
|
@ -68,6 +68,7 @@ class phpbb_notification_manager
|
|||
'start' => 0,
|
||||
'all_unread' => false,
|
||||
'count_unread' => false,
|
||||
'count_total' => false,
|
||||
), $options);
|
||||
|
||||
// If all_unread, count_unread mus be true
|
||||
|
@ -79,12 +80,13 @@ class phpbb_notification_manager
|
|||
return array(
|
||||
'notifications' => array(),
|
||||
'unread_count' => 0,
|
||||
'total_count' => 0,
|
||||
);
|
||||
}
|
||||
|
||||
$notifications = $user_ids = array();
|
||||
$load_special = array();
|
||||
$count = 0;
|
||||
$total_count = $unread_count = 0;
|
||||
|
||||
if ($options['count_unread'])
|
||||
{
|
||||
|
@ -94,7 +96,18 @@ class phpbb_notification_manager
|
|||
WHERE user_id = ' . (int) $options['user_id'] . '
|
||||
AND unread = 1';
|
||||
$result = $this->db->sql_query($sql);
|
||||
$count = (int) $this->db->sql_fetchfield('count', $result);
|
||||
$unread_count = (int) $this->db->sql_fetchfield('count', $result);
|
||||
$this->db->sql_freeresult($result);
|
||||
}
|
||||
|
||||
if ($options['count_total'])
|
||||
{
|
||||
// Get the total number of notifications
|
||||
$sql = 'SELECT COUNT(*) AS count
|
||||
FROM ' . NOTIFICATIONS_TABLE . '
|
||||
WHERE user_id = ' . (int) $options['user_id'];
|
||||
$result = $this->db->sql_query($sql);
|
||||
$total_count = (int) $this->db->sql_fetchfield('count', $result);
|
||||
$this->db->sql_freeresult($result);
|
||||
}
|
||||
|
||||
|
@ -115,7 +128,7 @@ class phpbb_notification_manager
|
|||
$this->db->sql_freeresult($result);
|
||||
|
||||
// Get all unread notifications
|
||||
if ($count && $options['all_unread'] && !empty($rowset))
|
||||
if ($unread_count && $options['all_unread'] && !empty($rowset))
|
||||
{
|
||||
$sql = 'SELECT *
|
||||
FROM ' . NOTIFICATIONS_TABLE . '
|
||||
|
@ -165,14 +178,15 @@ class phpbb_notification_manager
|
|||
|
||||
return array(
|
||||
'notifications' => $notifications,
|
||||
'unread_count' => $count,
|
||||
'unread_count' => $unread_count,
|
||||
'total_count' => $total_count,
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Mark notifications read
|
||||
*
|
||||
* @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|string|array $item_type Type identifier or array of item types (only acceptable if the $data is identical for the specified types). False to mark read for all item 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 $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)
|
||||
|
@ -191,12 +205,15 @@ class phpbb_notification_manager
|
|||
|
||||
$time = ($time) ?: time();
|
||||
|
||||
$this->get_item_type_class_name($item_type);
|
||||
if ($item_type !== false)
|
||||
{
|
||||
$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 .
|
||||
WHERE time <= " . $time .
|
||||
(($item_type !== false) ? ' AND ' . (is_array($item_type) ? $this->db->sql_in_set('item_type', $item_type) : " item_type = '" . $this->db->sql_escape($item_type) . "'") : '') .
|
||||
(($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);
|
||||
|
|
|
@ -124,6 +124,8 @@ abstract class phpbb_notification_type_base implements phpbb_notification_type_i
|
|||
public function prepare_for_display()
|
||||
{
|
||||
return array(
|
||||
'NOTIFICATION_ID' => $this->notification_id,
|
||||
|
||||
'AVATAR' => $this->get_avatar(),
|
||||
|
||||
'FORMATTED_TITLE' => $this->get_title(),
|
||||
|
@ -344,6 +346,8 @@ abstract class phpbb_notification_type_base implements phpbb_notification_type_i
|
|||
*/
|
||||
protected function mark($unread = true, $return = false)
|
||||
{
|
||||
$this->unread = (bool) $unread;
|
||||
|
||||
$where = array(
|
||||
'item_type = ' . $this->db->sql_escape($this->item_type),
|
||||
'item_id = ' . (int) $this->item_id,
|
||||
|
@ -357,7 +361,7 @@ abstract class phpbb_notification_type_base implements phpbb_notification_type_i
|
|||
}
|
||||
|
||||
$sql = 'UPDATE ' . NOTIFICATIONS_TABLE . '
|
||||
SET unread = ' . (bool) $unread . '
|
||||
SET unread = ' . $this->unread . '
|
||||
WHERE ' . $where;
|
||||
$this->db->sql_query($sql);
|
||||
}
|
||||
|
|
|
@ -20,6 +20,7 @@ class ucp_notifications_info
|
|||
'version' => '1.0.0',
|
||||
'modes' => array(
|
||||
'notification_options' => array('title' => 'UCP_NOTIFICATION_OPTIONS', 'auth' => '', 'cat' => array('UCP_PREFS')),
|
||||
'notification_list' => array('title' => 'UCP_NOTIFICATION_LIST', 'auth' => '', 'cat' => array('UCP_MAIN')),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
|
|
@ -21,9 +21,13 @@ class ucp_notifications
|
|||
|
||||
public function main($id, $mode)
|
||||
{
|
||||
global $template, $user, $request, $phpbb_notifications;
|
||||
global $config, $template, $user, $request, $phpbb_notifications;
|
||||
global $phpbb_root_path, $phpEx;
|
||||
|
||||
add_form_key('ucp_notification_options');
|
||||
add_form_key('ucp_notification');
|
||||
|
||||
$start = request_var('start', 0);
|
||||
$form_time = min(request_var('form_time', 0), time());
|
||||
|
||||
switch ($mode)
|
||||
{
|
||||
|
@ -33,7 +37,7 @@ class ucp_notifications
|
|||
// Add/remove subscriptions
|
||||
if ($request->is_set_post('submit'))
|
||||
{
|
||||
if (!check_form_key('ucp_notification_options'))
|
||||
if (!check_form_key('ucp_notification'))
|
||||
{
|
||||
trigger_error('FORM_INVALID');
|
||||
}
|
||||
|
@ -79,12 +83,80 @@ class ucp_notifications
|
|||
$this->output_notification_types('notification_types', $phpbb_notifications, $template, $user);
|
||||
|
||||
$this->tpl_name = 'ucp_notifications';
|
||||
$this->page_title = 'UCP_NOTIFICATIONS';
|
||||
$this->page_title = 'UCP_NOTIFICATION_OPTIONS';
|
||||
break;
|
||||
|
||||
case 'notification_list':
|
||||
default:
|
||||
//$phpbb_notifications->load_notifications();
|
||||
// Mark all items read
|
||||
if (request_var('mark', '') == 'all' && (confirm_box(true) || check_link_hash(request_var('token', ''), 'mark_all_notifications_read')))
|
||||
{
|
||||
if (confirm_box(true))
|
||||
{
|
||||
$phpbb_notifications->mark_notifications_read(false, false, $user->data['user_id'], $form_time);
|
||||
|
||||
meta_refresh(3, $this->u_action);
|
||||
$message = $user->lang['NOTIFICATIONS_MARK_ALL_READ_SUCCESS'] . '<br /><br />' . sprintf($user->lang['RETURN_UCP'], '<a href="' . $this->u_action . '">', '</a>');
|
||||
trigger_error($message);
|
||||
}
|
||||
else
|
||||
{
|
||||
confirm_box(false, 'NOTIFICATIONS_MARK_ALL_READ', build_hidden_fields(array(
|
||||
'mark' => 'all',
|
||||
'form_time' => $form_time,
|
||||
)));
|
||||
}
|
||||
}
|
||||
|
||||
// Mark specific notifications read
|
||||
if ($request->is_set_post('submit'))
|
||||
{
|
||||
if (!check_form_key('ucp_notification'))
|
||||
{
|
||||
trigger_error('FORM_INVALID');
|
||||
}
|
||||
|
||||
$mark_read = request_var('mark', array(0));
|
||||
|
||||
if (!empty($mark_read))
|
||||
{
|
||||
$phpbb_notifications->mark_notifications_read_by_id($mark_read, $form_time);
|
||||
}
|
||||
}
|
||||
|
||||
$notifications = $phpbb_notifications->load_notifications(array(
|
||||
'start' => $start,
|
||||
'limit' => $config['topics_per_page'],
|
||||
'count_total' => true,
|
||||
));
|
||||
|
||||
foreach ($notifications['notifications'] as $notification)
|
||||
{
|
||||
$template->assign_block_vars('notification_list', $notification->prepare_for_display());
|
||||
}
|
||||
|
||||
$base_url = append_sid("{$phpbb_root_path}ucp.$phpEx", "i=ucp_notifications&mode=notification_list");
|
||||
phpbb_generate_template_pagination($template, $base_url, 'pagination', 'start', $notifications['total_count'], $config['topics_per_page'], $start);
|
||||
|
||||
$template->assign_vars(array(
|
||||
'PAGE_NUMBER' => phpbb_on_page($template, $user, $base_url, $notifications['total_count'], $config['topics_per_page'], $start),
|
||||
'TOTAL_COUNT' => $user->lang('NOTIFICATIONS_COUNT', $notifications['total_count']),
|
||||
'U_MARK_ALL' => $base_url . '&mark=all&token=' . generate_link_hash('mark_all_notifications_read'),
|
||||
));
|
||||
|
||||
$this->tpl_name = 'ucp_notifications';
|
||||
$this->page_title = 'UCP_NOTIFICATION_LIST';
|
||||
break;
|
||||
}
|
||||
|
||||
$template->assign_vars(array(
|
||||
'TITLE' => $user->lang($this->page_title),
|
||||
'TITLE_EXPLAIN' => $user->lang($this->page_title . '_EXPLAIN'),
|
||||
|
||||
'MODE' => $mode,
|
||||
|
||||
'FORM_TIME' => time(),
|
||||
));
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -2465,13 +2465,20 @@ function change_database_data(&$no_updates, $version)
|
|||
'auth' => '',
|
||||
'cat' => 'UCP_PROFILE',
|
||||
),
|
||||
'notifications' => array(
|
||||
'notification_options' => array(
|
||||
'base' => 'ucp_notifications',
|
||||
'class' => 'ucp',
|
||||
'title' => 'UCP_NOTIFICATION_OPTIONS',
|
||||
'auth' => '',
|
||||
'cat' => 'UCP_PREFS',
|
||||
),
|
||||
'notification_list' => array(
|
||||
'base' => 'ucp_notifications',
|
||||
'class' => 'ucp',
|
||||
'title' => 'UCP_NOTIFICATION_LIST',
|
||||
'auth' => '',
|
||||
'cat' => 'UCP_MAIN',
|
||||
),
|
||||
);
|
||||
|
||||
_add_modules($modules_to_install);
|
||||
|
|
|
@ -289,6 +289,9 @@ $lang = array_merge($lang, array(
|
|||
'NEW_PASSWORD_ERROR' => 'The passwords you entered do not match.',
|
||||
|
||||
'NOTIFICATIONS' => 'Notifications',
|
||||
'NOTIFICATIONS_MARK_ALL_READ' => 'Mark all notifications read',
|
||||
'NOTIFICATIONS_MARK_ALL_READ_CONFIRM' => 'Are you sure you want to mark all notifications read?',
|
||||
'NOTIFICATIONS_MARK_ALL_READ_SUCCESS' => 'All notifications have been marked read successfully.',
|
||||
'NOTIFICATION_METHOD_EMAIL' => 'Email',
|
||||
'NOTIFICATION_METHOD_JABBER' => 'Jabber',
|
||||
'NOTIFICATION_TYPE' => 'Notification type',
|
||||
|
@ -470,6 +473,8 @@ $lang = array_merge($lang, array(
|
|||
'UCP_MSNM' => 'Windows Live Messenger',
|
||||
'UCP_NO_ATTACHMENTS' => 'You have posted no files.',
|
||||
|
||||
'UCP_NOTIFICATION_LIST' => 'Manage notifications',
|
||||
'UCP_NOTIFICATION_LIST_EXPLAIN' => 'Here you may view all past notifications.',
|
||||
'UCP_NOTIFICATION_OPTIONS' => 'Edit notification options',
|
||||
'UCP_NOTIFICATION_OPTIONS_EXPLAIN' => 'Here you can set your preferred notification methods for the board.',
|
||||
|
||||
|
|
|
@ -133,7 +133,7 @@
|
|||
<!-- IF S_NOTIFICATIONS_DISPLAY -->
|
||||
<li>
|
||||
[ <a href="#" id="notification_list_button" title="{NOTIFICATIONS_COUNT}">{NOTIFICATIONS_COUNT}</a> ] •
|
||||
<div id="notification_list">
|
||||
<div id="notification_list" class="notification_list">
|
||||
<ul class="topiclist forums">
|
||||
<!-- BEGIN notifications -->
|
||||
<li class="row<!-- IF notifications.UNREAD --> bg2<!-- ENDIF -->">
|
||||
|
|
|
@ -2,45 +2,105 @@
|
|||
|
||||
<form id="ucp" method="post" action="{S_UCP_ACTION}"{S_FORM_ENCTYPE}>
|
||||
|
||||
<h2>{L_UCP_NOTIFICATION_OPTIONS}</h2>
|
||||
<h2>{TITLE}</h2>
|
||||
<div class="panel">
|
||||
<div class="inner">
|
||||
|
||||
<p>{L_UCP_NOTIFICATION_OPTIONS_EXPLAIN}</p>
|
||||
<p>{TITLE_EXPLAIN}</p>
|
||||
|
||||
<ul class="topiclist">
|
||||
<li class="header">
|
||||
<dl>
|
||||
<dt>{L_NOTIFICATION_TYPE}</dt>
|
||||
<!-- BEGIN notification_methods -->
|
||||
<dd class="mark">{notification_methods.NAME}</dd>
|
||||
<!-- END notification_methods -->
|
||||
<dd class="mark">{L_NOTIFICATIONS}</dd>
|
||||
</dl>
|
||||
</li>
|
||||
</ul>
|
||||
<ul class="topiclist cplist">
|
||||
<!-- IF MODE == 'notification_options' -->
|
||||
<ul class="topiclist">
|
||||
<li class="header">
|
||||
<dl>
|
||||
<dt>{L_NOTIFICATION_TYPE}</dt>
|
||||
<!-- BEGIN notification_methods -->
|
||||
<dd class="mark">{notification_methods.NAME}</dd>
|
||||
<!-- END notification_methods -->
|
||||
<dd class="mark">{L_NOTIFICATIONS}</dd>
|
||||
</dl>
|
||||
</li>
|
||||
</ul>
|
||||
<ul class="topiclist cplist">
|
||||
|
||||
<!-- BEGIN notification_types -->
|
||||
<li class="row<!-- IF notification_types.S_ROW_COUNT is odd --> bg1<!-- ELSE --> bg2<!-- ENDIF -->">
|
||||
<dl>
|
||||
<dt>
|
||||
{notification_types.NAME}
|
||||
</dt>
|
||||
<!-- BEGIN notification_methods -->
|
||||
<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"<!-- IF notification_types.SUBSCRIBED --> checked="checked"<!-- ENDIF --> /> <dfn>{notification_methods.NAME}</dfn></dd>
|
||||
</dl>
|
||||
</li>
|
||||
<!-- END notification_types -->
|
||||
<!-- BEGIN notification_types -->
|
||||
<li class="row<!-- IF notification_types.S_ROW_COUNT is odd --> bg1<!-- ELSE --> bg2<!-- ENDIF -->">
|
||||
<dl>
|
||||
<dt>
|
||||
{notification_types.NAME}
|
||||
</dt>
|
||||
<!-- BEGIN notification_methods -->
|
||||
<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"<!-- IF notification_types.SUBSCRIBED --> checked="checked"<!-- ENDIF --> /> <dfn>{notification_methods.NAME}</dfn></dd>
|
||||
</dl>
|
||||
</li>
|
||||
<!-- END notification_types -->
|
||||
</ul>
|
||||
<!-- ELSE -->
|
||||
<!-- IF .pagination or TOTAL_COUNT -->
|
||||
<div class="topic-actions">
|
||||
<div class="pagination">
|
||||
<!-- IF U_MARK_ALL --><a href="{U_MARK_ALL}">{L_NOTIFICATIONS_MARK_ALL_READ}</a> • <!-- ENDIF -->
|
||||
<!-- IF TOTAL_COUNT -->{TOTAL_COUNT} • <!-- ENDIF -->
|
||||
<!-- IF .pagination -->
|
||||
<!-- INCLUDE pagination.html -->
|
||||
<!-- ELSE -->
|
||||
{PAGE_NUMBER}
|
||||
<!-- ENDIF -->
|
||||
</div>
|
||||
</div>
|
||||
<!-- ENDIF -->
|
||||
|
||||
</ul>
|
||||
<ul class="topiclist">
|
||||
<li class="header">
|
||||
<dl>
|
||||
<dt>{L_NOTIFICATIONS}</dt>
|
||||
<dd class="mark">{L_MARK_READ}</dd>
|
||||
</dl>
|
||||
</li>
|
||||
</ul>
|
||||
|
||||
<div class="notification_list">
|
||||
<ul class="topiclist cplist">
|
||||
<!-- BEGIN notification_list -->
|
||||
<li class="row<!-- IF notification_list.UNREAD --> bg3<!-- ELSE --><!-- IF notification_list.S_ROW_COUNT is odd --> bg1<!-- ELSE --> bg2<!-- ENDIF --><!-- ENDIF -->">
|
||||
<dl>
|
||||
<dt>
|
||||
<!-- IF notification_list.URL --><a href="{notification_list.URL}"><!-- ENDIF -->
|
||||
{notification_list.AVATAR}
|
||||
<div>
|
||||
{notification_list.FORMATTED_TITLE}<br />
|
||||
{notification_list.TIME}
|
||||
</div>
|
||||
<!-- IF notification_list.URL --></a><!-- ENDIF -->
|
||||
</dt>
|
||||
<dd class="mark"><!-- IF notification_list.UNREAD --><input type="checkbox" name="mark[]" value="{notification_list.NOTIFICATION_ID}" /> <dfn>{L_MARK_READ}</dfn><!-- ENDIF --></dd>
|
||||
</dl>
|
||||
</li>
|
||||
<!-- END notification_list -->
|
||||
</ul>
|
||||
</div>
|
||||
|
||||
<!-- IF .pagination or TOTAL_COUNT -->
|
||||
<div class="topic-actions">
|
||||
<div class="pagination">
|
||||
<!-- IF TOTAL_COUNT -->{TOTAL_COUNT} • <!-- ENDIF -->
|
||||
<!-- IF .pagination -->
|
||||
<!-- INCLUDE pagination.html -->
|
||||
<!-- ELSE -->
|
||||
{PAGE_NUMBER}
|
||||
<!-- ENDIF -->
|
||||
</div>
|
||||
</div>
|
||||
<!-- ENDIF -->
|
||||
|
||||
<!-- ENDIF -->
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
<fieldset class="submit-buttons">
|
||||
<input type="hidden" name="form_time" value="{FORM_TIME}" />
|
||||
{S_HIDDEN_FIELDS}<input type="reset" value="{L_RESET}" name="reset" class="button2" />
|
||||
<input type="submit" name="submit" value="{L_SUBMIT}" class="button1" />
|
||||
{S_FORM_TOKEN}
|
||||
|
|
|
@ -682,11 +682,11 @@ p.rules a {
|
|||
width: 310px;
|
||||
}
|
||||
|
||||
#notification_list ul li a {
|
||||
.notification_list ul li a {
|
||||
text-decoration: none;
|
||||
}
|
||||
|
||||
#notification_list ul li img {
|
||||
.notification_list ul li img {
|
||||
float: left;
|
||||
padding: 0 10px 10px 0;
|
||||
max-width: 50px;
|
||||
|
|
|
@ -272,6 +272,7 @@ class phpbb_notification_test extends phpbb_database_test_case
|
|||
$this->assertEquals(array(
|
||||
'notifications' => array(),
|
||||
'unread_count' => 0,
|
||||
'total_count' => 0,
|
||||
), $this->notifications->load_notifications(array(
|
||||
'count_unread' => true,
|
||||
)));
|
||||
|
|
Loading…
Add table
Reference in a new issue