Skip to content

Commit 9f68924

Browse files
committed
changed: notify_user replaced by elgg_notify_user or notificationhandler
1 parent 567d21a commit 9f68924

File tree

8 files changed

+100
-60
lines changed

8 files changed

+100
-60
lines changed

classes/ColdTrick/EventManager/Notifications/CreateEventEventHandler.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,14 @@ class CreateEventEventHandler extends NotificationEventHandler {
1313
* {@inheritdoc}
1414
*/
1515
protected function getNotificationSubject(\ElggUser $recipient, string $method): string {
16-
return elgg_echo('event_manager:notification:subject', [$this->event->getObject()->getDisplayName()], $recipient->getLanguage());
16+
return elgg_echo('event_manager:notification:subject', [$this->event->getObject()->getDisplayName()]);
1717
}
1818

1919
/**
2020
* {@inheritdoc}
2121
*/
2222
protected function getNotificationSummary(\ElggUser $recipient, string $method): string {
23-
return elgg_echo('event_manager:notification:summary', [$this->event->getObject()->getDisplayName()], $recipient->getLanguage());
23+
return elgg_echo('event_manager:notification:summary', [$this->event->getObject()->getDisplayName()]);
2424
}
2525

2626
/**
@@ -32,7 +32,7 @@ protected function getNotificationBody(\ElggUser $recipient, string $method): st
3232
$body = elgg_echo('event_manager:notification:body', [
3333
$this->event->getActor()->getDisplayName(),
3434
$entity->getDisplayName(),
35-
], $recipient->getLanguage());
35+
]);
3636

3737
$description = $entity->description;
3838
if (!empty($description)) {

classes/ColdTrick/EventManager/Notifications/CreateEventMailEventHandler.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ protected function getNotificationSubject(\ElggUser $recipient, string $method):
1919
return elgg_echo('event_manager:mail:notification:subject', [
2020
$container->getDisplayName(),
2121
$entity->getDisplayName(),
22-
], $recipient->getLanguage());
22+
]);
2323
}
2424

2525
/**
@@ -32,7 +32,7 @@ protected function getNotificationBody(\ElggUser $recipient, string $method): st
3232
return elgg_echo('event_manager:mail:notification:body', [
3333
$entity->description,
3434
$container->getURL(),
35-
], $recipient->getLanguage());
35+
]);
3636
}
3737

3838
/**
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
<?php
2+
3+
namespace ColdTrick\EventManager\Notifications;
4+
5+
use Elgg\Notifications\InstantNotificationEventHandler;
6+
7+
/**
8+
* Send a rsvp notification to an event owner/organizer/contactperson
9+
*/
10+
class RsvpOwnerHandler extends InstantNotificationEventHandler {
11+
12+
/**
13+
* {@inheritdoc}
14+
*/
15+
protected function getNotificationSubject(\ElggUser $recipient, string $method): string {
16+
if ($this->getParam('rsvp_type') === EVENT_MANAGER_RELATION_UNDO) {
17+
return elgg_echo('event_manager:event:registration:notification:owner:subject:event_undo', [$this->getEventEntity()?->getDisplayName()]);
18+
}
19+
20+
return elgg_echo('event_manager:event:registration:notification:owner:subject', [$this->getEventEntity()?->getDisplayName()]);
21+
}
22+
23+
/**
24+
* {@inheritdoc}
25+
*/
26+
protected function getNotificationSummary(\ElggUser $recipient, string $method): string {
27+
return elgg_echo('event_manager:event:registration:notification:owner:summary:' . $this->getParam('rsvp_type'), [
28+
$this->getEventActor()?->getDisplayName(),
29+
$this->getEventEntity()?->getDisplayName(),
30+
]);
31+
}
32+
33+
/**
34+
* {@inheritdoc}
35+
*/
36+
protected function getNotificationBody(\ElggUser $recipient, string $method): string {
37+
return elgg_echo('event_manager:event:registration:notification:owner:text:' . $this->getParam('rsvp_type'), [
38+
$this->getEventEntity()?->getDisplayName(),
39+
(string) $this->getParam('event_title_link'),
40+
]) . $this->getParam('registration_link');
41+
}
42+
}

classes/Event.php

Lines changed: 36 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
<?php
22

3-
use Elgg\Database\QueryBuilder;
43
use Elgg\Database\Clauses\JoinClause;
54
use Elgg\Database\Delete;
5+
use Elgg\Database\QueryBuilder;
66
use Elgg\Database\Select;
77

88
/**
@@ -604,20 +604,17 @@ protected function notifyOnRsvp(string $type, int $to = 0): void {
604604

605605
if ($to_entity instanceof ElggUser) {
606606
// use notification system for real users
607-
$summary = elgg_echo('event_manager:event:registration:notification:user:summary:' . $type, [$this->getDisplayName()]);
608-
609-
// set params for site notifications
610607
$params = [
611-
'summary' => $summary,
612-
'object' => $this,
613-
'action' => 'rsvp',
608+
'summary' => elgg_echo('event_manager:event:registration:notification:user:summary:' . $type, [$this->getDisplayName()]),
609+
'subject' => $user_subject,
610+
'body' => $user_message,
614611
];
615612

616613
if (!empty($attachment)) {
617614
$params['attachments'] = [$attachment];
618615
}
619-
620-
notify_user($to, $this->getOwnerGUID(), $user_subject, $user_message, $params);
616+
617+
$to_entity->notify('rsvp', $this, $params, $this->getOwnerEntity());
621618
} else {
622619
// send e-mail for non users
623620
$options = [
@@ -648,7 +645,6 @@ protected function notifyOnRsvp(string $type, int $to = 0): void {
648645
* @return void
649646
*/
650647
protected function notifyOwnerOnRSVP(string $type, \ElggEntity $rsvp_entity, string $event_title_link, string $registration_link = ''): void {
651-
652648
if (!$this->notify_onsignup) {
653649
return;
654650
}
@@ -670,33 +666,11 @@ protected function notifyOwnerOnRSVP(string $type, \ElggEntity $rsvp_entity, str
670666
}
671667

672668
foreach ($recipients as $recipient) {
673-
$current_language = elgg_get_current_language();
674-
$recipient_language = $recipient instanceof \ElggUser ? $recipient->getLanguage() : $current_language;
675-
elgg()->translator->setCurrentLanguage($recipient_language);
676-
677-
// set params for site notifications
678-
$params = [
679-
'summary' => elgg_echo('event_manager:event:registration:notification:owner:summary:' . $type, [
680-
$rsvp_entity->getDisplayName(),
681-
$this->getDisplayName(),
682-
]),
683-
'object' => $this,
684-
'action' => 'rsvp_owner',
685-
];
686-
687-
$subject = elgg_echo('event_manager:event:registration:notification:owner:subject', [$this->getDisplayName()]);
688-
if ($type === EVENT_MANAGER_RELATION_UNDO) {
689-
$subject = elgg_echo("event_manager:event:registration:notification:owner:subject:{$type}", [$this->getDisplayName()]);
690-
}
691-
692-
$message = elgg_echo('event_manager:event:registration:notification:owner:text:' . $type, [
693-
$rsvp_entity->getDisplayName(),
694-
$event_title_link,
695-
]) . $registration_link;
696-
697-
notify_user($recipient->guid, $rsvp_entity->guid, $subject, $message, $params);
698-
699-
elgg()->translator->setCurrentLanguage($current_language);
669+
$recipient->notify('rsvp_owner', $this, [
670+
'rsvp_type' => $type,
671+
'event_title_link' => $event_title_link,
672+
'registration_link' => $registration_link,
673+
], $rsvp_entity);
700674
}
701675
}
702676

@@ -1008,11 +982,13 @@ public function generateNewAttendee(): bool {
1008982
}
1009983

1010984
$this->rsvp(EVENT_MANAGER_RELATION_ATTENDING, $waiting_user->guid, false, false, false);
1011-
985+
986+
// send custom notification about being moved from the waitinglist
1012987
$current_language = elgg_get_current_language();
1013-
elgg()->translator->setCurrentLanguage($waiting_user->getLanguage());
988+
$recipient_language = $waiting_user instanceof \ElggUser ? $waiting_user->getLanguage() : $current_language;
989+
elgg()->translator->setCurrentLanguage($recipient_language);
1014990

1015-
$notification_body = elgg_echo('event_manager:event:registration:notification:user:text:event_spotfree', [
991+
$body = elgg_echo('event_manager:event:registration:notification:user:text:event_spotfree', [
1016992
$this->getDisplayName(),
1017993
$this->getURL(),
1018994
]);
@@ -1021,17 +997,31 @@ public function generateNewAttendee(): bool {
1021997
if (!empty($completed_text)) {
1022998
$completed_text = str_ireplace('[NAME]', $waiting_user->getDisplayName(), $completed_text);
1023999
$completed_text = str_ireplace('[EVENT]', $this->getDisplayName(), $completed_text);
1024-
1025-
$notification_body .= PHP_EOL . PHP_EOL . $completed_text;
1000+
1001+
$body .= PHP_EOL . PHP_EOL . $completed_text;
10261002
}
10271003

10281004
if (elgg_get_config('email_html_part')) {
10291005
// add addthisevent banners in footer
1030-
$notification_body .= elgg_view('event_manager/addthisevent/email', ['entity' => $this]);
1006+
$body .= elgg_view('event_manager/addthisevent/email', ['entity' => $this]);
10311007
}
1032-
1033-
notify_user($waiting_user->guid, $this->owner_guid, elgg_echo('event_manager:event:registration:notification:user:subject', [$this->getDisplayName()]), $notification_body, [], ['email']);
1034-
1008+
1009+
$subject = elgg_echo('event_manager:event:registration:notification:user:subject', [$this->getDisplayName()]);
1010+
1011+
if ($waiting_user instanceof \ElggUser) {
1012+
$waiting_user->notify('spot_free', $this, [
1013+
'subject' => $subject,
1014+
'body' => $body,
1015+
'methods_override' => ['email'],
1016+
], $this->getOwnerEntity());
1017+
} else {
1018+
elgg_send_email(\Elgg\Email::factory([
1019+
'to' => $waiting_user,
1020+
'subject' => $subject,
1021+
'body' => $body,
1022+
]));
1023+
}
1024+
10351025
elgg()->translator->setCurrentLanguage($current_language);
10361026

10371027
return true;

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,6 @@
2525
}
2626
},
2727
"conflict": {
28-
"elgg/elgg": "<6.3"
28+
"elgg/elgg": "<6.3.1"
2929
}
3030
}

composer.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

elgg-plugin.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -399,6 +399,7 @@
399399
'object' => [
400400
'event' => [
401401
'create' => \ColdTrick\EventManager\Notifications\CreateEventEventHandler::class,
402+
'rsvp_owner' => \ColdTrick\EventManager\Notifications\RsvpOwnerHandler::class,
402403
],
403404
'eventmail' => [
404405
'create' => \ColdTrick\EventManager\Notifications\CreateEventMailEventHandler::class,

lib/functions.php

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -126,24 +126,31 @@ function event_manager_validate_registration_validation_code(int $event_guid, in
126126
* @return void
127127
*/
128128
function event_manager_send_registration_validation_email(\Event $event, \ElggEntity $entity): void {
129-
$language = $entity instanceof \ElggUser ? $entity->getLanguage() : '';
129+
$current_language = elgg_get_current_language();
130+
$recipient_language = $entity instanceof \ElggUser ? $entity->getLanguage() : $current_language;
131+
elgg()->translator->setCurrentLanguage($recipient_language);
130132

131-
$subject = elgg_echo('event_manager:registration:confirm:subject', [$event->getDisplayName()], $language);
132-
$message = elgg_echo('event_manager:registration:confirm:message', [
133+
$subject = elgg_echo('event_manager:registration:confirm:subject', [$event->getDisplayName()]);
134+
$body = elgg_echo('event_manager:registration:confirm:message', [
133135
$event->getDisplayName(),
134136
event_manager_get_registration_validation_url($event->guid, $entity->guid)
135-
], $language);
137+
]);
136138

137-
// send confirmation mail
138139
if ($entity instanceof \ElggUser) {
139-
notify_user($entity->guid, $event->getOwnerGUID(), $subject, $message, null, 'email');
140+
$entity->notify('confirm_registration', $event, [
141+
'subject' => $subject,
142+
'body' => $body,
143+
'methods_override' => ['email'],
144+
], $event->getOwnerEntity());
140145
} else {
141146
elgg_send_email(\Elgg\Email::factory([
142147
'to' => $entity,
143148
'subject' => $subject,
144-
'body' => $message,
149+
'body' => $body,
145150
]));
146151
}
152+
153+
elgg()->translator->setCurrentLanguage($current_language);
147154
}
148155

149156
/**

0 commit comments

Comments
 (0)