Skip to content

Commit

Permalink
Merge pull request #47 from HiEventsDev/develop
Browse files Browse the repository at this point in the history
Attach ICS calendar event to attendee ticket emails
  • Loading branch information
daveearley authored Jun 16, 2024
2 parents c6cd50d + 3c725c6 commit 5d1f81c
Show file tree
Hide file tree
Showing 8 changed files with 229 additions and 4 deletions.
23 changes: 23 additions & 0 deletions backend/app/DomainObjects/EventSettingDomainObject.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,27 @@ public function getGetEmailFooterHtml(): string
</div>
HTML;
}

public function getAddressString(): string
{
$locationDetails = $this->getLocationDetails();

if (is_null($locationDetails)) {
return '';
}

$addressParts = [
$locationDetails['venue_name'] ?? null,
$locationDetails['address_line_1'] ?? null,
$locationDetails['address_line_2'] ?? null,
$locationDetails['city'] ?? null,
$locationDetails['state_or_region'] ?? null,
$locationDetails['zip_or_postal_code'] ?? null,
$locationDetails['country'] ?? null
];

$filteredAddressParts = array_filter($addressParts, static fn($part) => !is_null($part) && $part !== '');

return implode(', ', $filteredAddressParts);
}
}
41 changes: 41 additions & 0 deletions backend/app/Mail/Attendee/AttendeeTicketMail.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,20 @@

namespace HiEvents\Mail\Attendee;

use Carbon\Carbon;
use HiEvents\DomainObjects\AttendeeDomainObject;
use HiEvents\DomainObjects\EventDomainObject;
use HiEvents\DomainObjects\EventSettingDomainObject;
use HiEvents\DomainObjects\OrganizerDomainObject;
use HiEvents\Helper\StringHelper;
use HiEvents\Helper\Url;
use HiEvents\Mail\BaseMail;
use Illuminate\Mail\Mailables\Attachment;
use Illuminate\Mail\Mailables\Content;
use Illuminate\Mail\Mailables\Envelope;
use Illuminate\Support\Str;
use Spatie\IcalendarGenerator\Components\Calendar;
use Spatie\IcalendarGenerator\Components\Event;

