[ticket/16955] Clean up variable names and docblocks in notifications

PHPBB3-16955
This commit is contained in:
Marc Alexander 2022-12-26 14:49:18 +01:00
parent 733f4e2530
commit 96911b7403
No known key found for this signature in database
GPG key ID: 50E0D2423696F995
25 changed files with 235 additions and 202 deletions

View file

@ -873,9 +873,9 @@ class manager
/**
* Helper to get the list of methods enabled by default
*
* @return method\method_interface[]
* @return string[] Default method types
*/
public function get_default_methods()
public function get_default_methods(): array
{
$default_methods = array();
@ -894,13 +894,20 @@ class manager
* Helper to get the notifications item type class and set it up
*
* @param string $notification_type_name
* @param array $data
* @param array $data
*
* @return type\type_interface
* @throws \Exception When type name is not o notification type
*/
public function get_item_type_class($notification_type_name, $data = array())
{
$item = $this->load_object($notification_type_name);
if (!$item instanceof type\type_interface)
{
throw new \Exception('Supplied type name returned invalid service: ' . $notification_type_name);
}
$item->set_initial_data($data);
return $item;
@ -910,18 +917,30 @@ class manager
* Helper to get the notifications method class and set it up
*
* @param string $method_name
*
* @return method\method_interface
* @throws \Exception When object name is not o notification method
*/
public function get_method_class($method_name)
{
return $this->load_object($method_name);
$object = $this->load_object($method_name);
if (!$object instanceof method\method_interface)
{
throw new \Exception('Supplied method name returned invalid service: ' . $method_name);
}
return $object;
}
/**
* Helper to load objects (notification types/methods)
*
* @param string $object_name
*
* @return method\method_interface|type\type_interface
* @psalm-suppress NullableReturnStatement Invalid service will result in exception
* @throws \Exception When object name is not o notification method or type
*/
protected function load_object($object_name)
{
@ -932,6 +951,11 @@ class manager
$object->set_notification_manager($this);
}
if (!$object instanceof method\method_interface && !$object instanceof type\type_interface)
{
throw new \Exception('Supplied object name returned invalid service: ' . $object_name);
}
return $object;
}

View file

@ -126,7 +126,7 @@ class email extends \phpbb\notification\method\messenger_base
public function mark_notifications($notification_type_id, $item_id, $user_id, $time = false, $mark_read = true)
{
$sql = 'DELETE FROM ' . $this->notification_emails_table . '
WHERE ' . ($notification_type_id !== false ? $this->db->sql_in_set('notification_type_id', $notification_type_id) : '1=1') .
WHERE ' . ($notification_type_id !== false ? $this->db->sql_in_set('notification_type_id', is_array($notification_type_id) ? $notification_type_id : [$notification_type_id]) : '1=1') .
($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);
@ -138,7 +138,7 @@ class email extends \phpbb\notification\method\messenger_base
public function mark_notifications_by_parent($notification_type_id, $item_parent_id, $user_id, $time = false, $mark_read = true)
{
$sql = 'DELETE FROM ' . $this->notification_emails_table . '
WHERE ' . ($notification_type_id !== false ? $this->db->sql_in_set('notification_type_id', $notification_type_id) : '1=1') .
WHERE ' . ($notification_type_id !== false ? $this->db->sql_in_set('notification_type_id', is_array($notification_type_id) ? $notification_type_id : [$notification_type_id]) : '1=1') .
($user_id !== false ? ' AND ' . $this->db->sql_in_set('user_id', $user_id) : '') .
($item_parent_id !== false ? ' AND ' . $this->db->sql_in_set('item_parent_id', $item_parent_id, false, true) : '');
$this->db->sql_query($sql);

View file

@ -63,7 +63,7 @@ abstract class messenger_base extends \phpbb\notification\method\base
* @param int $notify_method Notify method for messenger (e.g. NOTIFY_IM)
* @param string $template_dir_prefix Base directory to prepend to the email template name
*
* @return null
* @return void
*/
protected function notify_using_messenger($notify_method, $template_dir_prefix = '')
{

View file

@ -102,7 +102,7 @@ interface method_interface
/**
* Mark notifications read or unread from a parent identifier
*
* @param string $notification_type_id Type identifier of item types
* @param string|int|array $notification_type_id Type identifier of item types
* @param bool|int|array $item_parent_id Item parent id or array of item parent ids. False to mark read for all item parent ids
* @param bool|int|array $user_id User id or array of user ids. False to mark read for all user ids
* @param bool|int $time Time at which to mark all notifications prior to as read. False to mark all as read. (Default: False)

View file

@ -68,15 +68,15 @@ class admin_activate_user extends \phpbb\notification\type\base
/**
* {@inheritdoc}
*/
public static function get_item_id($user)
public static function get_item_id($type_data)
{
return (int) $user['user_id'];
return (int) $type_data['user_id'];
}
/**
* {@inheritdoc}
*/
public static function get_item_parent_id($post)
public static function get_item_parent_id($type_data)
{
return 0;
}
@ -84,7 +84,7 @@ class admin_activate_user extends \phpbb\notification\type\base
/**
* {@inheritdoc}
*/
public function find_users_for_notification($user, $options = array())
public function find_users_for_notification($type_data, $options = array())
{
$options = array_merge(array(
'ignore_users' => array(),
@ -175,11 +175,11 @@ class admin_activate_user extends \phpbb\notification\type\base
/**
* {@inheritdoc}
*/
public function create_insert_array($user, $pre_create_data = array())
public function create_insert_array($type_data, $pre_create_data = array())
{
$this->set_data('user_actkey', $user['user_actkey']);
$this->notification_time = $user['user_regdate'];
$this->set_data('user_actkey', $type_data['user_actkey']);
$this->notification_time = $type_data['user_regdate'];
parent::create_insert_array($user, $pre_create_data);
parent::create_insert_array($type_data, $pre_create_data);
}
}

View file

@ -67,18 +67,18 @@ class approve_post extends \phpbb\notification\type\post
/**
* Find the users who want to receive notifications
*
* @param array $post Data from submit_post
* @param array $type_data Data from submit_post
* @param array $options Options for finding users for notification
*
* @return array
*/
public function find_users_for_notification($post, $options = array())
public function find_users_for_notification($type_data, $options = array())
{
$options = array_merge(array(
'ignore_users' => array(),
), $options);
return $this->get_authorised_recipients(array($post['poster_id']), $post['forum_id'], array_merge($options, array(
return $this->get_authorised_recipients(array($type_data['poster_id']), $type_data['forum_id'], array_merge($options, array(
'item_type' => static::$notification_option['id'],
)));
}
@ -89,12 +89,13 @@ class approve_post extends \phpbb\notification\type\post
* and load data, before create_insert_array() is run. The data
* returned from this function will be sent to create_insert_array().
*
* @param array $post Post data from submit_post
* @param array $type_data Post data from submit_post
* @param array $notify_users Notify users list
* Formatted from find_users_for_notification()
*
* @return array Whatever you want to send to create_insert_array().
*/
public function pre_create_insert_array($post, $notify_users)
public function pre_create_insert_array($type_data, $notify_users)
{
// In the parent class, this is used to check if the post is already
// read by a user and marks the notification read if it was marked read.
@ -106,11 +107,11 @@ class approve_post extends \phpbb\notification\type\post
/**
* {@inheritdoc}
*/
public function create_insert_array($post, $pre_create_data = array())
public function create_insert_array($type_data, $pre_create_data = array())
{
$this->set_data('post_subject', $post['post_subject']);
$this->set_data('post_subject', $type_data['post_subject']);
parent::create_insert_array($post, $pre_create_data);
parent::create_insert_array($type_data, $pre_create_data);
$this->notification_time = time();
}

View file

@ -67,18 +67,18 @@ class approve_topic extends \phpbb\notification\type\topic
/**
* Find the users who want to receive notifications
*
* @param array $post Data from submit_post
* @param array $type_data Data from submit_post
* @param array $options Options for finding users for notification
*
* @return array
*/
public function find_users_for_notification($post, $options = array())
public function find_users_for_notification($type_data, $options = array())
{
$options = array_merge(array(
'ignore_users' => array(),
), $options);
return $this->get_authorised_recipients(array($post['poster_id']), $post['forum_id'], array_merge($options, array(
return $this->get_authorised_recipients(array($type_data['poster_id']), $type_data['forum_id'], array_merge($options, array(
'item_type' => static::$notification_option['id'],
)));
}
@ -89,12 +89,13 @@ class approve_topic extends \phpbb\notification\type\topic
* and load data, before create_insert_array() is run. The data
* returned from this function will be sent to create_insert_array().
*
* @param array $post Post data from submit_post
* @param array $type_data Post data from submit_post
* @param array $notify_users Notify users list
* Formatted from find_users_for_notification()
*
* @return array Whatever you want to send to create_insert_array().
*/
public function pre_create_insert_array($post, $notify_users)
public function pre_create_insert_array($type_data, $notify_users)
{
// In the parent class, this is used to check if the post is already
// read by a user and marks the notification read if it was marked read.
@ -106,10 +107,10 @@ class approve_topic extends \phpbb\notification\type\topic
/**
* {@inheritdoc}
*/
public function create_insert_array($post, $pre_create_data = array())
public function create_insert_array($type_data, $pre_create_data = array())
{
parent::create_insert_array($post, $pre_create_data);
parent::create_insert_array($type_data, $pre_create_data);
$this->notification_time = time();
}

View file

@ -162,12 +162,12 @@ abstract class base implements \phpbb\notification\type\type_interface
/**
* Get special data (only important for the classes that extend this)
*
* @param string $name Name of the variable to get
* @param string|false $name Name of the variable to get, false if all data should be returned
* @return mixed
*/
protected function get_data($name)
{
return ($name === false) ? $this->data['notification_data'] : ((isset($this->data['notification_data'][$name])) ? $this->data['notification_data'][$name] : null);
return ($name === false) ? $this->data['notification_data'] : ($this->data['notification_data'][$name] ?? null);
}
/**

View file

@ -53,18 +53,18 @@ class bookmark extends \phpbb\notification\type\post
*/
public function is_available()
{
return $this->config['allow_bookmarks'];
return (bool) $this->config['allow_bookmarks'];
}
/**
* Find the users who want to receive notifications
*
* @param array $post Data from submit_post
* @param array $type_data Data from submit_post
* @param array $options Options for finding users for notification
*
* @return array
*/
public function find_users_for_notification($post, $options = array())
public function find_users_for_notification($type_data, $options = array())
{
$options = array_merge(array(
'ignore_users' => array(),
@ -74,8 +74,8 @@ class bookmark extends \phpbb\notification\type\post
$sql = 'SELECT user_id
FROM ' . BOOKMARKS_TABLE . '
WHERE ' . $this->db->sql_in_set('topic_id', $post['topic_id']) . '
AND user_id <> ' . (int) $post['poster_id'];
WHERE ' . $this->db->sql_in_set('topic_id', $type_data['topic_id']) . '
AND user_id <> ' . (int) $type_data['poster_id'];
$result = $this->db->sql_query($sql);
while ($row = $this->db->sql_fetchrow($result))
{
@ -83,7 +83,7 @@ class bookmark extends \phpbb\notification\type\post
}
$this->db->sql_freeresult($result);
$notify_users = $this->get_authorised_recipients($users, $post['forum_id'], $options, true);
$notify_users = $this->get_authorised_recipients($users, $type_data['forum_id'], $options, true);
if (empty($notify_users))
{
@ -92,7 +92,7 @@ class bookmark extends \phpbb\notification\type\post
// Try to find the users who already have been notified about replies and have not read the topic since and just update their notifications
$notified_users = $this->notification_manager->get_notified_users($this->get_type(), array(
'item_parent_id' => static::get_item_parent_id($post),
'item_parent_id' => static::get_item_parent_id($type_data),
'read' => 0,
));
@ -102,11 +102,11 @@ class bookmark extends \phpbb\notification\type\post
/** @var bookmark $notification */
$notification = $this->notification_manager->get_item_type_class($this->get_type(), $notification_data);
$update_responders = $notification->add_responders($post);
$update_responders = $notification->add_responders($type_data);
if (!empty($update_responders))
{
$this->notification_manager->update_notification($notification, $update_responders, array(
'item_parent_id' => self::get_item_parent_id($post),
'item_parent_id' => self::get_item_parent_id($type_data),
'read' => 0,
'user_id' => $user,
));

View file

@ -127,11 +127,11 @@ class disapprove_post extends \phpbb\notification\type\approve_post
/**
* {@inheritdoc}
*/
public function create_insert_array($post, $pre_create_data = array())
public function create_insert_array($type_data, $pre_create_data = array())
{
$this->set_data('disapprove_reason', $post['disapprove_reason']);
$this->set_data('disapprove_reason', $type_data['disapprove_reason']);
parent::create_insert_array($post, $pre_create_data);
parent::create_insert_array($type_data, $pre_create_data);
$this->notification_time = time();
}

View file

@ -127,11 +127,11 @@ class disapprove_topic extends \phpbb\notification\type\approve_topic
/**
* {@inheritdoc}
*/
public function create_insert_array($post, $pre_create_data = array())
public function create_insert_array($type_data, $pre_create_data = array())
{
$this->set_data('disapprove_reason', $post['disapprove_reason']);
$this->set_data('disapprove_reason', $type_data['disapprove_reason']);
parent::create_insert_array($post, $pre_create_data);
parent::create_insert_array($type_data, $pre_create_data);
$this->notification_time = time();
}

View file

@ -44,12 +44,12 @@ class forum extends \phpbb\notification\type\post
/**
* Find the users who want to receive notifications
*
* @param array $post Data from submit_post
* @param array $type_data Data from submit_post
* @param array $options Options for finding users for notification
*
* @return array
*/
public function find_users_for_notification($post, $options = [])
public function find_users_for_notification($type_data, $options = [])
{
$options = array_merge([
'ignore_users' => [],
@ -59,9 +59,9 @@ class forum extends \phpbb\notification\type\post
$sql = 'SELECT user_id
FROM ' . FORUMS_WATCH_TABLE . '
WHERE forum_id = ' . (int) $post['forum_id'] . '
WHERE forum_id = ' . (int) $type_data['forum_id'] . '
AND notify_status = ' . NOTIFY_YES . '
AND user_id <> ' . (int) $post['poster_id'];
AND user_id <> ' . (int) $type_data['poster_id'];
$result = $this->db->sql_query($sql);
while ($row = $this->db->sql_fetchrow($result))
{
@ -69,7 +69,7 @@ class forum extends \phpbb\notification\type\post
}
$this->db->sql_freeresult($result);
$notify_users = $this->get_authorised_recipients($users, $post['forum_id'], $options, true);
$notify_users = $this->get_authorised_recipients($users, $type_data['forum_id'], $options, true);
if (empty($notify_users))
{
@ -79,7 +79,7 @@ class forum extends \phpbb\notification\type\post
// Try to find the users who already have been notified about replies and have not read them
// Just update their notifications
$notified_users = $this->notification_manager->get_notified_users($this->get_type(), [
'item_parent_id' => static::get_item_parent_id($post),
'item_parent_id' => static::get_item_parent_id($type_data),
'read' => 0,
]);
@ -89,11 +89,11 @@ class forum extends \phpbb\notification\type\post
/** @var post $notification */
$notification = $this->notification_manager->get_item_type_class($this->get_type(), $notification_data);
$update_responders = $notification->add_responders($post);
$update_responders = $notification->add_responders($type_data);
if (!empty($update_responders))
{
$this->notification_manager->update_notification($notification, $update_responders, [
'item_parent_id' => self::get_item_parent_id($post),
'item_parent_id' => self::get_item_parent_id($type_data),
'read' => 0,
'user_id' => $user,
]);

View file

@ -58,24 +58,24 @@ class group_request extends \phpbb\notification\type\base
/**
* {@inheritdoc}
*/
public static function get_item_id($group)
public static function get_item_id($type_data)
{
return (int) $group['user_id'];
return (int) $type_data['user_id'];
}
/**
* {@inheritdoc}
*/
public static function get_item_parent_id($group)
public static function get_item_parent_id($type_data)
{
// Group id is the parent
return (int) $group['group_id'];
return (int) $type_data['group_id'];
}
/**
* {@inheritdoc}
*/
public function find_users_for_notification($group, $options = array())
public function find_users_for_notification($type_data, $options = array())
{
$options = array_merge(array(
'ignore_users' => array(),
@ -84,7 +84,7 @@ class group_request extends \phpbb\notification\type\base
$sql = 'SELECT user_id
FROM ' . USER_GROUP_TABLE . '
WHERE group_leader = 1
AND group_id = ' . (int) $group['group_id'];
AND group_id = ' . (int) $type_data['group_id'];
$result = $this->db->sql_query($sql);
$user_ids = array();
@ -160,10 +160,10 @@ class group_request extends \phpbb\notification\type\base
/**
* {@inheritdoc}
*/
public function create_insert_array($group, $pre_create_data = array())
public function create_insert_array($type_data, $pre_create_data = array())
{
$this->set_data('group_name', $group['group_name']);
$this->set_data('group_name', $type_data['group_name']);
parent::create_insert_array($group, $pre_create_data);
parent::create_insert_array($type_data, $pre_create_data);
}
}

View file

@ -34,15 +34,15 @@ class group_request_approved extends \phpbb\notification\type\base
/**
* {@inheritdoc}
*/
public static function get_item_id($group)
public static function get_item_id($type_data)
{
return (int) $group['group_id'];
return (int) $type_data['group_id'];
}
/**
* {@inheritdoc}
*/
public static function get_item_parent_id($group)
public static function get_item_parent_id($type_data)
{
return 0;
}
@ -50,13 +50,13 @@ class group_request_approved extends \phpbb\notification\type\base
/**
* {@inheritdoc}
*/
public function find_users_for_notification($group, $options = array())
public function find_users_for_notification($type_data, $options = array())
{
$users = array();
$group['user_ids'] = (!is_array($group['user_ids'])) ? array($group['user_ids']) : $group['user_ids'];
$type_data['user_ids'] = (!is_array($type_data['user_ids'])) ? array($type_data['user_ids']) : $type_data['user_ids'];
foreach ($group['user_ids'] as $user_id)
foreach ($type_data['user_ids'] as $user_id)
{
$users[$user_id] = $this->notification_manager->get_default_methods();
}
@ -83,11 +83,11 @@ class group_request_approved extends \phpbb\notification\type\base
/**
* {@inheritdoc}
*/
public function create_insert_array($group, $pre_create_data = array())
public function create_insert_array($type_data, $pre_create_data = array())
{
$this->set_data('group_name', $group['group_name']);
$this->set_data('group_name', $type_data['group_name']);
parent::create_insert_array($group, $pre_create_data);
parent::create_insert_array($type_data, $pre_create_data);
}
/**

View file

@ -59,24 +59,24 @@ class mention extends post
/**
* {@inheritDoc}
*/
public function find_users_for_notification($post, $options = array())
public function find_users_for_notification($type_data, $options = array())
{
$options = array_merge(array(
'ignore_users' => array(),
), $options);
$user_ids = $this->helper->get_mentioned_user_ids($post['post_text']);
$user_ids = $this->helper->get_mentioned_user_ids($type_data['post_text']);
$user_ids = array_unique($user_ids);
$user_ids = array_diff($user_ids, [(int) $post['poster_id']]);
$user_ids = array_diff($user_ids, [(int) $type_data['poster_id']]);
if (empty($user_ids))
{
return array();
}
return $this->get_authorised_recipients($user_ids, $post['forum_id'], $options, true);
return $this->get_authorised_recipients($user_ids, $type_data['forum_id'], $options, true);
}
/**

View file

@ -67,19 +67,19 @@ class pm extends \phpbb\notification\type\base
/**
* Get the id of the
*
* @param array $pm The data from the private message
* @param array $type_data The data from the private message
*/
public static function get_item_id($pm)
public static function get_item_id($type_data)
{
return (int) $pm['msg_id'];
return (int) $type_data['msg_id'];
}
/**
* Get the id of the parent
*
* @param array $pm The data from the pm
* @param array $type_data The data from the pm
*/
public static function get_item_parent_id($pm)
public static function get_item_parent_id($type_data)
{
// No parent
return 0;
@ -88,27 +88,27 @@ class pm extends \phpbb\notification\type\base
/**
* Find the users who want to receive notifications
*
* @param array $pm Data from submit_pm
* @param array $type_data Data from submit_pm
* @param array $options Options for finding users for notification
*
* @return array
*/
public function find_users_for_notification($pm, $options = array())
public function find_users_for_notification($type_data, $options = array())
{
$options = array_merge(array(
'ignore_users' => array(),
), $options);
if (!count($pm['recipients']))
if (!count($type_data['recipients']))
{
return array();
}
unset($pm['recipients'][$pm['from_user_id']]);
unset($type_data['recipients'][$type_data['from_user_id']]);
$this->user_loader->load_users(array_keys($pm['recipients']));
$this->user_loader->load_users(array_keys($type_data['recipients']));
return $this->check_user_notification_options(array_keys($pm['recipients']), $options);
return $this->check_user_notification_options(array_keys($type_data['recipients']), $options);
}
/**
@ -194,12 +194,12 @@ class pm extends \phpbb\notification\type\base
/**
* {@inheritdoc}
*/
public function create_insert_array($pm, $pre_create_data = array())
public function create_insert_array($type_data, $pre_create_data = array())
{
$this->set_data('from_user_id', $pm['from_user_id']);
$this->set_data('from_user_id', $type_data['from_user_id']);
$this->set_data('message_subject', $pm['message_subject']);
$this->set_data('message_subject', $type_data['message_subject']);
parent::create_insert_array($pm, $pre_create_data);
parent::create_insert_array($type_data, $pre_create_data);
}
}

View file

@ -76,40 +76,42 @@ class post extends \phpbb\notification\type\base
*/
public function is_available()
{
return $this->config['allow_topic_notify'];
return (bool) $this->config['allow_topic_notify'];
}
/**
* Get the id of the item
*
* @param array $post The data from the post
* @param array $type_data The data from the post
*
* @return int The post id
*/
public static function get_item_id($post)
public static function get_item_id($type_data)
{
return (int) $post['post_id'];
return (int) $type_data['post_id'];
}
/**
* Get the id of the parent
*
* @param array $post The data from the post
* @param array $type_data The data from the post
*
* @return int The topic id
*/
public static function get_item_parent_id($post)
public static function get_item_parent_id($type_data)
{
return (int) $post['topic_id'];
return (int) $type_data['topic_id'];
}
/**
* Find the users who want to receive notifications
*
* @param array $post Data from submit_post
* @param array $type_data Data from submit_post
* @param array $options Options for finding users for notification
*
* @return array
*/
public function find_users_for_notification($post, $options = array())
public function find_users_for_notification($type_data, $options = array())
{
$options = array_merge(array(
'ignore_users' => array(),
@ -119,9 +121,9 @@ class post extends \phpbb\notification\type\base
$sql = 'SELECT user_id
FROM ' . TOPICS_WATCH_TABLE . '
WHERE topic_id = ' . (int) $post['topic_id'] . '
WHERE topic_id = ' . (int) $type_data['topic_id'] . '
AND notify_status = ' . NOTIFY_YES . '
AND user_id <> ' . (int) $post['poster_id'];
AND user_id <> ' . (int) $type_data['poster_id'];
$result = $this->db->sql_query($sql);
while ($row = $this->db->sql_fetchrow($result))
{
@ -129,7 +131,7 @@ class post extends \phpbb\notification\type\base
}
$this->db->sql_freeresult($result);
$notify_users = $this->get_authorised_recipients($users, $post['forum_id'], $options, true);
$notify_users = $this->get_authorised_recipients($users, $type_data['forum_id'], $options, true);
if (empty($notify_users))
{
@ -138,7 +140,7 @@ class post extends \phpbb\notification\type\base
// Try to find the users who already have been notified about replies and have not read the topic since and just update their notifications
$notified_users = $this->notification_manager->get_notified_users($this->get_type(), array(
'item_parent_id' => static::get_item_parent_id($post),
'item_parent_id' => static::get_item_parent_id($type_data),
'read' => 0,
));
@ -148,11 +150,11 @@ class post extends \phpbb\notification\type\base
/** @var post $notification */
$notification = $this->notification_manager->get_item_type_class($this->get_type(), $notification_data);
$update_responders = $notification->add_responders($post);
$update_responders = $notification->add_responders($type_data);
if (!empty($update_responders))
{
$this->notification_manager->update_notification($notification, $update_responders, array(
'item_parent_id' => self::get_item_parent_id($post),
'item_parent_id' => self::get_item_parent_id($type_data),
'read' => 0,
'user_id' => $user,
));
@ -338,12 +340,13 @@ class post extends \phpbb\notification\type\base
* and load data, before create_insert_array() is run. The data
* returned from this function will be sent to create_insert_array().
*
* @param array $post Post data from submit_post
* @param array $type_data Post data from submit_post
* @param array $notify_users Notify users list
* Formatted from find_users_for_notification()
*
* @return array Whatever you want to send to create_insert_array().
*/
public function pre_create_insert_array($post, $notify_users)
public function pre_create_insert_array($type_data, $notify_users)
{
if (!count($notify_users) || !$this->inherit_read_status)
{
@ -352,7 +355,7 @@ class post extends \phpbb\notification\type\base
$tracking_data = array();
$sql = 'SELECT user_id, mark_time FROM ' . TOPICS_TRACK_TABLE . '
WHERE topic_id = ' . (int) $post['topic_id'] . '
WHERE topic_id = ' . (int) $type_data['topic_id'] . '
AND ' . $this->db->sql_in_set('user_id', array_keys($notify_users));
$result = $this->db->sql_query($sql);
while ($row = $this->db->sql_fetchrow($result))
@ -367,21 +370,21 @@ class post extends \phpbb\notification\type\base
/**
* {@inheritdoc}
*/
public function create_insert_array($post, $pre_create_data = array())
public function create_insert_array($type_data, $pre_create_data = array())
{
$this->set_data('poster_id', $post['poster_id']);
$this->set_data('poster_id', $type_data['poster_id']);
$this->set_data('topic_title', $post['topic_title']);
$this->set_data('topic_title', $type_data['topic_title']);
$this->set_data('post_subject', $post['post_subject']);
$this->set_data('post_subject', $type_data['post_subject']);
$this->set_data('post_username', (($post['poster_id'] == ANONYMOUS) ? $post['post_username'] : ''));
$this->set_data('post_username', (($type_data['poster_id'] == ANONYMOUS) ? $type_data['post_username'] : ''));
$this->set_data('forum_id', $post['forum_id']);
$this->set_data('forum_id', $type_data['forum_id']);
$this->set_data('forum_name', $post['forum_name']);
$this->set_data('forum_name', $type_data['forum_name']);
$this->notification_time = $post['post_time'];
$this->notification_time = $type_data['post_time'];
// Topics can be "read" before they are public (while awaiting approval).
// Make sure that if the user has read the topic, it's marked as read in the notification
@ -390,7 +393,7 @@ class post extends \phpbb\notification\type\base
$this->notification_read = true;
}
parent::create_insert_array($post, $pre_create_data);
parent::create_insert_array($type_data, $pre_create_data);
}
/**

View file

@ -69,19 +69,19 @@ class post_in_queue extends \phpbb\notification\type\post
/**
* Find the users who want to receive notifications
*
* @param array $post Data from the post
* @param array $type_data Data from the post
* @param array $options Options for finding users for notification
*
* @return array
*/
public function find_users_for_notification($post, $options = array())
public function find_users_for_notification($type_data, $options = array())
{
$options = array_merge(array(
'ignore_users' => array(),
), $options);
// 0 is for global moderator permissions
$auth_approve = $this->auth->acl_get_list(false, $this->permission, array($post['forum_id'], 0));
$auth_approve = $this->auth->acl_get_list(false, $this->permission, array($type_data['forum_id'], 0));
if (empty($auth_approve))
{
@ -90,9 +90,9 @@ class post_in_queue extends \phpbb\notification\type\post
$has_permission = array();
if (isset($auth_approve[$post['forum_id']][$this->permission]))
if (isset($auth_approve[$type_data['forum_id']][$this->permission]))
{
$has_permission = $auth_approve[$post['forum_id']][$this->permission];
$has_permission = $auth_approve[$type_data['forum_id']][$this->permission];
}
if (isset($auth_approve[0][$this->permission]))
@ -101,13 +101,13 @@ class post_in_queue extends \phpbb\notification\type\post
}
sort($has_permission);
$auth_read = $this->auth->acl_get_list($has_permission, 'f_read', $post['forum_id']);
$auth_read = $this->auth->acl_get_list($has_permission, 'f_read', $type_data['forum_id']);
if (empty($auth_read))
{
return array();
}
return $this->check_user_notification_options($auth_read[$post['forum_id']]['f_read'], array_merge($options, array(
return $this->check_user_notification_options($auth_read[$type_data['forum_id']]['f_read'], array_merge($options, array(
'item_type' => static::$notification_option['id'],
)));
}
@ -133,9 +133,9 @@ class post_in_queue extends \phpbb\notification\type\post
/**
* {@inheritdoc}
*/
public function create_insert_array($post, $pre_create_data = array())
public function create_insert_array($type_data, $pre_create_data = array())
{
parent::create_insert_array($post, $pre_create_data);
parent::create_insert_array($type_data, $pre_create_data);
$this->notification_time = time();
}

View file

@ -64,18 +64,18 @@ class quote extends \phpbb\notification\type\post
/**
* Find the users who want to receive notifications
*
* @param array $post Data from submit_post
* @param array $type_data Data from submit_post
* @param array $options Options for finding users for notification
*
* @return array
*/
public function find_users_for_notification($post, $options = array())
public function find_users_for_notification($type_data, $options = array())
{
$options = array_merge(array(
'ignore_users' => array(),
), $options);
$usernames = $this->utils->get_outermost_quote_authors($post['post_text']);
$usernames = $this->utils->get_outermost_quote_authors($type_data['post_text']);
if (empty($usernames))
{
@ -91,7 +91,7 @@ class quote extends \phpbb\notification\type\post
$sql = 'SELECT user_id
FROM ' . USERS_TABLE . '
WHERE ' . $this->db->sql_in_set('username_clean', $usernames) . '
AND user_id <> ' . (int) $post['poster_id'];
AND user_id <> ' . (int) $type_data['poster_id'];
$result = $this->db->sql_query($sql);
while ($row = $this->db->sql_fetchrow($result))
{
@ -99,7 +99,7 @@ class quote extends \phpbb\notification\type\post
}
$this->db->sql_freeresult($result);
return $this->get_authorised_recipients($users, $post['forum_id'], $options, true);
return $this->get_authorised_recipients($users, $type_data['forum_id'], $options, true);
}
/**

View file

@ -69,12 +69,13 @@ class report_pm extends \phpbb\notification\type\pm
/**
* Get the id of the parent
*
* @param array $pm The data from the pm
* @param array $type_data The data from the pm
*
* @return int The report id
*/
public static function get_item_parent_id($pm)
public static function get_item_parent_id($type_data)
{
return (int) $pm['report_id'];
return (int) $type_data['report_id'];
}
/**
@ -92,33 +93,33 @@ class report_pm extends \phpbb\notification\type\pm
* Find the users who want to receive notifications
* (copied from post_in_queue)
*
* @param array $post Data from the post
* @param array $type_data Data from the post
* @param array $options Options for finding users for notification
*
* @return array
*/
public function find_users_for_notification($post, $options = [])
public function find_users_for_notification($type_data, $options = [])
{
$options = array_merge([
'ignore_users' => [],
], $options);
// Global
$post['forum_id'] = 0;
$type_data['forum_id'] = 0;
$auth_approve = $this->auth->acl_get_list(false, $this->permission, $post['forum_id']);
$auth_approve = $this->auth->acl_get_list(false, $this->permission, $type_data['forum_id']);
if (empty($auth_approve))
{
return [];
}
if (($key = array_search($this->user->data['user_id'], $auth_approve[$post['forum_id']][$this->permission])))
if (($key = array_search($this->user->data['user_id'], $auth_approve[$type_data['forum_id']][$this->permission])))
{
unset($auth_approve[$post['forum_id']][$this->permission][$key]);
unset($auth_approve[$type_data['forum_id']][$this->permission][$key]);
}
return $this->check_user_notification_options($auth_approve[$post['forum_id']][$this->permission], array_merge($options, [
return $this->check_user_notification_options($auth_approve[$type_data['forum_id']][$this->permission], array_merge($options, [
'item_type' => static::$notification_option['id'],
]));
}
@ -246,13 +247,13 @@ class report_pm extends \phpbb\notification\type\pm
/**
* {@inheritdoc}
*/
public function create_insert_array($post, $pre_create_data = [])
public function create_insert_array($type_data, $pre_create_data = [])
{
$this->set_data('reporter_id', $this->user->data['user_id']);
$this->set_data('reason_title', strtoupper($post['reason_title']));
$this->set_data('reason_description', $post['reason_description']);
$this->set_data('report_text', $post['report_text']);
$this->set_data('reason_title', strtoupper($type_data['reason_title']));
$this->set_data('reason_description', $type_data['reason_description']);
$this->set_data('report_text', $type_data['report_text']);
parent::create_insert_array($post, $pre_create_data);
parent::create_insert_array($type_data, $pre_create_data);
}
}

View file

@ -64,23 +64,23 @@ class report_pm_closed extends \phpbb\notification\type\pm
/**
* Find the users who want to receive notifications
*
* @param array $pm Data from submit_pm
* @param array $type_data Data from submit_pm
* @param array $options Options for finding users for notification
*
* @return array
*/
public function find_users_for_notification($pm, $options = [])
public function find_users_for_notification($type_data, $options = [])
{
$options = array_merge([
'ignore_users' => [],
], $options);
if ($pm['reporter'] == $this->user->data['user_id'])
if ($type_data['reporter'] == $this->user->data['user_id'])
{
return [];
}
return $this->check_user_notification_options([$pm['reporter']], $options);
return $this->check_user_notification_options([$type_data['reporter']], $options);
}
/**
@ -161,11 +161,11 @@ class report_pm_closed extends \phpbb\notification\type\pm
/**
* {@inheritdoc}
*/
public function create_insert_array($pm, $pre_create_data = [])
public function create_insert_array($type_data, $pre_create_data = [])
{
$this->set_data('closer_id', $pm['closer_id']);
$this->set_data('closer_id', $type_data['closer_id']);
parent::create_insert_array($pm, $pre_create_data);
parent::create_insert_array($type_data, $pre_create_data);
$this->notification_time = time();
}

View file

@ -75,14 +75,14 @@ class report_post extends \phpbb\notification\type\post_in_queue
/**
* Find the users who want to receive notifications
*
* @param array $post Data from the post
* @param array $type_data Data from the post
* @param array $options Options for finding users for notification
*
* @return array
*/
public function find_users_for_notification($post, $options = array())
public function find_users_for_notification($type_data, $options = array())
{
$notify_users = parent::find_users_for_notification($post, $options);
$notify_users = parent::find_users_for_notification($type_data, $options);
// never notify reporter
unset($notify_users[$this->user->data['user_id']]);
@ -212,13 +212,13 @@ class report_post extends \phpbb\notification\type\post_in_queue
/**
* {@inheritdoc}
*/
public function create_insert_array($post, $pre_create_data = array())
public function create_insert_array($type_data, $pre_create_data = array())
{
$this->set_data('reporter_id', $this->user->data['user_id']);
$this->set_data('reason_title', strtoupper($post['reason_title']));
$this->set_data('reason_description', $post['reason_description']);
$this->set_data('report_text', $post['report_text']);
$this->set_data('reason_title', strtoupper($type_data['reason_title']));
$this->set_data('reason_description', $type_data['reason_description']);
$this->set_data('report_text', $type_data['report_text']);
parent::create_insert_array($post, $pre_create_data);
parent::create_insert_array($type_data, $pre_create_data);
}
}

View file

@ -71,23 +71,23 @@ class report_post_closed extends \phpbb\notification\type\post
/**
* Find the users who want to receive notifications
*
* @param array $post Data from submit_post
* @param array $type_data Data from submit_post
* @param array $options Options for finding users for notification
*
* @return array
*/
public function find_users_for_notification($post, $options = [])
public function find_users_for_notification($type_data, $options = [])
{
$options = array_merge([
'ignore_users' => [],
], $options);
if ($post['reporter'] == $this->user->data['user_id'])
if ($type_data['reporter'] == $this->user->data['user_id'])
{
return [];
}
return $this->check_user_notification_options([$post['reporter']], $options);
return $this->check_user_notification_options([$type_data['reporter']], $options);
}
/**
@ -187,11 +187,11 @@ class report_post_closed extends \phpbb\notification\type\post
/**
* {@inheritdoc}
*/
public function create_insert_array($post, $pre_create_data = [])
public function create_insert_array($type_data, $pre_create_data = [])
{
$this->set_data('closer_id', $post['closer_id']);
$this->set_data('closer_id', $type_data['closer_id']);
parent::create_insert_array($post, $pre_create_data);
parent::create_insert_array($type_data, $pre_create_data);
$this->notification_time = time();
}

View file

@ -76,40 +76,42 @@ class topic extends \phpbb\notification\type\base
*/
public function is_available()
{
return $this->config['allow_forum_notify'];
return (bool) $this->config['allow_forum_notify'];
}
/**
* Get the id of the item
*
* @param array $post The data from the post
* @param array $type_data The data from the post
*
* @return int The topic id
*/
public static function get_item_id($post)
public static function get_item_id($type_data)
{
return (int) $post['topic_id'];
return (int) $type_data['topic_id'];
}
/**
* Get the id of the parent
*
* @param array $post The data from the post
* @param array $type_data The data from the post
*
* @return int The forum id
*/
public static function get_item_parent_id($post)
public static function get_item_parent_id($type_data)
{
return (int) $post['forum_id'];
return (int) $type_data['forum_id'];
}
/**
* Find the users who want to receive notifications
*
* @param array $topic Data from the topic
* @param array $type_data Data from the topic
* @param array $options Options for finding users for notification
*
* @return array
*/
public function find_users_for_notification($topic, $options = array())
public function find_users_for_notification($type_data, $options = array())
{
$options = array_merge(array(
'ignore_users' => array(),
@ -119,9 +121,9 @@ class topic extends \phpbb\notification\type\base
$sql = 'SELECT user_id
FROM ' . FORUMS_WATCH_TABLE . '
WHERE forum_id = ' . (int) $topic['forum_id'] . '
WHERE forum_id = ' . (int) $type_data['forum_id'] . '
AND notify_status = ' . NOTIFY_YES . '
AND user_id <> ' . (int) $topic['poster_id'];
AND user_id <> ' . (int) $type_data['poster_id'];
$result = $this->db->sql_query($sql);
while ($row = $this->db->sql_fetchrow($result))
{
@ -129,7 +131,7 @@ class topic extends \phpbb\notification\type\base
}
$this->db->sql_freeresult($result);
return $this->get_authorised_recipients($users, $topic['forum_id'], $options);
return $this->get_authorised_recipients($users, $type_data['forum_id'], $options);
}
/**
@ -254,12 +256,13 @@ class topic extends \phpbb\notification\type\base
* and load data, before create_insert_array() is run. The data
* returned from this function will be sent to create_insert_array().
*
* @param array $post Post data from submit_post
* @param array $type_data Post data from submit_post
* @param array $notify_users Notify users list
* Formatted from find_users_for_notification()
*
* @return array Whatever you want to send to create_insert_array().
*/
public function pre_create_insert_array($post, $notify_users)
public function pre_create_insert_array($type_data, $notify_users)
{
if (!count($notify_users) || !$this->inherit_read_status)
{
@ -268,7 +271,7 @@ class topic extends \phpbb\notification\type\base
$tracking_data = array();
$sql = 'SELECT user_id, mark_time FROM ' . TOPICS_TRACK_TABLE . '
WHERE topic_id = ' . (int) $post['topic_id'] . '
WHERE topic_id = ' . (int) $type_data['topic_id'] . '
AND ' . $this->db->sql_in_set('user_id', array_keys($notify_users));
$result = $this->db->sql_query($sql);
while ($row = $this->db->sql_fetchrow($result))
@ -283,17 +286,17 @@ class topic extends \phpbb\notification\type\base
/**
* {@inheritdoc}
*/
public function create_insert_array($post, $pre_create_data = array())
public function create_insert_array($type_data, $pre_create_data = array())
{
$this->set_data('poster_id', $post['poster_id']);
$this->set_data('poster_id', $type_data['poster_id']);
$this->set_data('topic_title', $post['topic_title']);
$this->set_data('topic_title', $type_data['topic_title']);
$this->set_data('post_username', (($post['poster_id'] == ANONYMOUS) ? $post['post_username'] : ''));
$this->set_data('post_username', (($type_data['poster_id'] == ANONYMOUS) ? $type_data['post_username'] : ''));
$this->set_data('forum_name', $post['forum_name']);
$this->set_data('forum_name', $type_data['forum_name']);
$this->notification_time = $post['post_time'];
$this->notification_time = $type_data['post_time'];
// Topics can be "read" before they are public (while awaiting approval).
// Make sure that if the user has read the topic, it's marked as read in the notification
@ -302,6 +305,6 @@ class topic extends \phpbb\notification\type\base
$this->notification_read = true;
}
parent::create_insert_array($post, $pre_create_data);
parent::create_insert_array($type_data, $pre_create_data);
}
}

View file

@ -69,19 +69,19 @@ class topic_in_queue extends \phpbb\notification\type\topic
/**
* Find the users who want to receive notifications
*
* @param array $topic Data from the topic
* @param array $type_data Data from the topic
* @param array $options Options for finding users for notification
*
* @return array
*/
public function find_users_for_notification($topic, $options = array())
public function find_users_for_notification($type_data, $options = array())
{
$options = array_merge(array(
'ignore_users' => array(),
), $options);
// 0 is for global moderator permissions
$auth_approve = $this->auth->acl_get_list(false, 'm_approve', array($topic['forum_id'], 0));
$auth_approve = $this->auth->acl_get_list(false, 'm_approve', array($type_data['forum_id'], 0));
if (empty($auth_approve))
{
@ -90,9 +90,9 @@ class topic_in_queue extends \phpbb\notification\type\topic
$has_permission = array();
if (isset($auth_approve[$topic['forum_id']][$this->permission]))
if (isset($auth_approve[$type_data['forum_id']][$this->permission]))
{
$has_permission = $auth_approve[$topic['forum_id']][$this->permission];
$has_permission = $auth_approve[$type_data['forum_id']][$this->permission];
}
if (isset($auth_approve[0][$this->permission]))
@ -101,13 +101,13 @@ class topic_in_queue extends \phpbb\notification\type\topic
}
sort($has_permission);
$auth_read = $this->auth->acl_get_list($has_permission, 'f_read', $topic['forum_id']);
$auth_read = $this->auth->acl_get_list($has_permission, 'f_read', $type_data['forum_id']);
if (empty($auth_read))
{
return array();
}
return $this->check_user_notification_options($auth_read[$topic['forum_id']]['f_read'], array_merge($options, array(
return $this->check_user_notification_options($auth_read[$type_data['forum_id']]['f_read'], array_merge($options, array(
'item_type' => static::$notification_option['id'],
)));
}
@ -125,9 +125,9 @@ class topic_in_queue extends \phpbb\notification\type\topic
/**
* {@inheritdoc}
*/
public function create_insert_array($topic, $pre_create_data = array())
public function create_insert_array($type_data, $pre_create_data = array())
{
parent::create_insert_array($topic, $pre_create_data);
parent::create_insert_array($type_data, $pre_create_data);
$this->notification_time = time();
}