kompass/modules/event-participants/Requests/class-eatingrequest.php
2024-05-31 22:47:04 +02:00

50 lines
1.6 KiB
PHP

<?php
namespace Bdp\Modules\EventParticipants\Reqeust;
use Carbon\Carbon;
class EatingRequest {
public static function send(array $participantList, string $eatingHabit, \DateTime $date) {
$participantCount = [ '1' => 0, '2' => 0, '3' => 0 ];
foreach ($participantList as $participant) {
if ( $participant->essgewohnheit !== $eatingHabit ) {
continue;
}
$anreise = \DateTime::createFromFormat( 'Y-m-d', $participant->anreise );
$abreise = \DateTime::createFromFormat( 'Y-m-d', $participant->abreise );
if ( $anreise->getTimestamp() < $date->getTimestamp() && $abreise->getTimestamp() > $date->getTimestamp() ) {
$participantCount['1']++;
$participantCount['2']++;
$participantCount['3']++;
} elseif ( $anreise->getTimestamp() == $date->getTimestamp() ) { // Anreisetag
if ( $participant->anreise_essen == 3 ) {
$participantCount['1']++;
$participantCount['2']++;
$participantCount['3']++;
} elseif ( $participant->anreise_essen == 2 ) {
$participantCount['2']++;
$participantCount['3']++;
} elseif ( $participant->anreise_essen == 1 ) {
$participantCount['3']++;
}
} elseif ( $abreise->getTimestamp() == $date->getTimestamp() ) { // Abreisetag
if ( $participant->abreise_essen == 3 ) {
$participantCount['1']++;
$participantCount['2']++;
$participantCount['3']++;
} elseif ( $participant->abreise_essen == 2 ) {
$participantCount['1']++;
$participantCount['2']++;
} elseif ( $participant->abreise_essen == 1 ) {
$participantCount['1']++;
}
}
}
return $participantCount;
}
}