class manager

Notifications service class

Properties

protected array $notification_types
protected array $subscription_types
protected method_interface[] $notification_methods
protected ContainerInterface $phpbb_container
protected user_loader $user_loader
protected dispatcher_interface $phpbb_dispatcher
protected driver_interface $db
protected service $cache
protected language $language
protected user $user
protected string $notification_types_table
protected string $user_notifications_table

Methods

__construct(array $notification_types, array $notification_methods, ContainerInterface $phpbb_container, user_loader $user_loader, dispatcher_interface $phpbb_dispatcher, driver_interface $db, service $cache, language $language, user $user, string $notification_types_table, string $user_notifications_table)

Notification Constructor

array
load_notifications(string $method_name, array $options = array())

Load the user's notifications for a given method

mark_notifications_read(bool|string|array $notification_type_name, bool|int|array $item_id, bool|int|array $user_id, bool|int $time = false) deprecated

Mark notifications read or unread for all available methods

mark_notifications(bool|string|array $notification_type_name, bool|int|array $item_id, bool|int|array $user_id, bool|int $time = false, bool $mark_read = true)

Mark notifications read or unread for all available methods

mark_notifications_read_by_parent(string|array $notification_type_name, bool|int|array $item_parent_id, bool|int|array $user_id, bool|int $time = false) deprecated

Mark notifications read or unread from a parent identifier for all available methods

mark_notifications_by_parent(string|array $notification_type_name, bool|int|array $item_parent_id, bool|int|array $user_id, bool|int $time = false, bool $mark_read = true)

Mark notifications read or unread from a parent identifier for all available methods

mark_notifications_by_id(string $method_name, int|array $notification_id, bool|int $time = false, bool $mark_read = true)

Mark notifications read or unread for a given method

array
add_notifications(string|array $notification_type_name, array $data, array $options = array())

Add a notification

add_notifications_for_users(string|array $notification_type_name, array $data, array $notify_users)

Add a notification for specific users

update_notifications(string|array $notification_type_name, array $data, array $options = array())

Update notification

update_notification(type_interface $notification, array $data, array $options = array())

Update a notification

delete_notifications(string|array $notification_type_name, int|array $item_id, mixed $parent_id = false, mixed $user_id = false)

Delete a notification

array
get_subscription_types()

Get all of the subscription types

array
get_subscription_methods()

Get all of the subscription methods

array
get_user_notifications(int $user_id)

Get user's notification data

array
get_global_subscriptions(bool|int $user_id = false)

Get global subscriptions (item_id = 0)

add_subscription(string $item_type, int $item_id = 0, string $method = null, bool|int $user_id = false)

Add a subscription

delete_subscription(string $item_type, int $item_id = 0, string $method = null, bool|int $user_id = false)

Delete a subscription

disable_notifications(string $notification_type_name)

Disable all notifications of a certain type

purge_notifications(string $notification_type_name)

Purge all notifications of a certain type

enable_notifications(string $notification_type_name)

Enable all notifications of a certain type

prune_notifications(int $timestamp, bool $only_read = true)

Delete all notifications older than a certain time

get_default_methods()

Helper to get the list of methods enabled by default

get_item_type_class(string $notification_type_name, array $data = array())

Helper to get the notifications item type class and set it up

get_method_class(string $method_name)

Helper to get the notifications method class and set it up

load_object(string $object_name)

Helper to load objects (notification types/methods)

int
get_notification_type_id(string $notification_type_name)

Get the notification type id from the name

array
get_notification_type_ids(string|array $notification_type_names)

Get notification type ids (as an array)

array
get_notified_users(bool|string|array $notification_type_name, array $options)

Find the users which are already notified

Details

at line 74
__construct(array $notification_types, array $notification_methods, ContainerInterface $phpbb_container, user_loader $user_loader, dispatcher_interface $phpbb_dispatcher, driver_interface $db, service $cache, language $language, user $user, string $notification_types_table, string $user_notifications_table)

Notification Constructor

Parameters

array $notification_types
array $notification_methods
ContainerInterface $phpbb_container
user_loader $user_loader
dispatcher_interface $phpbb_dispatcher
driver_interface $db
service $cache
language $language
user $user
string $notification_types_table
string $user_notifications_table

at line 111
array load_notifications(string $method_name, array $options = array())

Load the user's notifications for a given method

Parameters

string $method_name
array $options

