WIP: Implement application process
This commit is contained in:
@@ -0,0 +1,46 @@
|
||||
<?php
|
||||
|
||||
namespace App\Service\Teamer;
|
||||
|
||||
use App\Entity\Availability;
|
||||
use Carbon\Carbon;
|
||||
|
||||
class AvailabilityProcessor
|
||||
{
|
||||
/**
|
||||
* Groups provided unsorted availabilities by year and month
|
||||
* [
|
||||
* '2023' => [
|
||||
* 'Januar' => [
|
||||
* ...
|
||||
* ],
|
||||
* 'Juni' => [
|
||||
* ...
|
||||
* ],
|
||||
* ],
|
||||
* ]
|
||||
*/
|
||||
public function groupRecords(array $records): array
|
||||
{
|
||||
$availabilities = [];
|
||||
|
||||
foreach ($records as $record) {
|
||||
/** @var Availability $record */
|
||||
$dateFrom = $record->getDateFrom();
|
||||
$year = $dateFrom->format('Y');
|
||||
$month = (new Carbon($dateFrom))->locale('de_DE')->monthName;
|
||||
|
||||
if (false === isset($availabilities[$year])) {
|
||||
$availabilities[$year] = [];
|
||||
}
|
||||
|
||||
if (false === isset($availabilities[$year][$month])) {
|
||||
$availabilities[$year][$month] = [];
|
||||
}
|
||||
|
||||
$availabilities[$year][$month][] = $record;
|
||||
}
|
||||
|
||||
return $availabilities;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user