phpBB

Code Changes

File: phpbb/notification/manager.php

  Unmodified   Added   Modified   Removed
Line 22Line 22
{
/** @var array */
protected $notification_types;

{
/** @var array */
protected $notification_types;

 

/** @var array */
protected $subscription_types;


/** @var array */
protected $notification_methods;


/** @var array */
protected $notification_methods;

Line 34Line 37

/** @var \phpbb\config\config */
protected $config;


/** @var \phpbb\config\config */
protected $config;

 

/** @var \phpbb\event\dispatcher_interface */
protected $phpbb_dispatcher;


/** @var \phpbb\db\driver\driver_interface */
protected $db;


/** @var \phpbb\db\driver\driver_interface */
protected $db;

Line 67Line 73
	* @param ContainerInterface $phpbb_container
* @param \phpbb\user_loader $user_loader
* @param \phpbb\config\config $config

	* @param ContainerInterface $phpbb_container
* @param \phpbb\user_loader $user_loader
* @param \phpbb\config\config $config

 
	* @param \phpbb\event\dispatcher_interface $phpbb_dispatcher

	* @param \phpbb\db\driver\driver_interface $db
* @param \phpbb\cache\service $cache
* @param \phpbb\user $user

	* @param \phpbb\db\driver\driver_interface $db
* @param \phpbb\cache\service $cache
* @param \phpbb\user $user

Line 78Line 85
	*
* @return \phpbb\notification\manager
*/

	*
* @return \phpbb\notification\manager
*/

	public function __construct($notification_types, $notification_methods, ContainerInterface $phpbb_container, \phpbb\user_loader $user_loader, \phpbb\config\config $config, \phpbb\db\driver\driver_interface $db, \phpbb\cache\service $cache, $user, $phpbb_root_path, $php_ext, $notification_types_table, $notifications_table, $user_notifications_table)

	public function __construct($notification_types, $notification_methods, ContainerInterface $phpbb_container, \phpbb\user_loader $user_loader, \phpbb\config\config $config, \phpbb\event\dispatcher_interface $phpbb_dispatcher, \phpbb\db\driver\driver_interface $db, \phpbb\cache\service $cache, $user, $phpbb_root_path, $php_ext, $notification_types_table, $notifications_table, $user_notifications_table)

	{
$this->notification_types = $notification_types;
$this->notification_methods = $notification_methods;

	{
$this->notification_types = $notification_types;
$this->notification_methods = $notification_methods;

Line 86Line 93

$this->user_loader = $user_loader;
$this->config = $config;


$this->user_loader = $user_loader;
$this->config = $config;

 
		$this->phpbb_dispatcher = $phpbb_dispatcher;

		$this->db = $db;
$this->cache = $cache;
$this->user = $user;

		$this->db = $db;
$this->cache = $cache;
$this->user = $user;

Line 178Line 186
		if (!$options['count_total'] || $total_count)
{
$rowset = array();

		if (!$options['count_total'] || $total_count)
{
$rowset = array();

 
			$selected_unread_count = 0;


// Get the main notifications
$sql = 'SELECT n.*, nt.notification_type_name
FROM ' . $this->notifications_table . ' n, ' . $this->notification_types_table . ' nt
WHERE n.user_id = ' . (int) $options['user_id'] .


// Get the main notifications
$sql = 'SELECT n.*, nt.notification_type_name
FROM ' . $this->notifications_table . ' n, ' . $this->notification_types_table . ' nt
WHERE n.user_id = ' . (int) $options['user_id'] .

					(($options['notification_id']) ? ((is_array($options['notification_id'])) ? ' AND ' . $this->db->sql_in_set('n.notification_id', $options['notification_id']) : ' AND n.notification_id = ' . (int) $options['notification_id']) : '') . '

					(($options['notification_id']) ? ' AND ' . $this->db->sql_in_set('n.notification_id', $options['notification_id']) : '') . '

					AND nt.notification_type_id = n.notification_type_id
AND nt.notification_type_enabled = 1
ORDER BY n.' . $this->db->sql_escape($options['order_by']) . ' ' . $this->db->sql_escape($options['order_dir']);

					AND nt.notification_type_id = n.notification_type_id
AND nt.notification_type_enabled = 1
ORDER BY n.' . $this->db->sql_escape($options['order_by']) . ' ' . $this->db->sql_escape($options['order_dir']);

Line 192Line 201
			while ($row = $this->db->sql_fetchrow($result))
{
$rowset[$row['notification_id']] = $row;

			while ($row = $this->db->sql_fetchrow($result))
{
$rowset[$row['notification_id']] = $row;

 
				$selected_unread_count += (int) !$row['notification_read'];

			}
$this->db->sql_freeresult($result);

// Get all unread notifications

			}
$this->db->sql_freeresult($result);

// Get all unread notifications

			if ($unread_count && $options['all_unread'] && !empty($rowset))

			if ($selected_unread_count < $unread_count && $options['all_unread'] && !empty($rowset))

			{
$sql = 'SELECT n.*, nt.notification_type_name
FROM ' . $this->notifications_table . ' n, ' . $this->notification_types_table . ' nt

			{
$sql = 'SELECT n.*, nt.notification_type_name
FROM ' . $this->notifications_table . ' n, ' . $this->notification_types_table . ' nt

Line 265Line 275
		$sql = 'UPDATE ' . $this->notifications_table . "
SET notification_read = 1
WHERE notification_time <= " . (int) $time .

		$sql = 'UPDATE ' . $this->notifications_table . "
SET notification_read = 1
WHERE notification_time <= " . (int) $time .

				(($notification_type_name !== false) ? ' AND ' .
(is_array($notification_type_name) ? $this->db->sql_in_set('notification_type_id', $this->get_notification_type_ids($notification_type_name)) : 'notification_type_id = ' . $this->get_notification_type_id($notification_type_name)) : '') .
(($user_id !== false) ? ' AND ' . (is_array($user_id) ? $this->db->sql_in_set('user_id', $user_id) : 'user_id = ' . (int) $user_id) : '') .
(($item_id !== false) ? ' AND ' . (is_array($item_id) ? $this->db->sql_in_set('item_id', $item_id) : 'item_id = ' . (int) $item_id) : '');

				(($notification_type_name !== false) ? ' AND ' . $this->db->sql_in_set('notification_type_id', $this->get_notification_type_ids($notification_type_name)) : '') .
(($user_id !== false) ? ' AND ' . $this->db->sql_in_set('user_id', $user_id) : '') .
(($item_id !== false) ? ' AND ' . $this->db->sql_in_set('item_id', $item_id) : '');


		$this->db->sql_query($sql);
}


		$this->db->sql_query($sql);
}


Line 287Line 296
		$sql = 'UPDATE ' . $this->notifications_table . "
SET notification_read = 1
WHERE notification_time <= " . (int) $time .

		$sql = 'UPDATE ' . $this->notifications_table . "
SET notification_read = 1
WHERE notification_time <= " . (int) $time .

				(($notification_type_name !== false) ? ' AND ' .
(is_array($notification_type_name) ? $this->db->sql_in_set('notification_type_id', $this->get_notification_type_ids($notification_type_name)) : 'notification_type_id = ' . $this->get_notification_type_id($notification_type_name)) : '') .
(($item_parent_id !== false) ? ' AND ' . (is_array($item_parent_id) ? $this->db->sql_in_set('item_parent_id', $item_parent_id) : 'item_parent_id = ' . (int) $item_parent_id) : '') .
(($user_id !== false) ? ' AND ' . (is_array($user_id) ? $this->db->sql_in_set('user_id', $user_id) : 'user_id = ' . (int) $user_id) : '');

				(($notification_type_name !== false) ? ' AND ' . $this->db->sql_in_set('notification_type_id', $this->get_notification_type_ids($notification_type_name)) : '') .
(($item_parent_id !== false) ? ' AND ' . $this->db->sql_in_set('item_parent_id', $item_parent_id, false, true) : '') .
(($user_id !== false) ? ' AND ' . $this->db->sql_in_set('user_id', $user_id) : '');


		$this->db->sql_query($sql);
}


		$this->db->sql_query($sql);
}


Line 307Line 315
		$sql = 'UPDATE ' . $this->notifications_table . "
SET notification_read = 1
WHERE notification_time <= " . (int) $time . '

		$sql = 'UPDATE ' . $this->notifications_table . "
SET notification_read = 1
WHERE notification_time <= " . (int) $time . '

				AND ' . ((is_array($notification_id)) ? $this->db->sql_in_set('notification_id', $notification_id) : 'notification_id = ' . (int) $notification_id);

				AND ' . $this->db->sql_in_set('notification_id', $notification_id);

		$this->db->sql_query($sql);
}


		$this->db->sql_query($sql);
}


Line 346Line 354

// find out which users want to receive this type of notification
$notify_users = $this->get_item_type_class($notification_type_name)->find_users_for_notification($data, $options);


// find out which users want to receive this type of notification
$notify_users = $this->get_item_type_class($notification_type_name)->find_users_for_notification($data, $options);

 

/**
* Allow filtering the notify_users array for a notification that is about to be sent.
* Here, $notify_users is already filtered by f_read and the ignored list included in the options variable
*
* @event core.notification_manager_add_notifications
* @var string notification_type_name The forum id from where the topic belongs
* @var array data Data specific for the notification_type_name used will be inserted
* @var array notify_users The array of userid that are going to be notified for this notification. Set to array() to cancel.
* @var array options The options that were used when this method was called (read only)
*
* @since 3.1.3-RC1
*/
$vars = array(
'notification_type_name',
'data',
'notify_users',
'options',
);
extract($this->phpbb_dispatcher->trigger_event('core.notification_manager_add_notifications', compact($vars)));


$this->add_notifications_for_users($notification_type_name, $data, $notify_users);



$this->add_notifications_for_users($notification_type_name, $data, $notify_users);


Line 512Line 540

$sql = 'DELETE FROM ' . $this->notifications_table . '
WHERE notification_type_id = ' . (int) $notification_type_id . '


$sql = 'DELETE FROM ' . $this->notifications_table . '
WHERE notification_type_id = ' . (int) $notification_type_id . '

				AND ' . (is_array($item_id) ? $this->db->sql_in_set('item_id', $item_id) : 'item_id = ' . (int) $item_id) .
(($parent_id !== false) ? ' AND ' . ((is_array($parent_id) ? $this->db->sql_in_set('item_parent_id', $parent_id) : 'item_parent_id = ' . (int) $parent_id)) : '');

				AND ' . $this->db->sql_in_set('item_id', $item_id) .
(($parent_id !== false) ? ' AND ' . $this->db->sql_in_set('item_parent_id', $parent_id) : '');

		$this->db->sql_query($sql);
}


		$this->db->sql_query($sql);
}


