%PDF- %PDF-
Direktori : /www/loslex/test/app/Mail/ |
Current File : //www/loslex/test/app/Mail/RegistrationCompletedMail.php |
<?php namespace App\Mail; use App\Models\Contest; use App\Models\Registration; use Illuminate\Bus\Queueable; use Illuminate\Contracts\Queue\ShouldQueue; use Illuminate\Mail\Attachment; use Illuminate\Mail\Mailable; use Illuminate\Mail\Mailables\Content; use Illuminate\Mail\Mailables\Envelope; use Illuminate\Queue\SerializesModels; use Illuminate\Support\Facades\App; class RegistrationCompletedMail extends Mailable { use Queueable, SerializesModels; public array $data; /** * Create a new message instance. */ public function __construct(Registration $registration) { list($startTime, $endTime, $startPres, $endPres) = $this->prepareStartEndTimes($registration); $hasPayment = !!($registration->contest->accountnumber); $this->data = array( 'isNew' => true, 'contestName' => $registration->contest->contestname, 'token' => (string)($registration->canceltoken), 'contestId' => $registration->contest->id, 'contestRange' => $registration->contest->range->name, 'contestRangeId' => $registration->contest->range->id, 'contestDate' => $registration->contest->date->format("d.m.Y"), 'contestPresentationStart' => $startPres, 'contestPresentationEnd' => $endPres, 'contestStart' => $startTime, 'contestEnd' => $endTime, 'regId' => $registration->id, 'regName' => $registration->user->firstname . " " . $registration->user->lastname . ($registration->user->suffix ? " " . $registration->user->suffix : ""), 'regSquad' => $registration->squad != 0 ? $registration->squad : "R", 'regDivision' => $registration->division?->division, 'hasPayment' => $hasPayment, 'payAccountNumber' => $registration->contest->accountnumber, 'payVarSymbol' => $registration->contest->accvarsym, 'payNote' => $hasPayment ? $registration->paymentnote : "", 'replyTo' => $registration->contest->organizerEmail ? $registration->contest->organizerEmail : $registration->contest->director->email, 'ical' => $this->createIcal($registration), 'contestFee' => $registration->lexmember ? $registration->contest->feelex : $registration->contest->feeothers, 'payConditions' => $registration->contest->acccondition, 'regNote' => $registration->note, 'qrimg' => $hasPayment ? base64_encode($registration->qrimg) : "" ); } /** * Get the message envelope. */ public function envelope(): Envelope { return new Envelope( replyTo: ['email' => $this->data['replyTo']], subject: __('Registration for contest') . ' - ' . $this->data['contestDate'] . ' - ' . $this->data['contestName'], ); } /** * Get the message content definition. */ public function content(): Content { return new Content( markdown: 'emails.registration.completed-' . App::getLocale(), ); } /** * Get the attachments for the message. * * @return array<int, \Illuminate\Mail\Mailables\Attachment> */ public function attachments(): array { return [ Attachment::fromData(fn () => $this->data['ical'], "contest.ics")->withMime('text/calendar') ]; } private function createIcal(Registration $registration): string { list($startTime, $endTime) = $this->prepareStartEndTimes($registration); $contestStart = $registration->contest->date->setTimeFromTimeString($startTime); $contestEnd = $registration->contest->date->setTimeFromTimeString($endTime); $contestUrl = route('contest.show', $registration->contest->id); // TODO: GEO:49.212047;17.519481 // TODO Description division, squad... return "BEGIN:VCALENDAR VERSION:2.0 CALSCALE:GREGORIAN PRODID:-//LosLex//loslex.cz//cs X-ORIGINAL-URL:/ BEGIN:VTIMEZONE TZID:Europe/Prague BEGIN:DAYLIGHT TZOFFSETFROM:+0100 TZOFFSETTO:+0200 TZNAME:CEST DTSTART:19700329T020000 RRULE:FREQ=YEARLY;BYDAY=-1SU;BYMONTH=3 END:DAYLIGHT BEGIN:STANDARD TZOFFSETFROM:+0200 TZOFFSETTO:+0100 TZNAME:CET DTSTART:19701025T030000 RRULE:FREQ=YEARLY;BYDAY=-1SU;BYMONTH=10 END:STANDARD END:VTIMEZONE BEGIN:VEVENT UID:c{$registration->contest->id}@loslex.cz DTSTAMP:{$contestStart->format("Ymd\\THis")} DTSTART;TZID=Europe/Prague:{$contestStart->format("Ymd\\THis")} DTEND;TZID=Europe/Prague:{$contestEnd->format("Ymd\\THis")} LOCATION:{$registration->contest->range->name} SUMMARY:LOS: {$registration->contest->contestname} DESCRIPTION:{$contestUrl} URL:{$contestUrl} END:VEVENT END:VCALENDAR"; } private function prepareStartEndTimes(Registration $registration): array { $startTime = $registration->contest->squadshootstyle == "together" ? $registration->contest->contestStart[0] : $registration->contest->contestStart[$registration->squad]; $endTime = $registration->contest->squadshootstyle == "together" ? $registration->contest->contestEnd[0] : $registration->contest->contestEnd[$registration->squad]; $startPres = $registration->contest->squadshootstyle == "together" ? $registration->contest->presentationStart[0] : $registration->contest->presentationStart[$registration->squad]; $endPres = $registration->contest->squadshootstyle == "together" ? $registration->contest->presentationEnd[0] : $registration->contest->presentationEnd[$registration->squad]; if ($registration->squad == 0 && $registration->contest->squadshootstyle == "manual") // RO squad when suqads are at different time { $startTime = $registration->contest->contestStart[1]; $endTime = $registration->contest->contestEnd[$registration->contest->squads]; $startPres = $registration->contest->presentationStart[1]; $endPres = $registration->contest->presentationEnd[$registration->contest->squads]; } return array($startTime, $endTime, $startPres, $endPres); } }