/**
* @uses /backend/resources/views/emails/orders/attendee-ticket.blade.php
Expand All @@ -20,6 +26,7 @@ public function __construct(
private readonly AttendeeDomainObject $attendee,
private readonly EventDomainObject $event,
private readonly EventSettingDomainObject $eventSettings,
private readonly OrganizerDomainObject $organizer,
)
{
parent::__construct();
Expand Down Expand Up @@ -51,4 +58,38 @@ public function content(): Content
]
);
}

public function attachments(): array
{
$startDateTime = Carbon::parse($this->event->getStartDate(), $this->event->getTimezone());
$endDateTime = $this->event->getEndDate() ? Carbon::parse($this->event->getEndDate(), $this->event->getTimezone()) : null;

$event = Event::create()
->name($this->event->getTitle())
->uniqueIdentifier('event-' . $this->attendee->getId())
->startsAt($startDateTime)
->url($this->event->getEventUrl())
->organizer($this->organizer->getEmail(), $this->organizer->getName());

if ($this->event->getDescription()) {
$event->description(StringHelper::previewFromHtml($this->event->getDescription()));
}

if ($this->eventSettings->getLocationDetails()) {
$event->address($this->eventSettings->getAddressString());
}

if ($endDateTime) {
$event->endsAt($endDateTime);
}

$calendar = Calendar::create()
->event($event)
->get();

return [
Attachment::fromData(static fn() => $calendar, 'event.ics')
->withMime('text/calendar')
];
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use HiEvents\DomainObjects\AttendeeDomainObject;
use HiEvents\DomainObjects\EventDomainObject;
use HiEvents\DomainObjects\EventSettingDomainObject;
use HiEvents\DomainObjects\OrganizerDomainObject;
use HiEvents\Mail\Attendee\AttendeeTicketMail;
use Illuminate\Contracts\Mail\Mailer;

Expand All @@ -20,12 +21,14 @@ public function send(
AttendeeDomainObject $attendee,
EventDomainObject $event,
EventSettingDomainObject $eventSettings,
OrganizerDomainObject $organizer,
): void
{
$this->mailer->to($attendee->getEmail())->send(new AttendeeTicketMail(
attendee: $attendee,
event: $event,
eventSettings: $eventSettings,
organizer: $organizer,
));
}
}
8 changes: 7 additions & 1 deletion backend/app/Services/Domain/Mail/SendOrderDetailsService.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,13 @@ private function sendAttendeeTicketEmails(OrderDomainObject $order, EventDomainO
continue;
}

$this->sendAttendeeTicketService->send($attendee, $event, $event->getEventSettings());
$this->sendAttendeeTicketService->send(
attendee: $attendee,
event: $event,
eventSettings: $event->getEventSettings(),
organizer: $event->getOrganizer(),
);

$sentEmails[] = $attendee->getEmail();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@
namespace HiEvents\Services\Handlers\Attendee;

use HiEvents\DomainObjects\EventSettingDomainObject;
use HiEvents\DomainObjects\OrganizerDomainObject;
use HiEvents\DomainObjects\Status\AttendeeStatus;
use HiEvents\Exceptions\ResourceConflictException;
use HiEvents\Repository\Eloquent\Value\Relationship;
use HiEvents\Repository\Interfaces\AttendeeRepositoryInterface;
use HiEvents\Repository\Interfaces\EventRepositoryInterface;
use HiEvents\Services\Domain\Attendee\SendAttendeeTicketService;
Expand Down Expand Up @@ -42,10 +44,16 @@ public function handle(ResendAttendeeTicketDTO $resendAttendeeTicketDTO): void
}

$event = $this->eventRepository
->loadRelation(new Relationship(OrganizerDomainObject::class, name: 'organizer'))
->loadRelation(EventSettingDomainObject::class)
->findById($resendAttendeeTicketDTO->eventId);

$this->sendAttendeeTicketService->send($attendee, $event, $event->getEventSettings());
$this->sendAttendeeTicketService->send(
attendee: $attendee,
event: $event,
eventSettings: $event->getEventSettings(),
organizer: $event->getOrganizer(),
);

$this->logger->info('Attendee ticket resent', [
'attendeeId' => $resendAttendeeTicketDTO->attendeeId,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,13 @@ public function handle(PartialUpdateEventSettingsDTO $eventSettingsDTO): EventSe
throw new RefundNotPossibleException('Event settings not found');
}

$locationDetails = $eventSettingsDTO->settings['location_details'] ?? $existingSettings->getLocationDetails();
$isOnlineEvent = $eventSettingsDTO->settings['is_online_event'] ?? $existingSettings->getIsOnlineEvent();

if ($isOnlineEvent) {
$locationDetails = null;
}

return $this->eventSettingsHandler->handle(
UpdateEventSettingsDTO::fromArray([
'event_id' => $eventSettingsDTO->event_id,
Expand Down Expand Up @@ -59,7 +66,7 @@ public function handle(PartialUpdateEventSettingsDTO $eventSettingsDTO): EventSe
'order_timeout_in_minutes' => $eventSettingsDTO->settings['order_timeout_in_minutes'] ?? $existingSettings->getOrderTimeoutInMinutes(),
'website_url' => $eventSettingsDTO->settings['website_url'] ?? $existingSettings->getWebsiteUrl(),
'maps_url' => $eventSettingsDTO->settings['maps_url'] ?? $existingSettings->getMapsUrl(),
'location_details' => $eventSettingsDTO->settings['location_details'] ?? $existingSettings->getLocationDetails(),
'location_details' => $locationDetails,
'is_online_event' => $eventSettingsDTO->settings['is_online_event'] ?? $existingSettings->getIsOnlineEvent(),
'online_event_connection_details' => array_key_exists('online_event_connection_details', $eventSettingsDTO->settings)
? $eventSettingsDTO->settings['online_event_connection_details']
Expand Down
1 change: 1 addition & 0 deletions backend/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
"maatwebsite/excel": "^3.1",
"nette/php-generator": "^4.0",
"php-open-source-saver/jwt-auth": "^2.1",
"spatie/icalendar-generator": "^2.8",
"stripe/stripe-php": "^10.15"
},
"require-dev": {
Expand Down
138 changes: 137 additions & 1 deletion backend/composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 5d1f81c

Please sign in to comment.