phpBB

Code Changes

File: phpbb/notification/manager.php

  Unmodified   Added   Modified   Removed
Line 38Line 38
	/** @var \phpbb\config\config */
protected $config;


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


	/** @var \phpbb\event\dispatcher */

	/** @var \phpbb\event\dispatcher_interface */

	protected $phpbb_dispatcher;

/** @var \phpbb\db\driver\driver_interface */

	protected $phpbb_dispatcher;

/** @var \phpbb\db\driver\driver_interface */

Line 73Line 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 $phpbb_dispatcher

	* @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 85Line 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\event\dispatcher $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)

	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 186Line 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 200Line 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 273Line 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 295Line 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, false, true) : '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 315Line 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 540Line 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 922Line 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 943Line 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 956Line 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 963Line 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)