Line 524Line 552
	*/
public function get_subscription_types()
{

	*/
public function get_subscription_types()
{

		$subscription_types = array();



		if ($this->subscription_types === null)
{
$this->subscription_types = array();


foreach ($this->notification_types as $type_name => $data)
{


foreach ($this->notification_types as $type_name => $data)
{

Line 533Line 563
			if ($type instanceof \phpbb\notification\type\type_interface && $type->is_available())
{
$options = array_merge(array(

			if ($type instanceof \phpbb\notification\type\type_interface && $type->is_available())
{
$options = array_merge(array(

					'id'		=> $type->get_type(),
'lang' => 'NOTIFICATION_TYPE_' . strtoupper($type->get_type()),
'group' => 'NOTIFICATION_GROUP_MISCELLANEOUS',

						'id' => $type->get_type(),
'lang' => 'NOTIFICATION_TYPE_' . strtoupper($type->get_type()),
'group' => 'NOTIFICATION_GROUP_MISCELLANEOUS',

				), (($type::$notification_option !== false) ? $type::$notification_option : array()));


				), (($type::$notification_option !== false) ? $type::$notification_option : array()));


				$subscription_types[$options['group']][$options['id']] = $options;

					$this->subscription_types[$options['group']][$options['id']] = $options;

			}
}

// Move Miscellaneous to the very last section

			}
}

// Move Miscellaneous to the very last section

		if (isset($subscription_types['NOTIFICATION_GROUP_MISCELLANEOUS']))

			if (isset($this->subscription_types['NOTIFICATION_GROUP_MISCELLANEOUS']))

		{

		{

			$miscellaneous = $subscription_types['NOTIFICATION_GROUP_MISCELLANEOUS'];
unset($subscription_types['NOTIFICATION_GROUP_MISCELLANEOUS']);
$subscription_types['NOTIFICATION_GROUP_MISCELLANEOUS'] = $miscellaneous;


				$miscellaneous = $this->subscription_types['NOTIFICATION_GROUP_MISCELLANEOUS'];
unset($this->subscription_types['NOTIFICATION_GROUP_MISCELLANEOUS']);
$this->subscription_types['NOTIFICATION_GROUP_MISCELLANEOUS'] = $miscellaneous;
}

		}


		}


		return $subscription_types;

		return $this->subscription_types;

	}

/**

	}

/**

Line 891Line 922
	public function get_notification_type_id($notification_type_name)
{
$notification_type_ids = $this->cache->get('notification_type_ids');

	public function get_notification_type_id($notification_type_name)
{
$notification_type_ids = $this->cache->get('notification_type_ids');

 

$this->db->sql_transaction('begin');


if ($notification_type_ids === false)
{


if ($notification_type_ids === false)
{

Line 912Line 945
		{
if (!isset($this->notification_types[$notification_type_name]) && !isset($this->notification_types['notification.type.' . $notification_type_name]))
{

		{
if (!isset($this->notification_types[$notification_type_name]) && !isset($this->notification_types['notification.type.' . $notification_type_name]))
{

 
				$this->db->sql_transaction('rollback');

				throw new \phpbb\notification\exception($this->user->lang('NOTIFICATION_TYPE_NOT_EXIST', $notification_type_name));
}


				throw new \phpbb\notification\exception($this->user->lang('NOTIFICATION_TYPE_NOT_EXIST', $notification_type_name));
}


Line 925Line 959

$this->cache->put('notification_type_ids', $notification_type_ids);
}


$this->cache->put('notification_type_ids', $notification_type_ids);
}

 

$this->db->sql_transaction('commit');


return $notification_type_ids[$notification_type_name];
}


return $notification_type_ids[$notification_type_name];
}

Line 932Line 968
	/**
* Get notification type ids (as an array)
*

	/**
* Get notification type ids (as an array)
*

	* @param array $notification_type_names Array of strings

	* @param string|array $notification_type_names Notification type names

	* @return array Array of integers
*/

	* @return array Array of integers
*/

	public function get_notification_type_ids(array $notification_type_names)

	public function get_notification_type_ids($notification_type_names)

	{

	{

 
		if (!is_array($notification_type_names))
{
$notification_type_names = array($notification_type_names);
}


		$notification_type_ids = array();

foreach ($notification_type_names as $name)

		$notification_type_ids = array();

foreach ($notification_type_names as $name)