diff options
author | Nathan Guse <nathaniel.guse@gmail.com> | 2012-09-27 18:25:37 -0500 |
---|---|---|
committer | Nathan Guse <nathaniel.guse@gmail.com> | 2012-09-27 18:25:37 -0500 |
commit | 48ccc9eb93c8413f05f6a50d40e597f560c671d8 (patch) | |
tree | 20ba16edf636eeb2523c51559d33462d1fea07f3 /phpBB | |
parent | f062087f30fab4ce497333cd88735920efe0737f (diff) | |
download | forums-48ccc9eb93c8413f05f6a50d40e597f560c671d8.tar forums-48ccc9eb93c8413f05f6a50d40e597f560c671d8.tar.gz forums-48ccc9eb93c8413f05f6a50d40e597f560c671d8.tar.bz2 forums-48ccc9eb93c8413f05f6a50d40e597f560c671d8.tar.xz forums-48ccc9eb93c8413f05f6a50d40e597f560c671d8.zip |
[ticket/11103] UCP Notification Options can now be set
PHPBB3-11103
Diffstat (limited to 'phpBB')
-rw-r--r-- | phpBB/includes/functions.php | 1 | ||||
-rw-r--r-- | phpBB/includes/notifications/service.php | 44 | ||||
-rw-r--r-- | phpBB/includes/ucp/ucp_notifications.php | 43 | ||||
-rw-r--r-- | phpBB/language/en/common.php | 5 | ||||
-rw-r--r-- | phpBB/styles/prosilver/template/overall_header.html | 2 | ||||
-rw-r--r-- | phpBB/styles/prosilver/template/ucp_notifications.html | 4 |
6 files changed, 80 insertions, 19 deletions
diff --git a/phpBB/includes/functions.php b/phpBB/includes/functions.php index 92cea20d10..92d72b6636 100644 --- a/phpBB/includes/functions.php +++ b/phpBB/includes/functions.php @@ -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'], diff --git a/phpBB/includes/notifications/service.php b/phpBB/includes/notifications/service.php index 174b73f9a5..2c1eb859c7 100644 --- a/phpBB/includes/notifications/service.php +++ b/phpBB/includes/notifications/service.php @@ -503,6 +503,46 @@ class phpbb_notifications_service } /** + * 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 * * @param string $item_type Type identifier of the 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); diff --git a/phpBB/includes/ucp/ucp_notifications.php b/phpBB/includes/ucp/ucp_notifications.php index 86052ada14..ad399ca290 100644 --- a/phpBB/includes/ucp/ucp_notifications.php +++ b/phpBB/includes/ucp/ucp_notifications.php @@ -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) { diff --git a/phpBB/language/en/common.php b/phpBB/language/en/common.php index 8ad7628891..43bc6328fe 100644 --- a/phpBB/language/en/common.php +++ b/phpBB/language/en/common.php @@ -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".', diff --git a/phpBB/styles/prosilver/template/overall_header.html b/phpBB/styles/prosilver/template/overall_header.html index 94830bb3a5..ff4e5d7b25 100644 --- a/phpBB/styles/prosilver/template/overall_header.html +++ b/phpBB/styles/prosilver/template/overall_header.html @@ -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> ] • + [ <a href="#" id="notification_list_button" title="{NOTIFICATIONS_CNT}">{NOTIFICATIONS_CNT}</a> ] • <div id="notification_list"> <ul class="topiclist forums"> <!-- BEGIN notifications --> diff --git a/phpBB/styles/prosilver/template/ucp_notifications.html b/phpBB/styles/prosilver/template/ucp_notifications.html index 0479e66efe..c6665c16c0 100644 --- a/phpBB/styles/prosilver/template/ucp_notifications.html +++ b/phpBB/styles/prosilver/template/ucp_notifications.html @@ -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 --> |