Optional options to control what notifications are loaded notification_id Notification id to load (or array of notification ids) user_id User id to load notifications for (Default: $user->data['user_id']) order_by Order by (Default: notification_time) order_dir Order direction (Default: DESC) limit Number of notifications to load (Default: 5) start Notifications offset (Default: 0) all_unread Load all unread notifications? If set to true, count_unread is set to true (Default: false) count_unread Count all unread notifications? (Default: false) count_total Count all notifications? (Default: false)

Return Value

array

Array of information based on the request with keys: 'notifications' array of notification type objects 'unread_count' number of unread notifications the user has if count_unread is true in the options 'total_count' number of notifications the user has if count_total is true in the options

Exceptions

exception

when the method doesn't refer to a class extending \phpbb\notification\method\method_interface

at line 143
mark_notifications_read(bool|string|array $notification_type_name, bool|int|array $item_id, bool|int|array $user_id, bool|int $time = false) deprecated

deprecated since 3.2

Mark notifications read or unread for all available methods

Parameters

bool|string|array $notification_type_name

Type identifier or array of item types (only acceptable if the $data is identical for the specified types). False to mark read for all item types

bool|int|array $item_id

Item id or array of item ids. False to mark read for all item ids

bool|int|array $user_id

User id or array of user ids. False to mark read for all user ids

bool|int $time

Time at which to mark all notifications prior to as read. False to mark all as read. (Default: False)

at line 157
mark_notifications(bool|string|array $notification_type_name, bool|int|array $item_id, bool|int|array $user_id, bool|int $time = false, bool $mark_read = true)

Mark notifications read or unread for all available methods

Parameters

bool|string|array $notification_type_name

Type identifier or array of item types (only acceptable if the $data is identical for the specified types). False to mark read for all item types

bool|int|array $item_id

Item id or array of item ids. False to mark read for all item ids

bool|int|array $user_id

User id or array of user ids. False to mark read for all user ids

bool|int $time

Time at which to mark all notifications prior to as read. False to mark all as read. (Default: False)

bool $mark_read

Define if the notification as to be set to True or False. (Default: True)

at line 189
mark_notifications_read_by_parent(string|array $notification_type_name, bool|int|array $item_parent_id, bool|int|array $user_id, bool|int $time = false) deprecated

deprecated since 3.2

Mark notifications read or unread from a parent identifier for all available methods

Parameters

string|array $notification_type_name

Type identifier or array of item types (only acceptable if the $data is identical for the specified types)

bool|int|array $item_parent_id

Item parent id or array of item parent ids. False to mark read for all item parent ids

bool|int|array $user_id

User id or array of user ids. False to mark read for all user ids

bool|int $time

Time at which to mark all notifications prior to as read. False to mark all as read. (Default: False)

at line 203
mark_notifications_by_parent(string|array $notification_type_name, bool|int|array $item_parent_id, bool|int|array $user_id, bool|int $time = false, bool $mark_read = true)

Mark notifications read or unread from a parent identifier for all available methods

Parameters

string|array $notification_type_name

Type identifier or array of item types (only acceptable if the $data is identical for the specified types)

bool|int|array $item_parent_id

Item parent id or array of item parent ids. False to mark read for all item parent ids

bool|int|array $user_id

User id or array of user ids. False to mark read for all user ids

bool|int $time

Time at which to mark all notifications prior to as read. False to mark all as read. (Default: False)

bool $mark_read

Define if the notification as to be set to True or False. (Default: True)

at line 229
mark_notifications_by_id(string $method_name, int|array $notification_id, bool|int $time = false, bool $mark_read = true)

Mark notifications read or unread for a given method

Parameters

string $method_name
int|array $notification_id

Notification id or array of notification ids.

bool|int $time

Time at which to mark all notifications prior to as read. False to mark all as read. (Default: False)

bool $mark_read

Define if the notification as to be set to True or False. (Default: True)

at line 250
array add_notifications(string|array $notification_type_name, array $data, array $options = array())

Add a notification

Parameters

string|array $notification_type_name

Type identifier or array of item types (only acceptable if the $data is identical for the specified types) Note: If you send an array of types, any user who could receive multiple notifications from this single item will only receive a single notification. If they MUST receive multiple notifications, call this function multiple times instead of sending an array

array $data

Data specific for this type that will be inserted

array $options

Optional options to control what notifications are loaded ignore_users array of data to specify which users should not receive certain types of notifications

Return Value

array

Information about what users were notified and how they were notified

at line 332
add_notifications_for_users(string|array $notification_type_name, array $data, array $notify_users)

Add a notification for specific users

Parameters

string|array $notification_type_name

Type identifier or array of item types (only acceptable if the $data is identical for the specified types)

array $data

Data specific for this type that will be inserted

array $notify_users

User list to notify

