182 lines
6.8 KiB
PHP
182 lines
6.8 KiB
PHP
<?php
|
|
|
|
namespace App\Repositories;
|
|
|
|
use App\Enumerations\EatingHabit;
|
|
use App\Models\Event;
|
|
use App\Models\EventParticipant;
|
|
use Illuminate\Http\Request;
|
|
|
|
class EventParticipantRepository {
|
|
public function getForList(Event $event, Request $request, bool $signedOffParticipants = false) : array {
|
|
$participants = [];
|
|
|
|
if (!$signedOffParticipants) {
|
|
$allParticipants = $event->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;
|
|
}
|
|
}
|