<commit_before><?php

namespace App\Mail;

use App\Position;
use Illuminate\Bus\Queueable;
use Illuminate\Mail\Mailable;
use Illuminate\Queue\SerializesModels;
use Illuminate\Contracts\Queue\ShouldQueue;

class PositionAssigned extends Mailable implements ShouldQueue
{
    use Queueable, SerializesModels;

    protected $position;
    protected $servicepositions;
    protected $authorizedby;
    protected $user_id_original;

    /**
     * Create a new message instance.
     *
     * @return void
     */
    public function __construct(Position $position, $authorizedby, $user_id)
    {
        $this->position = $position;
        $this->authorizedby = $authorizedby;
        $this->user_id_original = $user_id;
    }

    /**
     * Build the message.
     *
     * @return $this
     */
    public function build()
    {
        //because this is delayed -> check if position is still valid and assigned user is still the same
        $posStillValid = Position::find($this->position->id);
        if ($posStillValid != null && $posStillValid->user_id != null && $posStillValid->user_id == $this->user_id_original) {

            $client = $this->position->service()->first()->client()->first();
            $service = $this->position->service()->first();
            $this->servicepositions = $this->position->service->positions()->whereNotNull('user_id')->with('user')->with('qualification')->get();

            if (!empty($service->dateEnd)) {
                $start = new \Eluceo\iCal\Domain\ValueObject\DateTime(new \DateTime($service->date->toDateTimeString()), true);
                $end = new \Eluceo\iCal\Domain\ValueObject\DateTime(new \DateTime($service->dateEnd->toDateTimeString()), true);
                $occurrence = new \Eluceo\iCal\Domain\ValueObject\TimeSpan($start, $end);
            }
            else {
                $date = new \Eluceo\iCal\Domain\ValueObject\Date(new \DateTime($service->date->toDateString()));
                $occurrence = new \Eluceo\iCal\Domain\ValueObject\SingleDay($date);
            }

            $vEvent = new \Eluceo\iCal\Domain\Entity\Event();
            $vEvent->setOccurrence($occurrence);
            $vEvent->setSummary('Wachdienst');
            if(!empty($service->comment)) {
                $vEvent->setDescription($service->comment);
            }
            if (!empty($service->location)) {
                $vEvent->setLocation((new \Eluceo\iCal\Domain\ValueObject\Location($service->location, $service->location)));
            }
            $vCalendar = new \Eluceo\iCal\Domain\Entity\Calendar([$vEvent]);
            $iCalendarComponent = (new \Eluceo\iCal\Presentation\Factory\CalendarFactory())->createCalendar($vCalendar);

            return $this->subject('Dienstplan📟: Dienst zugewiesen')->view('email.position')->with([
                'position' => $this->position,
                'servicepositions' => $this->servicepositions,
                'authorizedby' => $this->authorizedby,
            ])->replyTo($client->mailReplyAddress, $client->mailSenderName)
            ->attachData(((string) $iCalendarComponent), 'dienst'.$service->date->toDateString().'.ics', [
                'mime' => 'text/calendar;charset=UTF-8;method=REQUEST',
            ]);
        }
    }
}<commit_msg>Upgrade Laravel 6 (lts) -> 9 (lts) #105 update ical module<commit_after><?php

namespace App\Mail;

use App\Position;
use Illuminate\Bus\Queueable;
use Illuminate\Mail\Mailable;
use Illuminate\Queue\SerializesModels;
use Illuminate\Contracts\Queue\ShouldQueue;

class PositionAssigned extends Mailable implements ShouldQueue
{
    use Queueable, SerializesModels;

    protected $position;
    protected $servicepositions;
    protected $authorizedby;
    protected $user_id_original;

    /**
     * Create a new message instance.
     *
     * @return void
     */
    public function __construct(Position $position, $authorizedby, $user_id)
    {
        $this->position = $position;
        $this->authorizedby = $authorizedby;
        $this->user_id_original = $user_id;
    }

    /**
     * Build the message.
     *
     * @return $this
     */
    public function build()
    {
        //because this is delayed -> check if position is still valid and assigned user is still the same
        $posStillValid = Position::find($this->position->id);
        if ($posStillValid != null && $posStillValid->user_id != null && $posStillValid->user_id == $this->user_id_original) {

            $client = $this->position->service()->first()->client()->first();
            $service = $this->position->service()->first();
            $this->servicepositions = $this->position->service->positions()->whereNotNull('user_id')->with('user')->with('qualification')->get();

            if (!empty($service->dateEnd)) {
                $start = new \Eluceo\iCal\Domain\ValueObject\DateTime(new \DateTime($service->date->toDateTimeString()), true);
                $end = new \Eluceo\iCal\Domain\ValueObject\DateTime(new \DateTime($service->dateEnd->toDateTimeString()), true);
                $occurrence = new \Eluceo\iCal\Domain\ValueObject\TimeSpan($start, $end);
            }
            else {
                $date = new \Eluceo\iCal\Domain\ValueObject\Date(new \DateTimeImmutable($service->date->toDateString()));
                $occurrence = new \Eluceo\iCal\Domain\ValueObject\SingleDay($date);
            }

            $vEvent = new \Eluceo\iCal\Domain\Entity\Event();
            $vEvent->setOccurrence($occurrence);
            $vEvent->setSummary('Wachdienst');
            if(!empty($service->comment)) {
                $vEvent->setDescription($service->comment);
            }
            if (!empty($service->location)) {
                $vEvent->setLocation((new \Eluceo\iCal\Domain\ValueObject\Location($service->location, $service->location)));
            }
            $vCalendar = new \Eluceo\iCal\Domain\Entity\Calendar([$vEvent]);
            $iCalendarComponent = (new \Eluceo\iCal\Presentation\Factory\CalendarFactory())->createCalendar($vCalendar);

            return $this->subject('Dienstplan📟: Dienst zugewiesen')->view('email.position')->with([
                'position' => $this->position,
                'servicepositions' => $this->servicepositions,
                'authorizedby' => $this->authorizedby,
            ])->replyTo($client->mailReplyAddress, $client->mailSenderName)
            ->attachData(((string) $iCalendarComponent), 'dienst'.$service->date->toDateString().'.ics', [
                'mime' => 'text/calendar;charset=UTF-8;method=REQUEST',
            ]);
        }
    }
}
{'fraction_non_alphanumeric': 0.15252953650408968, 'fraction_numerical': 0.0010602847621932747, 'mean_word_length': 2.6400220507166483, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 120, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2241433', 'n_tokens_mistral': 1875, 'n_tokens_neox': 1833, 'n_words': 305}