[ticket/11103] UCP Notification option grouping

Also add the ability to specify an _EXPLAIN text for the notification option

PHPBB3-11103
This commit is contained in:
Nathan Guse 2012-10-13 23:52:49 -05:00
parent 94ffbb4050
commit c5f280351a
15 changed files with 115 additions and 55 deletions

View file

@ -495,17 +495,24 @@ class phpbb_notification_manager
if ($class->is_available() && method_exists($class_name, 'get_item_type')) if ($class->is_available() && method_exists($class_name, 'get_item_type'))
{ {
if ($class_name::$notification_option === false) $options = array_merge(array(
{ 'id' => $class_name::get_item_type(),
$subscription_types[$class_name::get_item_type()] = $class_name::get_item_type(); 'lang' => 'NOTIFICATION_TYPE_' . strtoupper($class_name::get_item_type()),
} 'group' => 'NOTIFICATION_GROUP_MISCELLANEOUS',
else ), (($class_name::$notification_option !== false) ? $class_name::$notification_option : array()));
{
$subscription_types[$class_name::$notification_option['id']] = $class_name::$notification_option; $subscription_types[$options['group']][$options['id']] = $options;
}
} }
} }
// Move Miscellaneous to the very last section
if (isset($subscription_types['NOTIFICATION_GROUP_MISCELLANEOUS']))
{
$miscellaneous = $subscription_types['NOTIFICATION_GROUP_MISCELLANEOUS'];
unset($subscription_types['NOTIFICATION_GROUP_MISCELLANEOUS']);
$subscription_types['NOTIFICATION_GROUP_MISCELLANEOUS'] = $miscellaneous;
}
return $subscription_types; return $subscription_types;
} }

View file

@ -41,11 +41,12 @@ class phpbb_notification_type_approve_post extends phpbb_notification_type_post
* Notification option data (for outputting to the user) * Notification option data (for outputting to the user)
* *
* @var bool|array False if the service should use it's default data * @var bool|array False if the service should use it's default data
* Array of data (including keys 'id' and 'lang') * Array of data (including keys 'id', 'lang', and 'group')
*/ */
public static $notification_option = array( public static $notification_option = array(
'id' => 'moderation_queue', 'id' => 'moderation_queue',
'lang' => 'NOTIFICATION_TYPE_MODERATION_QUEUE', 'lang' => 'NOTIFICATION_TYPE_MODERATION_QUEUE',
'group' => 'NOTIFICATION_GROUP_POSTING',
); );
/** /**

View file

@ -41,11 +41,12 @@ class phpbb_notification_type_approve_topic extends phpbb_notification_type_topi
* Notification option data (for outputting to the user) * Notification option data (for outputting to the user)
* *
* @var bool|array False if the service should use it's default data * @var bool|array False if the service should use it's default data
* Array of data (including keys 'id' and 'lang') * Array of data (including keys 'id', 'lang', and 'group')
*/ */
public static $notification_option = array( public static $notification_option = array(
'id' => 'moderation_queue', 'id' => 'moderation_queue',
'lang' => 'NOTIFICATION_TYPE_MODERATION_QUEUE', 'lang' => 'NOTIFICATION_TYPE_MODERATION_QUEUE',
'group' => 'NOTIFICATION_GROUP_POSTING',
); );
/** /**

View file

@ -34,7 +34,7 @@ abstract class phpbb_notification_type_base implements phpbb_notification_type_i
* Notification option data (for outputting to the user) * Notification option data (for outputting to the user)
* *
* @var bool|array False if the service should use its default data * @var bool|array False if the service should use its default data
* Array of data (including keys 'id' and 'lang') * Array of data (including keys 'id', 'lang', and 'group')
*/ */
public static $notification_option = false; public static $notification_option = false;

View file

