Skip to content

Commit 5cdce3a

Browse files
committed
changed: updated for Elgg 6.3
1 parent 250d8d6 commit 5cdce3a

25 files changed

+794
-244
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
Group Tools
22
===========
33

4-
![Elgg 6.2](https://img.shields.io/badge/Elgg-6.2-green.svg)
4+
![Elgg 6.3](https://img.shields.io/badge/Elgg-6.3-green.svg)
55
![Lint Checks](https://github.com/ColdTrick/group_tools/actions/workflows/lint.yml/badge.svg?event=push)
66
[![Latest Stable Version](https://poser.pugx.org/coldtrick/group_tools/v/stable.svg)](https://packagist.org/packages/coldtrick/group_tools)
77
[![License](https://poser.pugx.org/coldtrick/group_tools/license.svg)](https://packagist.org/packages/coldtrick/group_tools)

actions/group_tools/admin/approve.php

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -36,19 +36,7 @@
3636
/* @var $owner \ElggUser */
3737
$owner = $group->getOwnerEntity();
3838

39-
$subject = elgg_echo('group_tools:group:admin_approve:approve:subject', [$group->getDisplayName()], $owner->getLanguage());
40-
$summary = elgg_echo('group_tools:group:admin_approve:approve:summary', [$group->getDisplayName()], $owner->getLanguage());
41-
$message = elgg_echo('group_tools:group:admin_approve:approve:message', [
42-
$group->getDisplayName(),
43-
$group->getURL(),
44-
], $owner->getLanguage());
45-
46-
$params = [
47-
'object' => $group,
48-
'action' => 'approve',
49-
'summary' => $summary,
50-
];
51-
notify_user($owner->guid, elgg_get_logged_in_user_guid(), $subject, $message, $params);
39+
$owner->notify('approve', $group, [], elgg_get_logged_in_user_entity());
5240

5341
// report success
5442
return elgg_ok_response('', elgg_echo('group_tools:group:admin_approve:approve:success'));

actions/group_tools/admin/decline.php

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
$group_guid = (int) get_input('guid');
77
$reason = get_input('reason');
8+
89
$group = get_entity($group_guid);
910
if (!$group instanceof \ElggGroup) {
1011
return elgg_error_response(elgg_echo('error:missing_data'));
@@ -14,17 +15,9 @@
1415
/* @var $owner \ElggUser */
1516
$owner = $group->getOwnerEntity();
1617

17-
$subject = elgg_echo('group_tools:group:admin_approve:decline:subject', [$group->getDisplayName()], $owner->getLanguage());
18-
$summary = elgg_echo('group_tools:group:admin_approve:decline:summary', [$group->getDisplayName()], $owner->getLanguage());
19-
$message = elgg_echo('group_tools:group:admin_approve:decline:message', [
20-
$group->getDisplayName(),
21-
$reason,
22-
], $owner->getLanguage());
23-
24-
$params = [
25-
'summary' => $summary,
26-
];
27-
notify_user($owner->guid, elgg_get_logged_in_user_guid(), $subject, $message, $params);
18+
$owner->notify('decline', $group, [
19+
'reason' => $reason,
20+
], elgg_get_logged_in_user_entity());
2821

2922
// correct forward url
3023
$forward_url = REFERRER;

actions/group_tools/join_motivation.php

Lines changed: 0 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -26,38 +26,4 @@
2626
$access_id = ($group_acl instanceof \ElggAccessCollection) ? (int) $group_acl->id : ACCESS_LOGGED_IN;
2727
$group->annotate('join_motivation', $motivation, $access_id, $user->guid);
2828

29-
// notify owner
30-
/* @var $owner \ElggUser */
31-
$owner = $group->getOwnerEntity();
32-
33-
$url = elgg_generate_url('requests:group:group', [
34-
'guid' => $group->guid,
35-
]);
36-
37-
$subject = elgg_echo('group_tools:join_motivation:notification:subject', [
38-
$user->getDisplayName(),
39-
$group->getDisplayName(),
40-
], $owner->getLanguage());
41-
$summary = elgg_echo('group_tools:join_motivation:notification:summary', [
42-
$user->getDisplayName(),
43-
$group->getDisplayName(),
44-
], $owner->getLanguage());
45-
46-
$body = elgg_echo('group_tools:join_motivation:notification:body', [
47-
$user->getDisplayName(),
48-
$group->getDisplayName(),
49-
$motivation,
50-
$user->getURL(),
51-
$url,
52-
], $owner->getLanguage());
53-
54-
$params = [
55-
'action' => 'membership_request',
56-
'object' => $group,
57-
'summary' => $summary,
58-
];
59-
60-
// Notify group owner
61-
notify_user($owner->guid, $user->guid, $subject, $body, $params);
62-
6329
return elgg_ok_response('', elgg_echo('groups:joinrequestmade'));

actions/group_tools/related_groups.php

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -44,19 +44,9 @@
4444
/* @var $related_owner \ElggUser */
4545
$related_owner = $related->getOwnerEntity();
4646

47-
$subject = elgg_echo('group_tools:related_groups:notify:owner:subject', [], $related_owner->getLanguage());
48-
$message = elgg_echo('group_tools:related_groups:notify:owner:message', [
49-
$logged_in_user->getDisplayName(),
50-
$related->getDisplayName(),
51-
$group->getDisplayName(),
52-
], $related_owner->getLanguage());
53-
54-
$params = [
55-
'action' => 'relate',
56-
'object' => $related,
57-
];
58-
59-
notify_user($related_owner->guid, $logged_in_user->guid, $subject, $message, $params);
47+
$related_owner->notify('relate', $related, [
48+
'group' => $group,
49+
], $logged_in_user);
6050
}
6151

6252
return elgg_ok_response('', elgg_echo('group_tools:action:related_groups:success'));

actions/groups/invite.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,9 @@
6464

6565
// show hidden (unvalidated) users
6666
elgg_call(ELGG_SHOW_DISABLED_ENTITIES, function() use ($text, $group, $user_guids, $adding, $emails, $csv, $resend, &$already_invited, &$invited, &$member, &$join) {
67+
// unregister default invite notification handler
68+
elgg_unregister_notification_event('relationship', 'invited', ['create:after']);
69+
6770
// invite existing users
6871
if (!empty($user_guids)) {
6972
if (!$adding) {

classes/ColdTrick/GroupTools/Cron.php

Lines changed: 4 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
use Elgg\Database\EntityTable;
77
use Elgg\Database\MetadataTable;
88
use Elgg\Database\QueryBuilder;
9-
use Elgg\Values;
109

1110
/**
1211
* Cron handler
@@ -209,21 +208,7 @@ protected static function notifyStaleGroupOwner(\ElggGroup $entity): void {
209208
return;
210209
}
211210

212-
$site = elgg_get_site_entity();
213-
214-
$subject = elgg_echo('groups_tools:state_info:notification:subject', [$entity->getDisplayName()], $owner->getLanguage());
215-
$message = elgg_echo('groups_tools:state_info:notification:message', [
216-
$entity->getDisplayName(),
217-
$entity->getURL(),
218-
], $owner->getLanguage());
219-
220-
$mail_params = [
221-
'object' => $entity,
222-
'action' => 'group_tools:stale',
223-
'summary' => elgg_echo('groups_tools:state_info:notification:summary', [$entity->getDisplayName()], $owner->getLanguage()),
224-
];
225-
226-
notify_user($owner->guid, $site->guid, $subject, $message, $mail_params);
211+
$owner->notify('group_tools:stale', $entity);
227212
}
228213

229214
/**
@@ -277,9 +262,6 @@ public static function notifyConceptGroupOwners(\Elgg\Event $event): void {
277262
$days = (int) elgg_get_plugin_setting('concept_groups_retention', 'group_tools');
278263

279264
elgg_call(ELGG_IGNORE_ACCESS, function() use ($days) {
280-
$site = elgg_get_site_entity();
281-
$current_language = elgg()->translator->getCurrentLanguage();
282-
283265
/* @var $groups \ElggBatch */
284266
$groups = elgg_get_entities([
285267
'type' => 'group',
@@ -296,37 +278,10 @@ public static function notifyConceptGroupOwners(\Elgg\Event $event): void {
296278
/* @var $owner \ElggUser */
297279
$owner = $group->getOwnerEntity();
298280

299-
// setting language to make sure friendly time is in the correct language
300-
elgg()->translator->setCurrentLanguage($owner->getLanguage());
301-
302-
if ($days > 0) {
303-
$expires = Values::normalizeTime($group->time_created);
304-
$expires->modify("+{$days} days");
305-
306-
$subject = elgg_echo('group_tools:notification:concept_group:expires:subject', [$group->getDisplayName()], $owner->getLanguage());
307-
$message = elgg_echo('group_tools:notification:concept_group:expires:message', [
308-
$group->getDisplayName(),
309-
elgg_get_friendly_time($expires->getTimestamp()),
310-
$group->getURL(),
311-
], $owner->getLanguage());
312-
} else {
313-
$subject = elgg_echo('group_tools:notification:concept_group:subject', [$group->getDisplayName()]);
314-
$message = elgg_echo('group_tools:notification:concept_group:message', [
315-
$group->getDisplayName(),
316-
$group->getURL(),
317-
], $owner->getLanguage());
318-
}
319-
320-
$params = [
321-
'object' => $group,
322-
'action' => 'concept_group_reminder',
323-
];
324-
325-
notify_user($owner->guid, $site->guid, $subject, $message, $params, ['email']);
281+
$owner->notify('concept_group_reminder', $group, [
282+
'retention' => $days,
283+
]);
326284
}
327-
328-
// restore language
329-
elgg()->translator->setCurrentLanguage($current_language);
330285
});
331286
}
332287
}

classes/ColdTrick/GroupTools/Membership.php

Lines changed: 8 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -62,29 +62,9 @@ public static function deleteRequest(\Elgg\Event $event): void {
6262
return;
6363
}
6464

65-
$reason = get_input('reason');
66-
if (empty($reason)) {
67-
$body = elgg_echo('group_tools:notify:membership:declined:message', [
68-
$group->getDisplayName(),
69-
$group->getURL(),
70-
], $user->getLanguage());
71-
} else {
72-
$body = elgg_echo('group_tools:notify:membership:declined:message:reason', [
73-
$group->getDisplayName(),
74-
$reason,
75-
$group->getURL(),
76-
], $user->getLanguage());
77-
}
78-
79-
$subject = elgg_echo('group_tools:notify:membership:declined:subject', [
80-
$group->getDisplayName(),
81-
], $user->getLanguage());
82-
83-
$params = [
84-
'object' => $group,
85-
'action' => 'delete',
86-
];
87-
notify_user($user->guid, $logged_in_user->guid, $subject, $body, $params);
65+
$user->notify('membership:decline', $group, [
66+
'reason' => get_input('reason'),
67+
], $logged_in_user);
8868
}
8969

9070
/**
@@ -108,7 +88,7 @@ public static function groupJoin(\Elgg\Event $event): void {
10888
self::notificationsToggle($user, $group);
10989
}
11090

111-
// cleanup invites and membershiprequests
91+
// cleanup invites and membership requests
11292
self::cleanupGroupInvites($user, $group);
11393

11494
// welcome message
@@ -169,7 +149,7 @@ protected static function notificationsToggle(\ElggUser $user, \ElggGroup $group
169149
}
170150

171151
/**
172-
* Cleanup group invitations and membershiprequests
152+
* Cleanup group invitations and membership requests
173153
*
174154
* @param \ElggUser $user the user to clean up for
175155
* @param \ElggGroup $group the group to clean up on
@@ -226,36 +206,9 @@ protected static function sendWelcomeMessage(\ElggUser $recipient, \ElggGroup $g
226206
return;
227207
}
228208

229-
// replace the placeholders
230-
$welcome_message = str_ireplace('[name]', $recipient->getDisplayName(), $welcome_message);
231-
$welcome_message = str_ireplace('[group_name]', $group->getDisplayName(), $welcome_message);
232-
$welcome_message = str_ireplace('[group_url]', $group->getURL(), $welcome_message);
233-
234-
// get notification preferences for this group
235-
$methods = elgg_get_notification_methods();
236-
if ($group->hasSubscription($recipient->guid, $methods)) {
237-
$subscription = elgg_echo('on', [], $recipient->getLanguage());
238-
} else {
239-
$subscription = elgg_echo('off', [], $recipient->getLanguage());
240-
}
241-
242-
$subscription = elgg_format_element('b', [], $subscription);
243-
244-
$welcome_message .= PHP_EOL . PHP_EOL . elgg_echo('group_tools:welcome_message:notifications', [
245-
$subscription,
246-
], $recipient->getLanguage());
247-
248-
// subject
249-
$subject = elgg_echo('group_tools:welcome_message:subject', [$group->getDisplayName()], $recipient->getLanguage());
250-
251-
// mail params
252-
$mail_params = [
253-
'object' => $group,
254-
'action' => 'welcome',
255-
];
256-
257-
// notify the user
258-
notify_user($recipient->guid, $group->guid, $subject, $welcome_message, $mail_params);
209+
$recipient->notify('welcome', $group, [
210+
'welcome_message' => $welcome_message,
211+
], $group);
259212
}
260213

261214
/**

classes/ColdTrick/GroupTools/Notifications.php

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,6 @@ public static function sendConfirmationOfGroupAdminApprovalToOwner(\Elgg\Event $
3030
/* @var $owner \ElggUser */
3131
$owner = $object->getOwnerEntity();
3232

33-
$subject = elgg_echo('group_tools:group:admin_approve:owner:subject', [$object->getDisplayName()], $owner->getLanguage());
34-
$message = elgg_echo('group_tools:group:admin_approve:owner:message', [
35-
$object->getDisplayName(),
36-
$object->getURL(),
37-
], $owner->getLanguage());
38-
39-
notify_user($owner->guid, elgg_get_site_entity()->guid, $subject, $message, [], ['email']);
33+
$owner->notify('admin_approval:owner', $object);
4034
}
4135
}
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
<?php
2+
3+
namespace ColdTrick\GroupTools\Notifications;
4+
5+
use Elgg\Notifications\InstantNotificationEventHandler;
6+
7+
/**
8+
* Send a notification when a user is added to a group
9+
*/
10+
class AddUserHandler extends InstantNotificationEventHandler {
11+
12+
/**
13+
* {@inheritdoc}
14+
*/
15+
protected function getNotificationSubject(\ElggUser $recipient, string $method): string {
16+
$group = $this->getEventEntity();
17+
if (!$group instanceof \ElggGroup) {
18+
return parent::getNotificationSubject($recipient, $method);
19+
}
20+
21+
return elgg_echo('group_tools:groups:invite:add:subject', [$group->getDisplayName()]);
22+
}
23+
24+
/**
25+
* {@inheritdoc}
26+
*/
27+
protected function getNotificationSummary(\ElggUser $recipient, string $method): string {
28+
$group = $this->getEventEntity();
29+
if (!$group instanceof \ElggGroup) {
30+
return parent::getNotificationSummary($recipient, $method);
31+
}
32+
33+
return elgg_echo('group_tools:groups:invite:add:subject', [$group->getDisplayName()]);
34+
}
35+
36+
/**
37+
* {@inheritdoc}
38+
*/
39+
protected function getNotificationBody(\ElggUser $recipient, string $method): string {
40+
$group = $this->getEventEntity();
41+
$actor = $this->getEventActor();
42+
if (!$group instanceof \ElggGroup || !$actor instanceof \ElggUser) {
43+
return parent::getNotificationBody($recipient, $method);
44+
}
45+
46+
$msg = elgg_echo('group_tools:groups:invite:add:body', [
47+
$actor->getDisplayName(),
48+
$group->getDisplayName(),
49+
(string) $this->getParam('add_text'),
50+
$group->getURL(),
51+
]);
52+
53+
$params = [
54+
'group' => $group,
55+
'inviter' => $actor,
56+
'invitee' => $recipient,
57+
];
58+
return elgg_trigger_event_results('invite_notification', 'group_tools', $params, $msg);
59+
}
60+
61+
/**
62+
* {@inheritdoc}
63+
*/
64+
protected function getNotificationMethods(): array {
65+
return ['email'];
66+
}
67+
}

0 commit comments

Comments
 (0)