mirror of
https://github.com/phpbb/phpbb.git
synced 2025-06-25 20:58:55 +00:00
[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
This commit is contained in:
parent
544fbe35f4
commit
ae91a0a846
12 changed files with 153 additions and 20 deletions
|
@ -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];
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -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_
|
||||
|
|
|
@ -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_
|
||||
|
|
|
@ -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 -------------------
|
||||
*/
|
||||
|
|
|
@ -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_
|
||||
|
|
|
@ -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_
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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();
|
||||
|
||||
|
|
|
@ -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')),
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
<div class="inner">
|
||||
<ul class="topiclist">
|
||||
<li class="header">
|
||||
<dl class="icon">
|
||||
<dl>
|
||||
<dt>{L_NOTIFICATION_TYPE}</dt>
|
||||
<!-- BEGIN notification_methods -->
|
||||
<dd class="mark">{notification_methods.NAME}</dd>
|
||||
|
@ -15,11 +15,11 @@
|
|||
</dl>
|
||||
</li>
|
||||
</ul>
|
||||
<ul class="topiclist cplist">
|
||||
<ul class="topiclist cplist">
|
||||
|
||||
<!-- BEGIN notification_types -->
|
||||
<li class="row<!-- IF notification_types.S_ROW_COUNT is odd --> bg1<!-- ELSE --> bg2<!-- ENDIF -->">
|
||||
<dl class="icon">
|
||||
<dl>
|
||||
<dt>
|
||||
{notification_types.NAME}
|
||||
</dt>
|
||||
|
|
Loading…
Add table
Reference in a new issue