at line 439
update_notifications(string|array $notification_type_name, array $data, array $options = array())

Update notification

Parameters

string|array $notification_type_name

Type identifier or array of item types (only acceptable if the $data is identical for the specified types)

array $data

Data specific for this type that will be updated

array $options

at line 461
update_notification(type_interface $notification, array $data, array $options = array())

Update a notification

Parameters

type_interface $notification

The notification

array $data

Data specific for this type that will be updated

array $options

at line 483
delete_notifications(string|array $notification_type_name, int|array $item_id, mixed $parent_id = false, mixed $user_id = false)

Delete a notification

Parameters

string|array $notification_type_name

Type identifier or array of item types (only acceptable if the $item_id is identical for the specified types)

int|array $item_id

Identifier within the type (or array of ids)

mixed $parent_id

Parent identifier within the type (or array of ids), used in combination with item_id if specified (Default: false; not checked)

mixed $user_id

User id (Default: false; not checked)

at line 509
array get_subscription_types()

Get all of the subscription types

Return Value

array

Array of item types

at line 550
array get_subscription_methods()

Get all of the subscription methods

Return Value

array

Array of methods

at line 618
protected array get_user_notifications(int $user_id)

Get user's notification data

Parameters

int $user_id

The user_id of the user to get the notifications for

Return Value

array

User's notification

at line 645
array get_global_subscriptions(bool|int $user_id = false)

Get global subscriptions (item_id = 0)

Parameters

bool|int $user_id

The user_id to add the subscription for (bool false for current user)

Return Value

array

Subscriptions

at line 699
add_subscription(string $item_type, int $item_id = 0, string $method = null, bool|int $user_id = false)

Add a subscription

Parameters

string $item_type

Type identifier of the subscription

int $item_id

The id of the item

string $method

The method of the notification e.g. 'board', 'email', or 'jabber' (if null a subscription will be added for all the defaults methods)

bool|int $user_id

The user_id to add the subscription for (bool false for current user)

at line 755
delete_subscription(string $item_type, int $item_id = 0, string $method = null, bool|int $user_id = false)

Delete a subscription

Parameters

string $item_type

Type identifier of the subscription

int $item_id

The id of the item

string $method

The method of the notification e.g. 'board', 'email', or 'jabber'

bool|int $user_id

The user_id to add the subscription for (bool false for current user)

at line 800
disable_notifications(string $notification_type_name)

Disable all notifications of a certain type

This should be called when an extension which has notification types is disabled so that all those notifications are hidden and do not cause errors

Parameters

string $notification_type_name

Type identifier of the subscription

at line 816
purge_notifications(string $notification_type_name)

Purge all notifications of a certain type

This should be called when an extension which has notification types is purged so that all those notifications are removed

Parameters

string $notification_type_name

Type identifier of the subscription

at line 850
enable_notifications(string $notification_type_name)

Enable all notifications of a certain type

This should be called when an extension which has notification types that was disabled is re-enabled so that all those notifications that were hidden are shown again

Parameters

string $notification_type_name

Type identifier of the subscription

at line 864
prune_notifications(int $timestamp, bool $only_read = true)

Delete all notifications older than a certain time

Parameters

int $timestamp

Unix timestamp to delete all notifications that were created before

bool $only_read

True (default) to only prune read notifications

at line 878
method_interface[] get_default_methods()

Helper to get the list of methods enabled by default

Return Value

method_interface[]

at line 900
type_interface get_item_type_class(string $notification_type_name, array $data = array())

Helper to get the notifications item type class and set it up

Parameters

string $notification_type_name
array $data

Return Value

type_interface

at line 915
method_interface get_method_class(string $method_name)

Helper to get the notifications method class and set it up

Parameters

string $method_name

Return Value

method_interface

at line 926
protected method_interface|type_interface load_object(string $object_name)

Helper to load objects (notification types/methods)

Parameters

string $object_name

Return Value

method_interface|type_interface

at line 945
int get_notification_type_id(string $notification_type_name)

Get the notification type id from the name

Parameters

string $notification_type_name

The name

Return Value

int

the notification_type_id

Exceptions

exception

at line 987
array get_notification_type_ids(string|array $notification_type_names)

Get notification type ids (as an array)

Parameters

string|array $notification_type_names

Notification type names

Return Value

array

Array of integers

at line 1011
array get_notified_users(bool|string|array $notification_type_name, array $options)

Find the users which are already notified

Parameters

bool|string|array $notification_type_name

Type identifier or array of item types (only acceptable if the $data is identical for the specified types). False to retrieve all item types

array $options

Return Value

array

The list of the notified users