1
0
mirror of https://github.com/phpbb/phpbb.git synced 2025-08-10 02:36:38 +02:00

[ticket/11103] UCP Notification List

PHPBB3-11103
This commit is contained in:
Nathan Guse
2012-10-13 20:02:38 -05:00
parent 441e389123
commit cb93784126
10 changed files with 213 additions and 46 deletions

View File

@@ -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);

View File

@@ -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);
}

View File

@@ -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')),
),
);
}

View File

@@ -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&amp;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 . '&amp;mark=all&amp;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(),
));
}
/**