Elgg
Version master
engine
classes
Elgg
Notifications
CreateContentEventHandler.php
Go to the documentation of this file.
1
<?php
2
3
namespace
Elgg\Notifications
;
4
11
class
CreateContentEventHandler
{
12
20
public
function
__invoke
(\
Elgg
\
Event
$event): void {
21
$entity
= $event->getObject();
22
if
(!
$entity
instanceof \
ElggObject
&& !
$entity
instanceof \
ElggGroup
) {
23
return
;
24
}
25
26
$owner
=
$entity
->getOwnerEntity();
27
if
(!
$owner
instanceof \
ElggUser
) {
28
return
;
29
}
30
31
if
(
$entity
instanceof \
ElggObject
) {
32
$notification_events
=
_elgg_services
()->notifications->getEvents();
33
if
(!isset(
$notification_events
[
$entity
->getType()]) || !isset(
$notification_events
[
$entity
->getType()][
$entity
->getSubtype()])) {
34
// no notification events registered for this entity type/subtype
35
// so there is no need to subscribe
36
// this also prevents the database from flooding with relationships that are never used (e.g. subscriptions to site notifications)
37
return
;
38
}
39
}
40
41
$content_preferences =
$owner
->getNotificationSettings(
'content_create'
);
42
$enabled_methods = array_keys(array_filter($content_preferences));
43
44
// loop through all notification types
45
$methods
=
elgg_get_notification_methods
();
46
foreach
($enabled_methods as $method) {
47
// only enable supported methods
48
if
(!in_array($method,
$methods
)) {
49
continue
;
50
}
51
52
$entity
->addSubscription(
$owner
->guid, $method);
53
}
54
}
55
}
$entity
$entity
Definition:
reset.php:8
$owner
$owner
Definition:
upload.php:7
ElggGroup
Definition:
ElggGroup.php:14
ElggObject
Definition:
ElggObject.php:15
ElggUser
Definition:
ElggUser.php:28
Elgg\Event
Models an event passed to event handlers.
Definition:
Event.php:11
Elgg\Notifications\CreateContentEventHandler
Apply subscriptions based on preferences.
Definition:
CreateContentEventHandler.php:11
Elgg\Notifications\CreateContentEventHandler\__invoke
__invoke(\Elgg\Event $event)
Subscribe to content you just created in order to receive notifications.
Definition:
CreateContentEventHandler.php:20
_elgg_services
_elgg_services()
Get the global service provider.
Definition:
elgglib.php:353
Elgg\Notifications
Definition:
CreateCommentEventHandler.php:3
Elgg
Definition:
ActionsService.php:3
elgg_get_notification_methods
elgg_get_notification_methods()
Returns registered delivery methods for notifications [ 'email' => 'email', 'sms' => 'sms',...
Definition:
notification.php:121
$notification_events
foreach($entity->getSubscriptions($user->guid) as $subscription) $notification_events
Definition:
details.php:44
$methods
$methods
Definition:
subscribe.php:8
Generated on Fri Aug 29 2025 00:01:58 for Elgg by
1.9.1