participants()->whereNull('unregistered_at'); } else { $allParticipants = $event->participants()->whereNotNull('unregistered_at'); } foreach ($allParticipants->orderBy('lastname')->orderBy('firstname')->get() as $participant) { $participants[] = $participant->toResource()->toArray($request); }; return $participants; } public function getByIdentifier(string $identifier, EventRepository $eventRepository, bool $withPermissionCheck = true) : ?EventParticipant { $participant = EventParticipant::where('identifier', $identifier)->first(); if ($participant === null) { return null; } if ($withPermissionCheck) { $event = $eventRepository->getById($participant->event_id); if ($event === null) { return null; } } return $participant; } public function groupByLocalGroup(Event $event, Request $request, ?string $filter = null) : array { $allParticipants = $this->getForList($event, $request); $participants = []; foreach ($allParticipants as $participant) { if ($filter === null || $participant['localgroup'] === $filter) { $participants[$participant['localgroup']][] = $participant; } } return $participants; } public function groupByParticipationType(Event $event, Request $request, ?string $filter = null) : array { $allParticipants = $this->getForList($event, $request); $participants = []; foreach ($allParticipants as $participant) { if ($filter === null || $participant['participationType'] === $filter) { $participants[$participant['participationType']][] = $participant; } } return $participants; } public function getSignedOffParticipants(Event $event, Request $request, ?string $filter = null) : array { $allParticipants = $this->getForList($event, $request, true); $participants = []; foreach ($allParticipants as $participant) { if ($filter === null || $participant['participationType'] === $filter) { $participants[$participant['participationType']][] = $participant; } } return $participants; } public function getParticipantsWithMissingPayments(Event$event, Request $request) : array { $participants = []; foreach ($event->participants()->whereNull('unregistered_at') ->whereColumn('amount', '<>', 'amount_paid') ->get() as $participant) { $participants[] = $participant; }; return $participants; } public function getParticipantsWithIntolerances(Event $event, Request $request) : array { $participants = []; foreach ($event->participants()->whereNotNull('intolerances')->whereNot('intolerances' , '=', '')->get() as $participant) { $participants[] = $participant->toResource()->toArray($request); }; return $participants; } public function getKitchenOverview(Event $event) : array { $data = []; $participants = $event->participants()->get(); for ($cur_date = $event->start_date; $cur_date <= $event->end_date; $cur_date->modify('+1 day')) { $dateKey = $cur_date->format('d.m.Y'); $data[$dateKey] = [ '1' => [], '2' => [], '3' => [], ]; foreach (EatingHabit::all() as $eatingHabit) { $data[$dateKey]['1'][$eatingHabit->slug] = 0; $data[$dateKey]['2'][$eatingHabit->slug] = 0; $data[$dateKey]['3'][$eatingHabit->slug] = 0; } foreach ($participants as $participant) { $eatingHabitSlug = $participant->eating_habit; if ($eatingHabitSlug === null) { continue; } $anreise = $participant->arrival_date; $abreise = $participant->departure_date; if ($anreise->getTimestamp() === $cur_date->getTimestamp()) { switch ((int)$participant->arrival_eating) { case 1: $data[$dateKey]['3'][$eatingHabitSlug]++; break; case 2: $data[$dateKey]['2'][$eatingHabitSlug]++; $data[$dateKey]['3'][$eatingHabitSlug]++; break; case 3: $data[$dateKey]['1'][$eatingHabitSlug]++; $data[$dateKey]['2'][$eatingHabitSlug]++; $data[$dateKey]['3'][$eatingHabitSlug]++; break; } } elseif ($abreise->getTimestamp() === $cur_date->getTimestamp()) { switch ((int)$participant->departure_eating) { case 1: $data[$dateKey]['1'][$eatingHabitSlug]++; break; case 2: $data[$dateKey]['1'][$eatingHabitSlug]++; $data[$dateKey]['2'][$eatingHabitSlug]++; break; case 3: $data[$dateKey]['1'][$eatingHabitSlug]++; $data[$dateKey]['2'][$eatingHabitSlug]++; $data[$dateKey]['3'][$eatingHabitSlug]++; break; } } else { $data[$dateKey]['1'][$eatingHabitSlug]++; $data[$dateKey]['2'][$eatingHabitSlug]++; $data[$dateKey]['3'][$eatingHabitSlug]++; } } } return $data; } public function getMailAddresses(array $participants) : array { $mailAddresses = []; foreach ($participants as $participant) { if (!in_array($participant['email_1'], $mailAddresses)) { $mailAddresses[] = $participant['email_1']; } if ($participant['email_2'] !== null && !in_array($participant['email_2'], $mailAddresses)) { $mailAddresses[] = $participant['email_2']; } } return $mailAddresses; } public function getMyParticipations(?int $maxEvents = null) : array { $participations = []; $user = auth()->user(); if ($user === null) { return $participations; } $request = new \Illuminate\Http\Request(); $query = EventParticipant::where('user_id', $user->id) ->whereNull('unregistered_at') ->whereHas('event', function ($q) { $q->where('end_date', '>=', now()); }) ->with(['event']) ->join('events', 'event_participants.event_id', '=', 'events.id') ->orderBy('events.start_date', 'asc') ->select('event_participants.*'); if ($maxEvents !== null) { $query->limit($maxEvents); } foreach ($query->get() as $participant) { $participations[] = $participant->toResource()->toArray($request); } return $participations; } public function getMyParticipationByIdentifier(string $identifier) : ?EventParticipant { $user = auth()->user(); if ($user === null) { return null; } return EventParticipant::where('identifier', $identifier) ->where('tenant', app('tenant')->slug) ->where('user_id', $user->id) ->whereNull('unregistered_at') ->first(); } }