From ae91a0a846828b44a53c2a7cd724e0ba062b0f3e Mon Sep 17 00:00:00 2001 From: Nathaniel Guse Date: Thu, 27 Sep 2012 10:37:37 -0500 Subject: [PATCH] [ticket/11103] Allow grouping of multiple types in ucp notification options Ability to hide notification types from UCP Notification options (if users do not have permission to use the notification type, or for whatever reason they should not see it) PHPBB3-11103 --- phpBB/includes/notifications/service.php | 15 +++++-- .../notifications/type/approve_post.php | 11 +++++ .../notifications/type/approve_topic.php | 11 +++++ phpBB/includes/notifications/type/base.php | 16 +++++++ .../notifications/type/disapprove_post.php | 11 +++++ .../notifications/type/disapprove_topic.php | 11 +++++ .../includes/notifications/type/interface.php | 2 + .../notifications/type/post_in_queue.php | 41 +++++++++++++++--- .../notifications/type/topic_in_queue.php | 43 ++++++++++++++++--- phpBB/includes/ucp/info/ucp_notifications.php | 2 +- phpBB/includes/ucp/ucp_notifications.php | 4 +- .../prosilver/template/ucp_notifications.html | 6 +-- 12 files changed, 153 insertions(+), 20 deletions(-) diff --git a/phpBB/includes/notifications/service.php b/phpBB/includes/notifications/service.php index 3160864f37..174b73f9a5 100644 --- a/phpBB/includes/notifications/service.php +++ b/phpBB/includes/notifications/service.php @@ -457,9 +457,16 @@ class phpbb_notifications_service include($file); } - if (method_exists($class, 'get_item_type')) + if ($class::is_available($this->phpbb_container) && method_exists($class, 'get_item_type')) { - $subscription_types[] = $class::get_item_type(); + if ($class::$notification_option === false) + { + $subscription_types[$class::get_item_type()] = $class::get_item_type(); + } + else + { + $subscription_types[$class::$notification_option['id']] = $class::$notification_option; + } } } @@ -548,6 +555,8 @@ class phpbb_notifications_service */ public function load_users($user_ids) { + $user_ids[] = ANONYMOUS; + // Load the users $user_ids = array_unique($user_ids); @@ -577,7 +586,7 @@ class phpbb_notifications_service */ public function get_user($user_id) { - return $this->users[$user_id]; + return (isset($this->users[$user_id])) ? $this->users[$user_id] : $this->users[ANONYMOUS]; } /** diff --git a/phpBB/includes/notifications/type/approve_post.php b/phpBB/includes/notifications/type/approve_post.php index b5e5cfd337..a3a52b8780 100644 --- a/phpBB/includes/notifications/type/approve_post.php +++ b/phpBB/includes/notifications/type/approve_post.php @@ -39,6 +39,17 @@ class phpbb_notifications_type_approve_post extends phpbb_notifications_type_pos */ protected $language_key = 'NOTIFICATION_POST_APPROVED'; + /** + * Notification option data (for outputting to the user) + * + * @var bool|array False if the service should use it's default data + * Array of data (including keys 'id' and 'lang') + */ + public static $notification_option = array( + 'id' => 'moderation_queue', + 'lang' => 'NOTIFICATION_TYPE_MODERATION_QUEUE', + ); + /** * Get the type of notification this is * phpbb_notifications_type_ diff --git a/phpBB/includes/notifications/type/approve_topic.php b/phpBB/includes/notifications/type/approve_topic.php index 3ba871599e..ba7227c671 100644 --- a/phpBB/includes/notifications/type/approve_topic.php +++ b/phpBB/includes/notifications/type/approve_topic.php @@ -39,6 +39,17 @@ class phpbb_notifications_type_approve_topic extends phpbb_notifications_type_to */ protected $language_key = 'NOTIFICATION_TOPIC_APPROVED'; + /** + * Notification option data (for outputting to the user) + * + * @var bool|array False if the service should use it's default data + * Array of data (including keys 'id' and 'lang') + */ + public static $notification_option = array( + 'id' => 'moderation_queue', + 'lang' => 'NOTIFICATION_TYPE_MODERATION_QUEUE', + ); + /** * Get the type of notification this is * phpbb_notifications_type_ diff --git a/phpBB/includes/notifications/type/base.php b/phpBB/includes/notifications/type/base.php index 710f1f7c6e..0da4dc8d93 100644 --- a/phpBB/includes/notifications/type/base.php +++ b/phpBB/includes/notifications/type/base.php @@ -36,6 +36,14 @@ abstract class phpbb_notifications_type_base implements phpbb_notifications_type */ protected $users = array(); + /** + * Notification option data (for outputting to the user) + * + * @var bool|array False if the service should use it's default data + * Array of data (including keys 'id' and 'lang') + */ + public static $notification_option = false; + /** * Indentification data * item_type @@ -236,6 +244,14 @@ abstract class phpbb_notifications_type_base implements phpbb_notifications_type return; } + /** + * Is available (fall-back) + */ + public static function is_available(ContainerBuilder $phpbb_container) + { + return true; + } + /** * -------------- Helper functions ------------------- */ diff --git a/phpBB/includes/notifications/type/disapprove_post.php b/phpBB/includes/notifications/type/disapprove_post.php index e0b7bfb178..6911af5b08 100644 --- a/phpBB/includes/notifications/type/disapprove_post.php +++ b/phpBB/includes/notifications/type/disapprove_post.php @@ -39,6 +39,17 @@ class phpbb_notifications_type_disapprove_post extends phpbb_notifications_type_ */ protected $language_key = 'NOTIFICATION_POST_DISAPPROVED'; + /** + * Notification option data (for outputting to the user) + * + * @var bool|array False if the service should use it's default data + * Array of data (including keys 'id' and 'lang') + */ + public static $notification_option = array( + 'id' => 'moderation_queue', + 'lang' => 'NOTIFICATION_TYPE_MODERATION_QUEUE', + ); + /** * Get the type of notification this is * phpbb_notifications_type_ diff --git a/phpBB/includes/notifications/type/disapprove_topic.php b/phpBB/includes/notifications/type/disapprove_topic.php index 7ad4c4edb8..dab5ec1b02 100644 --- a/phpBB/includes/notifications/type/disapprove_topic.php +++ b/phpBB/includes/notifications/type/disapprove_topic.php @@ -39,6 +39,17 @@ class phpbb_notifications_type_disapprove_topic extends phpbb_notifications_type */ protected $language_key = 'NOTIFICATION_TOPIC_DISAPPROVED'; + /** + * Notification option data (for outputting to the user) + * + * @var bool|array False if the service should use it's default data + * Array of data (including keys 'id' and 'lang') + */ + public static $notification_option = array( + 'id' => 'moderation_queue', + 'lang' => 'NOTIFICATION_TYPE_MODERATION_QUEUE', + ); + /** * Get the type of notification this is * phpbb_notifications_type_ diff --git a/phpBB/includes/notifications/type/interface.php b/phpBB/includes/notifications/type/interface.php index de08576a38..c85d7441f6 100644 --- a/phpBB/includes/notifications/type/interface.php +++ b/phpBB/includes/notifications/type/interface.php @@ -25,6 +25,8 @@ interface phpbb_notifications_type_interface public static function get_item_id($type_data); + public static function is_available(ContainerBuilder $phpbb_container); + public static function find_users_for_notification(ContainerBuilder $phpbb_container, $type_data); public function get_title(); diff --git a/phpBB/includes/notifications/type/post_in_queue.php b/phpBB/includes/notifications/type/post_in_queue.php index cd3a452856..0043a38944 100644 --- a/phpBB/includes/notifications/type/post_in_queue.php +++ b/phpBB/includes/notifications/type/post_in_queue.php @@ -39,6 +39,17 @@ class phpbb_notifications_type_post_in_queue extends phpbb_notifications_type_po */ protected $language_key = 'NOTIFICATION_POST_IN_QUEUE'; + /** + * Notification option data (for outputting to the user) + * + * @var bool|array False if the service should use it's default data + * Array of data (including keys 'id' and 'lang') + */ + public static $notification_option = array( + 'id' => 'needs_approval', + 'lang' => 'NOTIFICATION_TYPE_IN_MODERATION_QUEUE', + ); + /** * Get the type of notification this is * phpbb_notifications_type_ @@ -48,6 +59,16 @@ class phpbb_notifications_type_post_in_queue extends phpbb_notifications_type_po return 'post_in_queue'; } + /** + * Is available + */ + public static function is_available(ContainerBuilder $phpbb_container) + { + $m_approve = $phpbb_container->get('auth')->acl_getf('m_approve', true); + + return (!empty($m_approve)); + } + /** * Find the users who want to receive notifications * @@ -58,9 +79,8 @@ class phpbb_notifications_type_post_in_queue extends phpbb_notifications_type_po */ public static function find_users_for_notification(ContainerBuilder $phpbb_container, $post) { - /* todo - * find what type of notification they'd like to receive - */ + $db = $phpbb_container->get('dbal.conn'); + $auth_approve = $phpbb_container->get('auth')->acl_get_list(false, 'm_approve', $post['forum_id']); if (empty($auth_approve)) @@ -70,10 +90,21 @@ class phpbb_notifications_type_post_in_queue extends phpbb_notifications_type_po $notify_users = array(); - foreach ($auth_approve[$post['forum_id']]['m_approve'] as $user_id) + $sql = 'SELECT * + FROM ' . USER_NOTIFICATIONS_TABLE . " + WHERE item_type = 'needs_approval' + AND " . $db->sql_in_set('user_id', $auth_approve[$topic['forum_id']]['m_approve']); + $result = $db->sql_query($sql); + while ($row = $db->sql_fetchrow($result)) { - $notify_users[$user_id] = array(''); + if (!isset($rowset[$row['user_id']])) + { + $notify_users[$row['user_id']] = array(); + } + + $notify_users[$row['user_id']][] = $row['method']; } + $db->sql_freeresult($result); return $notify_users; } diff --git a/phpBB/includes/notifications/type/topic_in_queue.php b/phpBB/includes/notifications/type/topic_in_queue.php index 583ab5d8b3..dda647d18e 100644 --- a/phpBB/includes/notifications/type/topic_in_queue.php +++ b/phpBB/includes/notifications/type/topic_in_queue.php @@ -39,6 +39,27 @@ class phpbb_notifications_type_topic_in_queue extends phpbb_notifications_type_t */ protected $language_key = 'NOTIFICATION_TOPIC_IN_QUEUE'; + /** + * Notification option data (for outputting to the user) + * + * @var bool|array False if the service should use it's default data + * Array of data (including keys 'id' and 'lang') + */ + public static $notification_option = array( + 'id' => 'needs_approval', + 'lang' => 'NOTIFICATION_TYPE_IN_MODERATION_QUEUE', + ); + + /** + * Is available + */ + public static function is_available(ContainerBuilder $phpbb_container) + { + $m_approve = $phpbb_container->get('auth')->acl_getf('m_approve', true); + + return (!empty($m_approve)); + } + /** * Get the type of notification this is * phpbb_notifications_type_ @@ -58,9 +79,8 @@ class phpbb_notifications_type_topic_in_queue extends phpbb_notifications_type_t */ public static function find_users_for_notification(ContainerBuilder $phpbb_container, $topic) { - /* todo - * find what type of notification they'd like to receive - */ + $db = $phpbb_container->get('dbal.conn'); + $auth_approve = $phpbb_container->get('auth')->acl_get_list(false, 'm_approve', $topic['forum_id']); if (empty($auth_approve)) @@ -70,10 +90,21 @@ class phpbb_notifications_type_topic_in_queue extends phpbb_notifications_type_t $notify_users = array(); - foreach ($auth_approve[$topic['forum_id']]['m_approve'] as $user_id) + $sql = 'SELECT * + FROM ' . USER_NOTIFICATIONS_TABLE . " + WHERE item_type = 'needs_approval' + AND " . $db->sql_in_set('user_id', $auth_approve[$topic['forum_id']]['m_approve']); + $result = $db->sql_query($sql); + while ($row = $db->sql_fetchrow($result)) { - $notify_users[$user_id] = array(''); + if (!isset($rowset[$row['user_id']])) + { + $notify_users[$row['user_id']] = array(); + } + + $notify_users[$row['user_id']][] = $row['method']; } + $db->sql_freeresult($result); return $notify_users; } @@ -88,7 +119,7 @@ class phpbb_notifications_type_topic_in_queue extends phpbb_notifications_type_t */ public function create_insert_array($topic) { - $data = parent::create_insert_array($post); + $data = parent::create_insert_array($topic); $this->time = $data['time'] = time(); diff --git a/phpBB/includes/ucp/info/ucp_notifications.php b/phpBB/includes/ucp/info/ucp_notifications.php index f1e6bf65b8..4bc9ae2cea 100644 --- a/phpBB/includes/ucp/info/ucp_notifications.php +++ b/phpBB/includes/ucp/info/ucp_notifications.php @@ -16,7 +16,7 @@ class ucp_notifications_info { return array( 'filename' => 'ucp_notifications', - 'title' => 'UCP_NOTIFICATIONS', + 'title' => 'UCP_NOTIFICATION_OPTIONS', 'version' => '1.0.0', 'modes' => array( 'notification_options' => array('title' => 'UCP_NOTIFICATION_OPTIONS', 'auth' => '', 'cat' => array('UCP_MAIN')), diff --git a/phpBB/includes/ucp/ucp_notifications.php b/phpBB/includes/ucp/ucp_notifications.php index 0a01cd1cde..86052ada14 100644 --- a/phpBB/includes/ucp/ucp_notifications.php +++ b/phpBB/includes/ucp/ucp_notifications.php @@ -76,12 +76,12 @@ class ucp_notifications */ public function output_notification_types($block = 'notification_types', phpbb_notifications_service $phpbb_notifications, phpbb_template $template, phpbb_user $user) { - foreach($phpbb_notifications->get_subscription_types() as $type) + foreach($phpbb_notifications->get_subscription_types() as $type => $data) { $template->assign_block_vars($block, array( 'TYPE' => $type, - 'NAME' => $user->lang('NOTIFICATION_TYPE_' . strtoupper($type)), + 'NAME' => (isset($data['lang'])) ? $user->lang($data['lang']) : $user->lang('NOTIFICATION_TYPE_' . strtoupper($type)), )); $this->output_notification_methods($block . '.notification_methods', $phpbb_notifications, $template, $user); diff --git a/phpBB/styles/prosilver/template/ucp_notifications.html b/phpBB/styles/prosilver/template/ucp_notifications.html index 7ded4d01fe..0479e66efe 100644 --- a/phpBB/styles/prosilver/template/ucp_notifications.html +++ b/phpBB/styles/prosilver/template/ucp_notifications.html @@ -6,7 +6,7 @@
-