%PDF- %PDF-
Mini Shell

Mini Shell

Direktori : /home/nginx/.vscode-server/data/User/History/-72f7010d/
Upload File :
Create Path :
Current File : //home/nginx/.vscode-server/data/User/History/-72f7010d/tos8.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);

        $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' => !!($registration->contest->accountnumber),
            'payAccountNumber' => $registration->contest->accountnumber,
            'payVarSymbol' => $registration->contest->accvarsym,
            'payNote' => $registration->contest->accnote,
            '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
        );
    }

    /**
     * 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);

        // TODO: GEO:49.212047;17.519481
        return "BEGIN:VCALENDAR
VERSION:2.0
CALSCALE:GREGORIAN
PRODID:-//LosLex//loslex.cz//cs
X-ORIGINAL-URL:/
BEGIN:VEVENT
UID:c{$registration->contest->id}@loslex.cz
DTSTAMP:{$contestStart->format("Ymd\\THis")}
DTSTART:{$contestStart->format("Ymd\\THis")}
DTEND:{$contestEnd->format("Ymd\\THis")}
LOCATION:{$registration->contest->range->name}
SUMMARY:LOS: {$registration->contest->contestname}
DESCRIPTION:/contest/{$registration->contest->id}
URL:/contest/{$registration->contest->id}
END:VEVENT
END:VCALENDAR";
    }

    private function prepareStartEndTimes(Registration $registration): array
    {
        $startTime = (isset($registration->contest->contestStart[0]) && $registration->contest->contestStart[0]) ? $registration->contest->contestStart[0] : $registration->contest->contestStart[$registration->squad];
        $endTime = (isset($registration->contest->contestEnd[0]) && $registration->contest->contestEnd[0]) ? $registration->contest->contestEnd[0] : $registration->contest->contestEnd[$registration->squad];
        $startPres = (isset($registration->contest->presentationStart[0]) && $registration->contest->presentationStart[0]) ? $registration->contest->presentationStart[0] : $registration->contest->presentationStart[$registration->squad];
        $endPres = (isset($registration->contest->presentationEnd[0]) && $registration->contest->presentationEnd[0]) ? $registration->contest->presentationEnd[0] : $registration->contest->presentationEnd[$registration->squad];
        if ($registration->squad == 0 && !(isset($registration->contest->contestStart[0]) && $registration->contest->contestStart[0])) // ro, not all squads shoot at same 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);
    }
}

Zerion Mini Shell 1.0