@ -41,11 +41,12 @@ class phpbb_notification_type_disapprove_post extends phpbb_notification_type_ap
* Notification option data (for outputting to the user) * Notification option data (for outputting to the user)
* *
* @var bool|array False if the service should use it's default data * @var bool|array False if the service should use it's default data
* Array of data (including keys 'id' and 'lang') * Array of data (including keys 'id', 'lang', and 'group')
*/ */
public static $notification_option = array( public static $notification_option = array(
'id' => 'moderation_queue', 'id' => 'moderation_queue',
'lang' => 'NOTIFICATION_TYPE_MODERATION_QUEUE', 'lang' => 'NOTIFICATION_TYPE_MODERATION_QUEUE',
'group' => 'NOTIFICATION_GROUP_POSTING',
); );
/** /**

View file

@ -41,11 +41,12 @@ class phpbb_notification_type_disapprove_topic extends phpbb_notification_type_a
* Notification option data (for outputting to the user) * Notification option data (for outputting to the user)
* *
* @var bool|array False if the service should use it's default data * @var bool|array False if the service should use it's default data
* Array of data (including keys 'id' and 'lang') * Array of data (including keys 'id', 'lang', and 'group')
*/ */
public static $notification_option = array( public static $notification_option = array(
'id' => 'moderation_queue', 'id' => 'moderation_queue',
'lang' => 'NOTIFICATION_TYPE_MODERATION_QUEUE', 'lang' => 'NOTIFICATION_TYPE_MODERATION_QUEUE',
'group' => 'NOTIFICATION_GROUP_POSTING',
); );
/** /**

View file

@ -37,6 +37,16 @@ class phpbb_notification_type_post extends phpbb_notification_type_base
*/ */
protected $language_key = 'NOTIFICATION_POST'; protected $language_key = 'NOTIFICATION_POST';
/**
* 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', 'lang', and 'group')
*/
public static $notification_option = array(
'group' => 'NOTIFICATION_GROUP_POSTING',
);
/** /**
* Get the type of notification this is * Get the type of notification this is
* phpbb_notification_type_ * phpbb_notification_type_

View file

@ -41,11 +41,12 @@ class phpbb_notification_type_post_in_queue extends phpbb_notification_type_post
* Notification option data (for outputting to the user) * Notification option data (for outputting to the user)
* *
* @var bool|array False if the service should use it's default data * @var bool|array False if the service should use it's default data
* Array of data (including keys 'id' and 'lang') * Array of data (including keys 'id', 'lang', and 'group')
*/ */
public static $notification_option = array( public static $notification_option = array(
'id' => 'needs_approval', 'id' => 'needs_approval',
'lang' => 'NOTIFICATION_TYPE_IN_MODERATION_QUEUE', 'lang' => 'NOTIFICATION_TYPE_IN_MODERATION_QUEUE',
'group' => 'NOTIFICATION_GROUP_MODERATION',
); );
/** /**

View file

@ -48,11 +48,12 @@ class phpbb_notification_type_report_pm extends phpbb_notification_type_pm
* Notification option data (for outputting to the user) * Notification option data (for outputting to the user)
* *
* @var bool|array False if the service should use it's default data * @var bool|array False if the service should use it's default data
* Array of data (including keys 'id' and 'lang') * Array of data (including keys 'id', 'lang', and 'group')
*/ */
public static $notification_option = array( public static $notification_option = array(
'id' => 'report', 'id' => 'report',
'lang' => 'NOTIFICATION_TYPE_REPORT', 'lang' => 'NOTIFICATION_TYPE_REPORT',
'group' => 'NOTIFICATION_GROUP_MODERATION',
); );
/** /**

View file

@ -53,6 +53,7 @@ class phpbb_notification_type_report_post extends phpbb_notification_type_post_i
public static $notification_option = array( public static $notification_option = array(
'id' => 'report', 'id' => 'report',
'lang' => 'NOTIFICATION_TYPE_REPORT', 'lang' => 'NOTIFICATION_TYPE_REPORT',
'group' => 'NOTIFICATION_GROUP_MODERATION',
); );
/** /**

View file

@ -37,6 +37,16 @@ class phpbb_notification_type_topic extends phpbb_notification_type_base
*/ */
protected $language_key = 'NOTIFICATION_TOPIC'; protected $language_key = 'NOTIFICATION_TOPIC';
/**
* 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', 'lang', and 'group')
*/
public static $notification_option = array(
'group' => 'NOTIFICATION_GROUP_POSTING',
);
/** /**
* Get the type of notification this is * Get the type of notification this is
* phpbb_notification_type_ * phpbb_notification_type_

View file

@ -41,11 +41,12 @@ class phpbb_notification_type_topic_in_queue extends phpbb_notification_type_top
* Notification option data (for outputting to the user) * Notification option data (for outputting to the user)
* *
* @var bool|array False if the service should use it's default data * @var bool|array False if the service should use it's default data
* Array of data (including keys 'id' and 'lang') * Array of data (including keys 'id', 'lang', and 'group')
*/ */
public static $notification_option = array( public static $notification_option = array(
'id' => 'needs_approval', 'id' => 'needs_approval',
'lang' => 'NOTIFICATION_TYPE_IN_MODERATION_QUEUE', 'lang' => 'NOTIFICATION_TYPE_IN_MODERATION_QUEUE',
'group' => 'NOTIFICATION_GROUP_MODERATION',
); );
/** /**

View file

@ -44,30 +44,33 @@ class ucp_notifications
$notification_methods = $phpbb_notifications->get_subscription_methods(); $notification_methods = $phpbb_notifications->get_subscription_methods();
foreach($phpbb_notifications->get_subscription_types() as $type => $data) foreach($phpbb_notifications->get_subscription_types() as $group => $subscription_types)
{ {
if ($request->is_set_post($type . '_notification') && !isset($subscriptions[$type])) foreach($subscription_types as $type => $data)
{ {
// add if ($request->is_set_post($type . '_notification') && !isset($subscriptions[$type]))
$phpbb_notifications->add_subscription($type);
}
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) && (!isset($subscriptions[$type]) || !in_array($method, $subscriptions[$type])))
{ {
// add // add
$phpbb_notifications->add_subscription($type, 0, $method); $phpbb_notifications->add_subscription($type);
} }
else if (!$request->is_set_post($type . '_' . $method) && isset($subscriptions[$type]) && in_array($method, $subscriptions[$type])) else if (!$request->is_set_post($type . '_notification') && isset($subscriptions[$type]))
{ {
// remove // remove
$phpbb_notifications->delete_subscription($type, 0, $method); $phpbb_notifications->delete_subscription($type);
}
foreach($notification_methods as $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 if (!$request->is_set_post($type . '_' . $method) && isset($subscriptions[$type]) && in_array($method, $subscriptions[$type]))
{
// remove
$phpbb_notifications->delete_subscription($type, 0, $method);
}
} }
} }
} }
@ -172,25 +175,33 @@ class ucp_notifications
$notification_methods = $phpbb_notifications->get_subscription_methods(); $notification_methods = $phpbb_notifications->get_subscription_methods();
$subscriptions = $phpbb_notifications->get_subscriptions(false, true); $subscriptions = $phpbb_notifications->get_subscriptions(false, true);
foreach($phpbb_notifications->get_subscription_types() as $type => $data) foreach($phpbb_notifications->get_subscription_types() as $group => $subscription_types)
{ {
$template->assign_block_vars($block, array( $template->assign_block_vars($block, array(
'TYPE' => $type, 'GROUP_NAME' => $user->lang($group),
'NAME' => (is_array($data) && isset($data['lang'])) ? $user->lang($data['lang']) : $user->lang('NOTIFICATION_TYPE_' . strtoupper($type)),
'SUBSCRIBED' => (isset($subscriptions[$type])) ? true : false,
)); ));
foreach($notification_methods as $method) foreach($subscription_types as $type => $data)
{ {
$template->assign_block_vars($block . '.notification_methods', array( $template->assign_block_vars($block, array(
'METHOD' => $method, 'TYPE' => $type,
'NAME' => $user->lang('NOTIFICATION_METHOD_' . strtoupper($method)), 'NAME' => $user->lang($data['lang']),
'EXPLAIN' => (isset($user->lang[$data['lang'] . '_EXPLAIN'])) ? $user->lang($data['lang'] . '_EXPLAIN') : '',
'SUBSCRIBED' => (isset($subscriptions[$type]) && in_array($method, $subscriptions[$type])) ? true : false, 'SUBSCRIBED' => (isset($subscriptions[$type])) ? true : false,
)); ));
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,
));
}
} }
} }
} }

View file

@ -292,6 +292,9 @@ $lang = array_merge($lang, array(
'NOTIFICATIONS_MARK_ALL_READ' => 'Mark all notifications read', '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_CONFIRM' => 'Are you sure you want to mark all notifications read?',
'NOTIFICATIONS_MARK_ALL_READ_SUCCESS' => 'All notifications have been marked read successfully.', 'NOTIFICATIONS_MARK_ALL_READ_SUCCESS' => 'All notifications have been marked read successfully.',
'NOTIFICATION_GROUP_MISCELLANEOUS' => 'Miscellaneous Notifications',
'NOTIFICATION_GROUP_MODERATION' => 'Moderation Notifications',
'NOTIFICATION_GROUP_POSTING' => 'Posting Notifications',
'NOTIFICATION_METHOD_EMAIL' => 'Email', 'NOTIFICATION_METHOD_EMAIL' => 'Email',
'NOTIFICATION_METHOD_JABBER' => 'Jabber', 'NOTIFICATION_METHOD_JABBER' => 'Jabber',
'NOTIFICATION_TYPE' => 'Notification type', 'NOTIFICATION_TYPE' => 'Notification type',

View file

@ -23,17 +23,28 @@
<ul class="topiclist cplist"> <ul class="topiclist cplist">
<!-- BEGIN notification_types --> <!-- BEGIN notification_types -->
<li class="row<!-- IF notification_types.S_ROW_COUNT is odd --> bg1<!-- ELSE --> bg2<!-- ENDIF -->"> <!-- IF notification_types.GROUP_NAME -->
<dl> <li class="row bg3">
<dt> <dl>
{notification_types.NAME} <dt>
</dt> {notification_types.GROUP_NAME}
<!-- BEGIN notification_methods --> </dt>
<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> </dl>
<!-- END notification_methods --> </li>
<dd class="mark"><input type="checkbox" name="{notification_types.TYPE}_notification"<!-- IF notification_types.SUBSCRIBED --> checked="checked"<!-- ENDIF --> /> <dfn>{notification_methods.NAME}</dfn></dd> <!-- ELSE -->
</dl> <li class="row<!-- IF notification_types.S_ROW_COUNT is odd --> bg1<!-- ELSE --> bg2<!-- ENDIF -->">
</li> <dl>
<dt>
{notification_types.NAME}
<!-- IF notification_types.EXPLAIN --><br />&nbsp; &nbsp;{notification_types.EXPLAIN}<!-- ENDIF -->
</dt>
<!-- BEGIN notification_methods -->
<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"<!-- IF notification_types.SUBSCRIBED --> checked="checked"<!-- ENDIF --> /> <dfn>{notification_methods.NAME}</dfn></dd>
</dl>
</li>
<!-- ENDIF -->
<!-- END notification_types --> <!-- END notification_types -->
</ul> </ul>
<!-- ELSE --> <!-- ELSE -->