1
0
mirror of https://github.com/phpbb/phpbb.git synced 2025-02-25 12:33:29 +01:00
php-phpbb/phpBB/includes/ucp/ucp_notifications.php
Nathan Guse 37e2473605 [ticket/11103] Rename classes
phpbb_notifications_service -> phpbb_notification_manager
phpbb_notifications_ -> phpbb_notification_

PHPBB3-11103
2012-10-04 13:39:54 -05:00

142 lines
4.0 KiB
PHP

<?php
/**
*
* @package notifications
* @copyright (c) 2012 phpBB Group
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
*
*/
/**
* @ignore
*/
if (!defined('IN_PHPBB'))
{
exit;
}
class ucp_notifications
{
public $u_action;
public function main($id, $mode)
{
global $phpbb_container;
add_form_key('ucp_notification_options');
$phpbb_notifications = $phpbb_container->get('notifications');
$template = $phpbb_container->get('template');
$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'))
{
if (!check_form_key('ucp_notification_options'))
{
trigger_error('FORM_INVALID');
}
$notification_methods = $phpbb_notifications->get_subscription_methods();
foreach($phpbb_notifications->get_subscription_types() as $type => $data)
{
if ($request->is_set_post($type . '_notification') && !isset($subscriptions[$type]))
{
// add
$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
$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);
}
}
}
}
// todo include language files for extensions?
$this->output_notification_methods('notification_methods', $phpbb_notifications, $template, $user);
$this->output_notification_types('notification_types', $phpbb_notifications, $template, $user);
$this->tpl_name = 'ucp_notifications';
$this->page_title = 'UCP_NOTIFICATIONS';
}
/**
* Output all the notification types to the template
*
* @param string $block
* @param phpbb_notification_manager $phpbb_notifications
* @param phpbb_template $template
* @param phpbb_user $user
*/
public function output_notification_types($block = 'notification_types', phpbb_notification_manager $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' => (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)
{
$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,
));
}
}
}
/**
* Output all the notification methods to the template
*
* @param string $block
* @param phpbb_notification_manager $phpbb_notifications
* @param phpbb_template $template
* @param phpbb_user $user
*/
public function output_notification_methods($block = 'notification_methods', phpbb_notification_manager $phpbb_notifications, phpbb_template $template, phpbb_user $user)
{
$notification_methods = $phpbb_notifications->get_subscription_methods();
foreach($notification_methods as $method)
{
$template->assign_block_vars($block, array(
'METHOD' => $method,
'NAME' => $user->lang('NOTIFICATION_METHOD_' . strtoupper($method)),
));
}
}
}