From cb937841269017d13058208378e4c9ad79718c6e Mon Sep 17 00:00:00 2001 From: Nathan Guse Date: Sat, 13 Oct 2012 20:02:38 -0500 Subject: [PATCH] [ticket/11103] UCP Notification List PHPBB3-11103 --- phpBB/includes/notification/manager.php | 33 +++-- phpBB/includes/notification/type/base.php | 6 +- phpBB/includes/ucp/info/ucp_notifications.php | 1 + phpBB/includes/ucp/ucp_notifications.php | 82 ++++++++++++- phpBB/install/database_update.php | 9 +- phpBB/language/en/ucp.php | 5 + .../prosilver/template/overall_header.html | 2 +- .../prosilver/template/ucp_notifications.html | 116 +++++++++++++----- phpBB/styles/prosilver/theme/common.css | 4 +- tests/notification/notification.php | 1 + 10 files changed, 213 insertions(+), 46 deletions(-) diff --git a/phpBB/includes/notification/manager.php b/phpBB/includes/notification/manager.php index 6c74fa965e..22fa12967a 100644 --- a/phpBB/includes/notification/manager.php +++ b/phpBB/includes/notification/manager.php @@ -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); diff --git a/phpBB/includes/notification/type/base.php b/phpBB/includes/notification/type/base.php index 45dc463061..f6b61aee49 100644 --- a/phpBB/includes/notification/type/base.php +++ b/phpBB/includes/notification/type/base.php @@ -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); } diff --git a/phpBB/includes/ucp/info/ucp_notifications.php b/phpBB/includes/ucp/info/ucp_notifications.php index 3c7ea80bee..98d8b9db61 100644 --- a/phpBB/includes/ucp/info/ucp_notifications.php +++ b/phpBB/includes/ucp/info/ucp_notifications.php @@ -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')), ), ); } diff --git a/phpBB/includes/ucp/ucp_notifications.php b/phpBB/includes/ucp/ucp_notifications.php index 8ce12dae35..35783e1b56 100644 --- a/phpBB/includes/ucp/ucp_notifications.php +++ b/phpBB/includes/ucp/ucp_notifications.php @@ -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'] . '

' . sprintf($user->lang['RETURN_UCP'], '', ''); + 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(), + )); } /** diff --git a/phpBB/install/database_update.php b/phpBB/install/database_update.php index 76af67545a..958db6b531 100644 --- a/phpBB/install/database_update.php +++ b/phpBB/install/database_update.php @@ -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); diff --git a/phpBB/language/en/ucp.php b/phpBB/language/en/ucp.php index e2dbd542f9..d75609880b 100644 --- a/phpBB/language/en/ucp.php +++ b/phpBB/language/en/ucp.php @@ -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.', diff --git a/phpBB/styles/prosilver/template/overall_header.html b/phpBB/styles/prosilver/template/overall_header.html index 2f789f3f2c..e00ad555ff 100644 --- a/phpBB/styles/prosilver/template/overall_header.html +++ b/phpBB/styles/prosilver/template/overall_header.html @@ -133,7 +133,7 @@
  • [ {NOTIFICATIONS_COUNT} ] • -
    +
    • diff --git a/phpBB/styles/prosilver/template/ucp_notifications.html b/phpBB/styles/prosilver/template/ucp_notifications.html index 531ffd3e6a..3ee58a278e 100644 --- a/phpBB/styles/prosilver/template/ucp_notifications.html +++ b/phpBB/styles/prosilver/template/ucp_notifications.html @@ -2,45 +2,105 @@
      -

      {L_UCP_NOTIFICATION_OPTIONS}

      +

      {TITLE}

      -

      {L_UCP_NOTIFICATION_OPTIONS_EXPLAIN}

      +

      {TITLE_EXPLAIN}

      -
        -
      • -
        -
        {L_NOTIFICATION_TYPE}
        - -
        {notification_methods.NAME}
        - -
        {L_NOTIFICATIONS}
        -
        -
      • -
      -
        + +
          +
        • +
          +
          {L_NOTIFICATION_TYPE}
          + +
          {notification_methods.NAME}
          + +
          {L_NOTIFICATIONS}
          +
          +
        • +
        +
          - -
        • -
          -
          - {notification_types.NAME} -
          - -
          checked="checked" /> {notification_methods.NAME}
          - -
          checked="checked" /> {notification_methods.NAME}
          -
          -
        • - + +
        • +
          +
          + {notification_types.NAME} +
          + +
          checked="checked" /> {notification_methods.NAME}
          + +
          checked="checked" /> {notification_methods.NAME}
          +
          +
        • + +
        + + +
        + +
        + -
      +
        +
      • +
        +
        {L_NOTIFICATIONS}
        +
        {L_MARK_READ}
        +
        +
      • +
      + + + + +
      + +
      + + +
      + {S_HIDDEN_FIELDS}  {S_FORM_TOKEN} diff --git a/phpBB/styles/prosilver/theme/common.css b/phpBB/styles/prosilver/theme/common.css index 1f5b45e006..3d8d640598 100644 --- a/phpBB/styles/prosilver/theme/common.css +++ b/phpBB/styles/prosilver/theme/common.css @@ -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; diff --git a/tests/notification/notification.php b/tests/notification/notification.php index 6fba973ead..13fc99bed3 100644 --- a/tests/notification/notification.php +++ b/tests/notification/notification.php @@ -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, )));