[ticket/11103] Display all unread notifications by default

Add unread count to the page title

PHPBB3-11103
This commit is contained in:
Nathan Guse 2012-09-14 18:30:12 -05:00
parent 959c81d00e
commit 7589a3093d
5 changed files with 56 additions and 20 deletions

View file

@ -1297,6 +1297,7 @@ function get_schema_struct()
$schema_data['phpbb_notifications'] = array( $schema_data['phpbb_notifications'] = array(
'COLUMNS' => array( 'COLUMNS' => array(
'notification_id' => array('UINT', NULL, 'auto_increment'),
'item_type' => array('VCHAR:25', ''), 'item_type' => array('VCHAR:25', ''),
'item_id' => array('UINT', 0), 'item_id' => array('UINT', 0),
'item_parent_id' => array('UINT', 0), 'item_parent_id' => array('UINT', 0),
@ -1305,11 +1306,7 @@ function get_schema_struct()
'time' => array('TIMESTAMP', 1), 'time' => array('TIMESTAMP', 1),
'data' => array('TEXT_UNI', ''), 'data' => array('TEXT_UNI', ''),
), ),
'PRIMARY_KEY' => array( 'PRIMARY_KEY' => 'notification_id',
'item_type',
'item_id',
'user_id',
),
'KEYS' => array( 'KEYS' => array(
'item_type' => array('INDEX', 'item_type'), 'item_type' => array('INDEX', 'item_type'),
'item_id' => array('INDEX', 'item_id'), 'item_id' => array('INDEX', 'item_id'),

View file

@ -4994,6 +4994,14 @@ function page_header($page_title = '', $display_online_list = true, $item_id = 0
$timezone_name = $user->lang['timezones'][$timezone_name]; $timezone_name = $user->lang['timezones'][$timezone_name];
} }
// Output the notifications
$phpbb_notifications = $phpbb_container->get('notifications');
$notifications = $phpbb_notifications->load_notifications();
foreach ($notifications['notifications'] as $notification)
{
$template->assign_block_vars('notifications', $notification->prepare_for_display());
}
// The following assigns all _common_ variables that may be used at any point in a template. // The following assigns all _common_ variables that may be used at any point in a template.
$template->assign_vars(array( $template->assign_vars(array(
'SITENAME' => $config['sitename'], 'SITENAME' => $config['sitename'],
@ -5008,6 +5016,7 @@ function page_header($page_title = '', $display_online_list = true, $item_id = 0
'RECORD_USERS' => $l_online_record, 'RECORD_USERS' => $l_online_record,
'PRIVATE_MESSAGE_INFO' => $l_privmsgs_text, 'PRIVATE_MESSAGE_INFO' => $l_privmsgs_text,
'PRIVATE_MESSAGE_INFO_UNREAD' => $l_privmsgs_text_unread, 'PRIVATE_MESSAGE_INFO_UNREAD' => $l_privmsgs_text_unread,
'NUM_UNREAD_NOTIFICATIONS' => $notifications['unread_count'],
'S_USER_NEW_PRIVMSG' => $user->data['user_new_privmsg'], 'S_USER_NEW_PRIVMSG' => $user->data['user_new_privmsg'],
'S_USER_UNREAD_PRIVMSG' => $user->data['user_unread_privmsg'], 'S_USER_UNREAD_PRIVMSG' => $user->data['user_unread_privmsg'],
@ -5119,13 +5128,6 @@ function page_header($page_title = '', $display_online_list = true, $item_id = 0
'A_COOKIE_SETTINGS' => addslashes('; path=' . $config['cookie_path'] . ((!$config['cookie_domain'] || $config['cookie_domain'] == 'localhost' || $config['cookie_domain'] == '127.0.0.1') ? '' : '; domain=' . $config['cookie_domain']) . ((!$config['cookie_secure']) ? '' : '; secure')), 'A_COOKIE_SETTINGS' => addslashes('; path=' . $config['cookie_path'] . ((!$config['cookie_domain'] || $config['cookie_domain'] == 'localhost' || $config['cookie_domain'] == '127.0.0.1') ? '' : '; domain=' . $config['cookie_domain']) . ((!$config['cookie_secure']) ? '' : '; secure')),
)); ));
// Output the notifications
$phpbb_notifications = $phpbb_container->get('notifications');
foreach ($phpbb_notifications->load_notifications() as $notification)
{
$template->assign_block_vars('notifications', $notification->prepare_for_display());
}
// application/xhtml+xml not used because of IE // application/xhtml+xml not used because of IE
header('Content-type: text/html; charset=UTF-8'); header('Content-type: text/html; charset=UTF-8');

View file

@ -50,6 +50,7 @@ class phpbb_notifications_service
* order_dir Order direction (Default: DESC) * order_dir Order direction (Default: DESC)
* limit Number of notifications to load (Default: 5) * limit Number of notifications to load (Default: 5)
* start Notifications offset (Default: 0) * start Notifications offset (Default: 0)
* all_unread Load all unread messages? (Default: true)
*/ */
public function load_notifications($options = array()) public function load_notifications($options = array())
{ {
@ -62,11 +63,24 @@ class phpbb_notifications_service
'order_dir' => 'DESC', 'order_dir' => 'DESC',
'limit' => 5, 'limit' => 5,
'start' => 0, 'start' => 0,
'all_unread' => true,
), $options); ), $options);
$notifications = $user_ids = array(); $notifications = $user_ids = array();
$load_special = array(); $load_special = array();
// Get the total number of unread notifications
$sql = 'SELECT COUNT(*) AS count
FROM ' . NOTIFICATIONS_TABLE . '
WHERE user_id = ' . (int) $options['user_id'] . '
AND unread = 1';
$result = $this->db->sql_query($sql);
$count = $this->db->sql_fetchfield('count', $result);
$this->db->sql_freeresult($result);
$rowset = array();
// Get the main notifications
$sql = 'SELECT * $sql = 'SELECT *
FROM ' . NOTIFICATIONS_TABLE . ' FROM ' . NOTIFICATIONS_TABLE . '
WHERE user_id = ' . (int) $options['user_id'] . ' WHERE user_id = ' . (int) $options['user_id'] . '
@ -74,6 +88,30 @@ class phpbb_notifications_service
$result = $this->db->sql_query_limit($sql, $options['limit'], $options['start']); $result = $this->db->sql_query_limit($sql, $options['limit'], $options['start']);
while ($row = $this->db->sql_fetchrow($result)) while ($row = $this->db->sql_fetchrow($result))
{
$rowset[$row['notification_id']] = $row;
}
$this->db->sql_freeresult($result);
// Get all unread notifications
if ($options['all_unread'])
{
$sql = 'SELECT *
FROM ' . NOTIFICATIONS_TABLE . '
WHERE user_id = ' . (int) $options['user_id'] . '
AND unread = 1
AND ' . $this->db->sql_in_set('notification_id', array_keys($rowset), true) . '
ORDER BY ' . $this->db->sql_escape($options['order_by']) . ' ' . $this->db->sql_escape($options['order_dir']);
$result = $this->db->sql_query_limit($sql, $options['limit'], $options['start']);
while ($row = $this->db->sql_fetchrow($result))
{
$rowset[$row['notification_id']] = $row;
}
$this->db->sql_freeresult($result);
}
foreach ($rowset as $row)
{ {
$item_type_class_name = $this->get_item_type_class_name($row['item_type'], true); $item_type_class_name = $this->get_item_type_class_name($row['item_type'], true);
@ -91,7 +129,6 @@ class phpbb_notifications_service
$notifications[] = $notification; $notifications[] = $notification;
} }
$this->db->sql_freeresult($result);
$this->load_users($user_ids); $this->load_users($user_ids);
@ -103,7 +140,10 @@ class phpbb_notifications_service
$item_type_class_name::load_special($this->phpbb_container, $data, $notifications); $item_type_class_name::load_special($this->phpbb_container, $data, $notifications);
} }
return $notifications; return array(
'notifications' => $notifications,
'unread_count' => $count,
);
} }
/** /**

View file

@ -1127,6 +1127,7 @@ function database_update_info()
), ),
NOTIFICATIONS_TABLE => array( NOTIFICATIONS_TABLE => array(
'COLUMNS' => array( 'COLUMNS' => array(
'notification_id' => array('UINT', NULL, 'auto_increment'),
'item_type' => array('VCHAR:25', ''), 'item_type' => array('VCHAR:25', ''),
'item_id' => array('UINT', 0), 'item_id' => array('UINT', 0),
'item_parent_id' => array('UINT', 0), 'item_parent_id' => array('UINT', 0),
@ -1135,11 +1136,7 @@ function database_update_info()
'time' => array('TIMESTAMP', 1), 'time' => array('TIMESTAMP', 1),
'data' => array('TEXT_UNI', ''), 'data' => array('TEXT_UNI', ''),
), ),
'PRIMARY_KEY' => array( 'PRIMARY_KEY' => 'notification_id',
'item_type',
'item_id',
'user_id',
),
'KEYS' => array( 'KEYS' => array(
'item_type' => array('INDEX', 'item_type'), 'item_type' => array('INDEX', 'item_type'),
'item_id' => array('INDEX', 'item_id'), 'item_id' => array('INDEX', 'item_id'),

View file

@ -5,7 +5,7 @@
<meta name="keywords" content="" /> <meta name="keywords" content="" />
<meta name="description" content="" /> <meta name="description" content="" />
{META} {META}
<title><!-- IF not S_VIEWTOPIC and not S_VIEWFORUM -->{SITENAME} - <!-- ENDIF --><!-- IF S_IN_MCP -->{L_MCP} - <!-- ELSEIF S_IN_UCP -->{L_UCP} - <!-- ENDIF -->{PAGE_TITLE}<!-- IF S_VIEWTOPIC or S_VIEWFORUM --> - {SITENAME}<!-- ENDIF --></title> <title><!-- IF NUM_UNREAD_NOTIFICATIONS -->({NUM_UNREAD_NOTIFICATIONS}) <!-- ENDIF --><!-- IF not S_VIEWTOPIC and not S_VIEWFORUM -->{SITENAME} - <!-- ENDIF --><!-- IF S_IN_MCP -->{L_MCP} - <!-- ELSEIF S_IN_UCP -->{L_UCP} - <!-- ENDIF -->{PAGE_TITLE}<!-- IF S_VIEWTOPIC or S_VIEWFORUM --> - {SITENAME}<!-- ENDIF --></title>
<!-- IF S_ENABLE_FEEDS --> <!-- IF S_ENABLE_FEEDS -->
<!-- IF S_ENABLE_FEEDS_OVERALL --><link rel="alternate" type="application/atom+xml" title="{L_FEED} - {SITENAME}" href="{U_FEED}" /><!-- ENDIF --> <!-- IF S_ENABLE_FEEDS_OVERALL --><link rel="alternate" type="application/atom+xml" title="{L_FEED} - {SITENAME}" href="{U_FEED}" /><!-- ENDIF -->