class webpush extends base implements extended_method_interface

Web Push notification method class This class handles sending push messages for notifications

Constants

MOZILLA_FALLBACK_PADDING

Properties

protected manager $notification_manager from  base
protected array $queue

Queue of messages to be sent

from  base
protected config $config
protected driver_interface $db
protected log_interface $log
protected user_loader $user_loader
protected user $user
protected string $phpbb_root_path
protected string $php_ext
protected string $notification_webpush_table
protected string $push_subscriptions_table

Methods

set_notification_manager(manager $notification_manager)

Set notification manager (required)

from  base
bool
is_enabled_by_default()

Is the method enable by default?

array
get_notified_users(int $notification_type_id, array $options)

Return the list of the users already notified

array
load_notifications(array $options = array())

Load the user's notifications

from  base
add_to_queue(type_interface $notification)

Add a notification to the queue

from  base
update_notification(type_interface $notification, array $data, array $options)

Update a notification

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

Mark notifications read or unread

mark_notifications_by_parent(string|int|array $notification_type_id, 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

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

Mark notifications read or unread

from  base
delete_notifications(int $notification_type_id, int|array $item_id, mixed $parent_id = false, mixed $user_id = false)

Delete a notification

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

Delete all notifications older than a certain time

purge_notifications(int $notification_type_id)

Purge all notifications of a certain type

from  base
empty_queue()

Empty the queue

from  base
__construct(config $config, driver_interface $db, log_interface $log, user_loader $user_loader, user $user, string $phpbb_root_path, string $php_ext, string $notification_webpush_table, string $push_subscriptions_table)

Notification Method Web Push constructor

string
get_type()

Get notification method name

is_available(type_interface $notification_type = null)

Is this method available for the user? This is checked on the notifications options

notify()

Parse the queue and notify the users

void
notify_using_webpush()

Notify using Web Push

static array
clean_data(array $data)

Clean data to contain only what we need for webpush notifications table

array
get_ucp_template_data(helper $controller_helper, form_helper $form_helper)

Get template data for the UCP

array
get_user_subscription_map(array $notify_users)

Get subscriptions for notify users

void
remove_subscriptions(array $subscription_ids)

Remove subscriptions

void
clean_expired_subscriptions(array $user_subscription_map, array $expired_endpoints)

Clean expired subscriptions from the database

void
set_endpoint_padding(WebPush $web_push, string $endpoint)

Set web push padding for endpoint

Details

in base at line 36
set_notification_manager(manager $notification_manager)

Set notification manager (required)

Parameters

manager $notification_manager

at line 114
bool is_enabled_by_default()

Is the method enable by default?

Return Value

bool

at line 122
array get_notified_users(int $notification_type_id, array $options)

Return the list of the users already notified

Parameters

int $notification_type_id

ID of the notification type

array $options

Return Value

array User

in base at line 62
array load_notifications(array $options = array())

Load the user's notifications

Parameters

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

in base at line 76
add_to_queue(type_interface $notification)

Add a notification to the queue

Parameters

type_interface $notification

in base at line 84
update_notification(type_interface $notification, array $data, array $options)

Update a notification

Parameters

type_interface $notification

Notification to update

array $data

Data specific for this type that will be updated

array $options

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

Mark notifications read or unread

Parameters

bool|string|array $notification_type_id

Type identifier of item 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 320
mark_notifications_by_parent(string|int|array $notification_type_id, 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

Parameters

string|int|array $notification_type_id

Type identifier of item 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)

in base at line 105
mark_notifications_by_id(array|int $notification_id, bool|int $time = false, bool $mark_read = true)

Mark notifications read or unread

Parameters

array|int $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)

in base at line 112
delete_notifications(int $notification_type_id, int|array $item_id, mixed $parent_id = false, mixed $user_id = false)

Delete a notification

Parameters

int $notification_type_id

Type identifier of item 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 332
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

in base at line 126
purge_notifications(int $notification_type_id)

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

int $notification_type_id

Type identifier of the subscription

in base at line 133
protected empty_queue()

Empty the queue

at line 79
__construct(config $config, driver_interface $db, log_interface $log, user_loader $user_loader, user $user, string $phpbb_root_path, string $php_ext, string $notification_webpush_table, string $push_subscriptions_table)

Notification Method Web Push constructor

Parameters

config $config
driver_interface $db
log_interface $log
user_loader $user_loader
user $user
string $phpbb_root_path
string $php_ext
string $notification_webpush_table
string $push_subscriptions_table

at line 96
string get_type()

Get notification method name

Return Value

string

at line 104
is_available(type_interface $notification_type = null)

Is this method available for the user? This is checked on the notifications options

Parameters

type_interface $notification_type

at line 145
notify()

Parse the queue and notify the users

at line 178
protected void notify_using_webpush()

Notify using Web Push

Return Value

void

at line 347
static array clean_data(array $data)

Clean data to contain only what we need for webpush notifications table

Parameters

array $data

Notification data

Return Value

array

Cleaned notification data

at line 370
array get_ucp_template_data(helper $controller_helper, form_helper $form_helper)

Get template data for the UCP

Parameters

helper $controller_helper
form_helper $form_helper

Return Value

array

Template data

at line 404
protected array get_user_subscription_map(array $notify_users)

Get subscriptions for notify users

Parameters

array $notify_users

Users to notify

Return Value

array

Subscription map

at line 428
void remove_subscriptions(array $subscription_ids)

Remove subscriptions

Parameters

array $subscription_ids

Subscription ids to remove

Return Value

void

at line 445
protected void clean_expired_subscriptions(array $user_subscription_map, array $expired_endpoints)

Clean expired subscriptions from the database

Parameters

array $user_subscription_map

User subscription map

array $expired_endpoints

Expired endpoints

Return Value

void

at line 478
protected void set_endpoint_padding(WebPush $web_push, string $endpoint)

Set web push padding for endpoint

Parameters

WebPush $web_push
string $endpoint

Return Value

void