Add speaker invitations with portal page and programme host picker.
Deploy Ladill Events / deploy (push) Successful in 47s
Deploy Ladill Events / deploy (push) Successful in 47s
Speakers require email, get a personal holding page with programme and stage links, auto-invites when programme hosts are saved, and manual send for events without a schedule; also fix wallet copy on event create and anchor attendee comms. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -75,6 +75,26 @@ class EventEmailService
|
||||
);
|
||||
}
|
||||
|
||||
public function sendSpeakerInvite(
|
||||
string $ownerPublicId,
|
||||
string $to,
|
||||
string $eventName,
|
||||
string $portalUrl,
|
||||
?string $speakerName = null,
|
||||
): bool {
|
||||
return $this->send(
|
||||
$ownerPublicId,
|
||||
$to,
|
||||
'Speaker invitation — '.$eventName,
|
||||
'mail.notifications.event-speaker-invite',
|
||||
[
|
||||
'eventName' => $eventName,
|
||||
'portalUrl' => $portalUrl,
|
||||
'speakerName' => $speakerName,
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
/** @param array<string, mixed> $viewData */
|
||||
private function send(string $ownerPublicId, string $to, string $subject, string $view, array $viewData): bool
|
||||
{
|
||||
|
||||
@@ -50,14 +50,59 @@ class EventProgrammeService
|
||||
public function hostsFromItems(array $items): array
|
||||
{
|
||||
return collect($items)
|
||||
->pluck('host')
|
||||
->filter(fn ($host) => is_string($host) && trim($host) !== '')
|
||||
->map(fn ($host) => trim($host))
|
||||
->flatMap(function ($item) {
|
||||
if (! is_array($item)) {
|
||||
return [];
|
||||
}
|
||||
|
||||
$email = strtolower(trim((string) ($item['host_speaker_email'] ?? '')));
|
||||
if ($email !== '' && filter_var($email, FILTER_VALIDATE_EMAIL)) {
|
||||
return [$email];
|
||||
}
|
||||
|
||||
$host = trim((string) ($item['host'] ?? ''));
|
||||
if ($host !== '' && filter_var($host, FILTER_VALIDATE_EMAIL)) {
|
||||
return [$host];
|
||||
}
|
||||
|
||||
if ($host !== '') {
|
||||
return [$host];
|
||||
}
|
||||
|
||||
return [];
|
||||
})
|
||||
->unique()
|
||||
->values()
|
||||
->all();
|
||||
}
|
||||
|
||||
/** @return list<array{email: string, name: string}> */
|
||||
public function speakerOptionsForProgramme(QrCode $programme): array
|
||||
{
|
||||
$options = [];
|
||||
|
||||
foreach ($this->eventsLinkedToProgramme($programme) as $event) {
|
||||
foreach ((array) ($event->content()['speakers'] ?? []) as $speaker) {
|
||||
if (! is_array($speaker)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$email = trim((string) ($speaker['email'] ?? ''));
|
||||
$name = trim((string) ($speaker['name'] ?? ''));
|
||||
if ($email === '' || ! filter_var($email, FILTER_VALIDATE_EMAIL) || $name === '') {
|
||||
continue;
|
||||
}
|
||||
|
||||
$options[strtolower($email)] = [
|
||||
'email' => $email,
|
||||
'name' => $name,
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
return array_values($options);
|
||||
}
|
||||
|
||||
/** @return Collection<int, QrCode> */
|
||||
public function eventsLinkedToProgramme(QrCode $programme): Collection
|
||||
{
|
||||
|
||||
@@ -0,0 +1,322 @@
|
||||
<?php
|
||||
|
||||
namespace App\Services\Events;
|
||||
|
||||
use App\Models\QrCode;
|
||||
use App\Models\User;
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
class EventSpeakerInviteService
|
||||
{
|
||||
public const SOURCE_PROGRAMME = 'programme';
|
||||
|
||||
public const SOURCE_MANUAL = 'manual';
|
||||
|
||||
public function __construct(
|
||||
private readonly EventEmailService $email,
|
||||
private readonly EventProgrammeService $programmes,
|
||||
private readonly EventSpeakerService $speakers,
|
||||
) {}
|
||||
|
||||
/** @return list<array<string, mixed>> */
|
||||
public function rosterWithInviteState(QrCode $event): array
|
||||
{
|
||||
return collect((array) ($event->content()['speakers'] ?? []))
|
||||
->map(fn ($speaker) => $this->normalizeSpeakerRow(is_array($speaker) ? $speaker : []))
|
||||
->filter(fn ($speaker) => ($speaker['name'] ?? '') !== '')
|
||||
->values()
|
||||
->all();
|
||||
}
|
||||
|
||||
public function canSendManualInvite(QrCode $event, array $speaker): bool
|
||||
{
|
||||
if (($speaker['email'] ?? '') === '') {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (! $this->speakers->linkedProgramme($event)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (empty($speaker['invited_at'])) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return ($speaker['invite_source'] ?? '') === self::SOURCE_MANUAL;
|
||||
}
|
||||
|
||||
public function sendManualInvite(QrCode $event, User $owner, string $email): bool
|
||||
{
|
||||
$email = strtolower(trim($email));
|
||||
$speakers = $this->rosterWithInviteState($event);
|
||||
$index = collect($speakers)->search(fn ($row) => strcasecmp((string) ($row['email'] ?? ''), $email) === 0);
|
||||
|
||||
if ($index === false) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$speaker = $speakers[$index];
|
||||
if (! $this->canSendManualInvite($event, $speaker)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return $this->deliverInvite($event, $owner, $speaker, self::SOURCE_MANUAL);
|
||||
}
|
||||
|
||||
public function inviteProgrammeHosts(QrCode $programme, User $owner): int
|
||||
{
|
||||
if ($programme->type !== QrCode::TYPE_ITINERARY) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
$sent = 0;
|
||||
|
||||
foreach ($this->programmes->eventsLinkedToProgramme($programme) as $event) {
|
||||
$sent += $this->inviteHostsForEvent($event->fresh(), $owner, $programme);
|
||||
}
|
||||
|
||||
return $sent;
|
||||
}
|
||||
|
||||
public function inviteHostsForEvent(QrCode $event, User $owner, ?QrCode $programme = null): int
|
||||
{
|
||||
$programme ??= $this->speakers->linkedProgramme($event);
|
||||
if (! $programme) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
$hostEmails = $this->hostSpeakerEmailsFromProgramme($programme);
|
||||
if ($hostEmails === []) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
$sent = 0;
|
||||
$speakers = $this->rosterWithInviteState($event);
|
||||
|
||||
foreach ($speakers as $speaker) {
|
||||
$email = strtolower((string) ($speaker['email'] ?? ''));
|
||||
if ($email === '' || ! in_array($email, $hostEmails, true)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (($speaker['invite_source'] ?? '') === self::SOURCE_PROGRAMME && ! empty($speaker['invited_at'])) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if ($this->deliverInvite($event, $owner, $speaker, self::SOURCE_PROGRAMME)) {
|
||||
$sent++;
|
||||
}
|
||||
}
|
||||
|
||||
return $sent;
|
||||
}
|
||||
|
||||
/** @return array{event: QrCode, speaker: array<string, mixed>}|null */
|
||||
public function resolvePortal(string $shortCode, string $token): ?array
|
||||
{
|
||||
$token = trim($token);
|
||||
if ($token === '') {
|
||||
return null;
|
||||
}
|
||||
|
||||
$event = QrCode::query()
|
||||
->where('short_code', $shortCode)
|
||||
->where('type', QrCode::TYPE_EVENT)
|
||||
->where('is_active', true)
|
||||
->first();
|
||||
|
||||
if (! $event) {
|
||||
return null;
|
||||
}
|
||||
|
||||
foreach ($this->rosterWithInviteState($event) as $speaker) {
|
||||
if (hash_equals((string) ($speaker['invite_token'] ?? ''), $token)) {
|
||||
return ['event' => $event, 'speaker' => $speaker];
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/** @return array<string, mixed>|null */
|
||||
public function verifyToken(QrCode $event, string $token): ?array
|
||||
{
|
||||
$token = trim($token);
|
||||
if ($token === '') {
|
||||
return null;
|
||||
}
|
||||
|
||||
foreach ($this->rosterWithInviteState($event) as $speaker) {
|
||||
if (hash_equals((string) ($speaker['invite_token'] ?? ''), $token)) {
|
||||
return [
|
||||
'email' => $speaker['email'],
|
||||
'name' => $speaker['name'],
|
||||
'role' => $speaker['role'] ?? '',
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public function portalUrl(QrCode $event, string $token): string
|
||||
{
|
||||
return route('qr.public.speaker.portal', [
|
||||
'shortCode' => $event->short_code,
|
||||
'token' => $token,
|
||||
]);
|
||||
}
|
||||
|
||||
/** @param array<string, mixed> $session */
|
||||
public function speakerJoinUrl(QrCode $event, array $session, string $token): ?string
|
||||
{
|
||||
$joinUrl = trim((string) ($session['join_url'] ?? ''));
|
||||
if ($joinUrl === '') {
|
||||
return null;
|
||||
}
|
||||
|
||||
$separator = str_contains($joinUrl, '?') ? '&' : '?';
|
||||
|
||||
return $joinUrl.$separator.'speaker='.urlencode($token);
|
||||
}
|
||||
|
||||
/** @return list<array{session: string, day: string, time: string, location: string}> */
|
||||
public function assignmentsForSpeaker(QrCode $event, array $speaker): array
|
||||
{
|
||||
$programme = $this->speakers->linkedProgramme($event);
|
||||
$snapshot = $this->programmes->snapshot($programme);
|
||||
if (! $snapshot) {
|
||||
return [];
|
||||
}
|
||||
|
||||
$email = strtolower((string) ($speaker['email'] ?? ''));
|
||||
$name = trim((string) ($speaker['name'] ?? ''));
|
||||
$assignments = [];
|
||||
|
||||
foreach ((array) ($snapshot['days'] ?? []) as $day) {
|
||||
$dayLabel = trim((string) ($day['date'] ?? $day['label'] ?? ''));
|
||||
foreach ((array) ($day['items'] ?? []) as $item) {
|
||||
if (! is_array($item)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$hostEmail = strtolower(trim((string) ($item['host_speaker_email'] ?? '')));
|
||||
$hostName = trim((string) ($item['host'] ?? ''));
|
||||
|
||||
$matches = ($email !== '' && $hostEmail === $email)
|
||||
|| ($name !== '' && strcasecmp($hostName, $name) === 0);
|
||||
|
||||
if (! $matches) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$assignments[] = [
|
||||
'session' => trim((string) ($item['title'] ?? '')),
|
||||
'day' => $dayLabel,
|
||||
'time' => trim((string) ($item['time'] ?? '')),
|
||||
'location' => trim((string) ($item['location'] ?? '')),
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
return $assignments;
|
||||
}
|
||||
|
||||
/** @param array<string, mixed> $speaker */
|
||||
private function deliverInvite(QrCode $event, User $owner, array $speaker, string $source): bool
|
||||
{
|
||||
$email = trim((string) ($speaker['email'] ?? ''));
|
||||
if ($email === '') {
|
||||
return false;
|
||||
}
|
||||
|
||||
$token = (string) ($speaker['invite_token'] ?? '');
|
||||
if ($token === '') {
|
||||
$token = Str::random(48);
|
||||
}
|
||||
|
||||
$eventName = (string) ($event->content()['name'] ?? $event->label);
|
||||
$portalUrl = $this->portalUrl($event, $token);
|
||||
|
||||
$sent = $this->email->sendSpeakerInvite(
|
||||
$owner->public_id,
|
||||
$email,
|
||||
$eventName,
|
||||
$portalUrl,
|
||||
$speaker['name'] ?? null,
|
||||
);
|
||||
|
||||
if (! $sent) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$this->persistSpeakerInviteMeta($event, $email, $token, $source);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private function persistSpeakerInviteMeta(QrCode $event, string $email, string $token, string $source): void
|
||||
{
|
||||
$email = strtolower(trim($email));
|
||||
$content = $event->content();
|
||||
$speakers = [];
|
||||
|
||||
foreach ((array) ($content['speakers'] ?? []) as $row) {
|
||||
if (! is_array($row)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$rowEmail = strtolower(trim((string) ($row['email'] ?? '')));
|
||||
if ($rowEmail === $email) {
|
||||
$row['invite_token'] = $token;
|
||||
$row['invited_at'] = now()->toIso8601String();
|
||||
$row['invite_source'] = $source;
|
||||
}
|
||||
|
||||
$speakers[] = $row;
|
||||
}
|
||||
|
||||
$payload = (array) ($event->payload ?? []);
|
||||
$payload['content'] = array_merge($content, ['speakers' => $speakers]);
|
||||
$event->payload = $payload;
|
||||
$event->save();
|
||||
}
|
||||
|
||||
/** @return list<string> */
|
||||
private function hostSpeakerEmailsFromProgramme(QrCode $programme): array
|
||||
{
|
||||
$emails = [];
|
||||
|
||||
foreach ((array) ($programme->content()['days'] ?? []) as $day) {
|
||||
foreach ((array) ($day['items'] ?? []) as $item) {
|
||||
if (! is_array($item)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$email = strtolower(trim((string) ($item['host_speaker_email'] ?? '')));
|
||||
if ($email !== '' && filter_var($email, FILTER_VALIDATE_EMAIL)) {
|
||||
$emails[] = $email;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return array_values(array_unique($emails));
|
||||
}
|
||||
|
||||
/** @param array<string, mixed> $speaker */
|
||||
private function normalizeSpeakerRow(array $speaker): array
|
||||
{
|
||||
$name = trim((string) ($speaker['name'] ?? ''));
|
||||
$email = trim((string) ($speaker['email'] ?? ''));
|
||||
|
||||
return [
|
||||
'name' => $name,
|
||||
'email' => filter_var($email, FILTER_VALIDATE_EMAIL) ? $email : '',
|
||||
'role' => trim((string) ($speaker['role'] ?? '')),
|
||||
'bio' => trim((string) ($speaker['bio'] ?? '')),
|
||||
'invite_token' => trim((string) ($speaker['invite_token'] ?? '')),
|
||||
'invited_at' => $speaker['invited_at'] ?? null,
|
||||
'invite_source' => $speaker['invite_source'] ?? null,
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -309,6 +309,8 @@ class QrCodeManagerService
|
||||
|
||||
if ($qrCode->type === QrCode::TYPE_ITINERARY) {
|
||||
$this->meetSync->syncEventsForProgramme($qrCode->fresh(), $qrCode->user);
|
||||
app(\App\Services\Events\EventSpeakerInviteService::class)
|
||||
->inviteProgrammeHosts($qrCode->fresh(), $qrCode->user);
|
||||
}
|
||||
|
||||
return $qrCode->fresh(['document']);
|
||||
|
||||
@@ -51,7 +51,16 @@ class QrPayloadValidator
|
||||
$merged['destination_url'] = $merged['url'];
|
||||
}
|
||||
|
||||
return $this->validateForCreate($qrCode->type, $merged);
|
||||
$result = $this->validateForCreate($qrCode->type, $merged);
|
||||
|
||||
if ($qrCode->type === QrCode::TYPE_EVENT && isset($result['content']['speakers'])) {
|
||||
$result['content']['speakers'] = $this->mergeSpeakerInviteMeta(
|
||||
(array) ($qrCode->content()['speakers'] ?? []),
|
||||
$result['content']['speakers'],
|
||||
);
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/** @param array<string, mixed> $input */
|
||||
@@ -354,7 +363,7 @@ class QrPayloadValidator
|
||||
return array_values($normalized);
|
||||
}
|
||||
|
||||
/** @return list<array{name: string, email: string, role: string, bio: string}> */
|
||||
/** @return list<array{name: string, email: string, role: string, bio: string, invite_token?: string, invited_at?: string, invite_source?: string}> */
|
||||
private function normalizeSpeakers(mixed $speakers, array $input): array
|
||||
{
|
||||
$rows = is_array($speakers) ? $speakers : (array) ($input['speakers'] ?? []);
|
||||
@@ -371,17 +380,57 @@ class QrPayloadValidator
|
||||
}
|
||||
|
||||
$email = trim((string) ($speaker['email'] ?? ''));
|
||||
$normalized[] = [
|
||||
if ($email === '' || ! filter_var($email, FILTER_VALIDATE_EMAIL)) {
|
||||
throw new RuntimeException('Each speaker must have a valid email address.');
|
||||
}
|
||||
|
||||
$row = [
|
||||
'name' => mb_substr($name, 0, 120),
|
||||
'email' => filter_var($email, FILTER_VALIDATE_EMAIL) ? $email : '',
|
||||
'email' => $email,
|
||||
'role' => mb_substr(trim((string) ($speaker['role'] ?? '')), 0, 80),
|
||||
'bio' => mb_substr(trim((string) ($speaker['bio'] ?? '')), 0, 500),
|
||||
];
|
||||
|
||||
foreach (['invite_token', 'invited_at', 'invite_source'] as $key) {
|
||||
if (! empty($speaker[$key])) {
|
||||
$row[$key] = $speaker[$key];
|
||||
}
|
||||
}
|
||||
|
||||
$normalized[] = $row;
|
||||
}
|
||||
|
||||
return array_values($normalized);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param list<array<string, mixed>> $previous
|
||||
* @param list<array<string, mixed>> $current
|
||||
* @return list<array<string, mixed>>
|
||||
*/
|
||||
private function mergeSpeakerInviteMeta(array $previous, array $current): array
|
||||
{
|
||||
$byEmail = collect($previous)
|
||||
->filter(fn ($row) => is_array($row) && filled($row['email'] ?? null))
|
||||
->keyBy(fn ($row) => strtolower((string) $row['email']));
|
||||
|
||||
return collect($current)->map(function (array $speaker) use ($byEmail) {
|
||||
$email = strtolower((string) ($speaker['email'] ?? ''));
|
||||
$prev = $byEmail->get($email);
|
||||
if (! $prev) {
|
||||
return $speaker;
|
||||
}
|
||||
|
||||
foreach (['invite_token', 'invited_at', 'invite_source'] as $key) {
|
||||
if (! empty($prev[$key]) && empty($speaker[$key])) {
|
||||
$speaker[$key] = $prev[$key];
|
||||
}
|
||||
}
|
||||
|
||||
return $speaker;
|
||||
})->values()->all();
|
||||
}
|
||||
|
||||
/** @param array<int, array{price: float}> $tiers */
|
||||
private function eventHasPaidTier(array $tiers): bool
|
||||
{
|
||||
@@ -417,13 +466,24 @@ class QrPayloadValidator
|
||||
if ($itemTitle === '') {
|
||||
continue;
|
||||
}
|
||||
$hostSpeakerEmail = strtolower(trim((string) ($item['host_speaker_email'] ?? '')));
|
||||
if ($hostSpeakerEmail !== '' && ! filter_var($hostSpeakerEmail, FILTER_VALIDATE_EMAIL)) {
|
||||
$hostSpeakerEmail = '';
|
||||
}
|
||||
|
||||
$host = mb_substr(trim((string) ($item['host'] ?? '')), 0, 120);
|
||||
if ($host === '' && $hostSpeakerEmail !== '') {
|
||||
$host = mb_substr(strtok($hostSpeakerEmail, '@') ?: $hostSpeakerEmail, 0, 120);
|
||||
}
|
||||
|
||||
$items[] = [
|
||||
'ref' => 'day'.$dayIndex.'-item'.$itemIndex,
|
||||
'time' => mb_substr(trim((string) ($item['time'] ?? '')), 0, 40),
|
||||
'title' => mb_substr($itemTitle, 0, 140),
|
||||
'description' => mb_substr(trim((string) ($item['description'] ?? '')), 0, 400),
|
||||
'location' => mb_substr(trim((string) ($item['location'] ?? '')), 0, 120),
|
||||
'host' => mb_substr(trim((string) ($item['host'] ?? '')), 0, 120),
|
||||
'ref' => 'day'.$dayIndex.'-item'.$itemIndex,
|
||||
'time' => mb_substr(trim((string) ($item['time'] ?? '')), 0, 40),
|
||||
'title' => mb_substr($itemTitle, 0, 140),
|
||||
'description' => mb_substr(trim((string) ($item['description'] ?? '')), 0, 400),
|
||||
'location' => mb_substr(trim((string) ($item['location'] ?? '')), 0, 120),
|
||||
'host' => $host,
|
||||
'host_speaker_email' => $hostSpeakerEmail,
|
||||
];
|
||||
}
|
||||
if (empty($items) && trim((string) ($day['label'] ?? '')) === '') {
|
||||
|
||||
Reference in New Issue
Block a user