Skip to content

Commit

Permalink
[FEATURE] Allow attachments in custom notifications via TypoScript
Browse files Browse the repository at this point in the history
The existing possibility to add attachment to emails sent using the
extension has been extended, so attachments configured in TypoScript
now also can be applied to custom notifications. The configuration
options are the same as for emails sent by the registration process.

Example:

```
customNotifications {
    thanksForParticipation {
        title = Thank you message
        template = ThanksForParticipation.html
        subject = Thank you for participation in event "{event.title}"
        attachments {
          user {
            fromFiles {
              1 = fileadmin/test.pdf
            }
            fromEventProperty {
              1 = files
              2 = image
            }
            iCalFile = 1
          }
        }
    }
}
```

Refs #1178
  • Loading branch information
derhansen committed Dec 6, 2023
1 parent eb00d32 commit 5394d0a
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 11 deletions.
30 changes: 21 additions & 9 deletions Classes/Service/Notification/AttachmentService.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

namespace DERHANSEN\SfEventMgt\Service\Notification;

use DERHANSEN\SfEventMgt\Domain\Model\Dto\CustomNotification;
use DERHANSEN\SfEventMgt\Domain\Model\Registration;
use DERHANSEN\SfEventMgt\Service\ICalendarService;
use DERHANSEN\SfEventMgt\Utility\MessageType;
Expand Down Expand Up @@ -62,26 +63,31 @@ public function getAttachments(
array $settings,
Registration $registration,
int $messageType,
string $messageRecipient
string $messageRecipient,
?CustomNotification $customNotification = null
): array {
$attachments = [];
$settingPath = $this->getSettingsPath($messageType);
$attachmentSettings = $settings['notification'][$settingPath]['attachments'][$messageRecipient] ?? [];

if (isset($settings['notification'][$settingPath]['attachments'][$messageRecipient])) {
if ($customNotification) {
$attachmentSettings = $settings['notification']['customNotifications'][$customNotification->getTemplate()]['attachments'][$messageRecipient] ?? [];
}

if (!empty($attachmentSettings)) {
// Attachments globally from TypoScript
$config = $settings['notification'][$settingPath]['attachments'][$messageRecipient];
$attachments = $this->getFileAttachments($config);
$attachments = $this->getFileAttachments($attachmentSettings);

// Attachments from Event properties
$eventAttachments = $this->getObjectAttachments(
$config['fromEventProperty'] ?? [],
$attachmentSettings['fromEventProperty'] ?? [],
$registration->getEvent()
);
$attachments = array_merge($attachments, $eventAttachments);

// Attachments from Registration properties
$registrationAttachments = $this->getObjectAttachments(
$config['fromRegistrationProperty'] ?? [],
$attachmentSettings['fromRegistrationProperty'] ?? [],
$registration
);
$attachments = array_merge($attachments, $registrationAttachments);
Expand All @@ -108,13 +114,19 @@ public function getICalAttachment(
array $settings,
Registration $registration,
int $messageType,
string $messageRecipient
string $messageRecipient,
?CustomNotification $customNotification = null
): string {
$file = '';
$settingPath = $this->getSettingsPath($messageType);

if (isset($settings['notification'][$settingPath]['attachments'][$messageRecipient]['iCalFile']) &&
(bool)$settings['notification'][$settingPath]['attachments'][$messageRecipient]['iCalFile']) {
$attachICalFile = (bool)($settings['notification'][$settingPath]['attachments'][$messageRecipient]['iCalFile'] ?? false);

if ($customNotification) {
$attachICalFile = (bool)($settings['notification']['customNotifications'][$customNotification->getTemplate()]['attachments'][$messageRecipient]['iCalFile'] ?? false);
}

if ($attachICalFile) {
$file = GeneralUtility::tempnam(
'event-' . $registration->getEvent()->getUid() . '-',
'.ics'
Expand Down
6 changes: 4 additions & 2 deletions Classes/Service/NotificationService.php
Original file line number Diff line number Diff line change
Expand Up @@ -191,15 +191,17 @@ public function sendUserMessage(
$settings,
$registration,
$type,
MessageRecipient::USER
MessageRecipient::USER,
$customNotification
);

// Get iCal attachment if configured
$iCalAttachment = $this->attachmentService->getICalAttachment(
$settings,
$registration,
$type,
MessageRecipient::USER
MessageRecipient::USER,
$customNotification
);

if ($iCalAttachment !== '') {
Expand Down
2 changes: 2 additions & 0 deletions Documentation/ForAdministrators/EmailAttachments/Index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ The extension supports to add attachments to the following type of emails:
* New event registration on the waitlist
* Confirmed event registration
* Confirmed event registration on the waitlist
* Custom notifications sent from backend (only recipient group :php:`user`)

Configuring email attachments
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Expand All @@ -39,6 +40,7 @@ Attachment configuration can be added to the following TypoScript settings:
* :php:`plugin.tx_sfeventmgt.settings.notification.registrationWaitlistNew`
* :php:`plugin.tx_sfeventmgt.settings.notification.registrationConfirmed`
* :php:`plugin.tx_sfeventmgt.settings.notification.registrationWaitlistConfirmed`
* :php:`plugin.tx_sfeventmgt.settings.notification.customNotifications.your-template-name`

Note, that you also need to configure the recipient group (:php:`user` or :php:`admin`).

Expand Down

0 comments on commit 5394d0a

Please sign in to comment.