67 lines
1.6 KiB
PHP
67 lines
1.6 KiB
PHP
<?php
|
|
|
|
namespace App\Helpers;
|
|
|
|
use Carbon\Carbon;
|
|
use Carbon\CarbonPeriod;
|
|
use Illuminate\Support\Collection;
|
|
|
|
class Helper{
|
|
public static function genderNormalization($anyGenderCode)
|
|
{
|
|
if ($anyGenderCode == 'M') {
|
|
return 'male';
|
|
} else if ($anyGenderCode == 'F') {
|
|
return 'female';
|
|
} else if ($anyGenderCode == 'O') {
|
|
return 'others';
|
|
} else if ($anyGenderCode == 'U') {
|
|
return 'unknown';
|
|
} else {
|
|
return null;
|
|
}
|
|
}
|
|
|
|
public static function paginateResources($resource)
|
|
{
|
|
return [
|
|
'current_page' => $resource->currentPage(),
|
|
'data' => $resource->items(),
|
|
'first_page_url' => '',
|
|
'from' => $resource->firstItem(),
|
|
'last_page' => $resource->lastPage(),
|
|
'last_page_url' => '',
|
|
'links' => $resource->links(null, $resource->items()),
|
|
'next_page_url' => $resource->nextPageUrl(),
|
|
];
|
|
}
|
|
|
|
public static function dailyAvailabilitiesToDate($dailyAvailabilities, $startDate, $endDate = null) {
|
|
|
|
Carbon::setLocale('id');
|
|
|
|
$startDate = Carbon::parse($startDate);
|
|
if ( empty($endDate) ) {
|
|
$endDate = $startDate;
|
|
} else {
|
|
$endDate = Carbon::parse($endDate);
|
|
}
|
|
$ranges = CarbonPeriod::create($startDate, $endDate);
|
|
|
|
$datesAvailabilities = [];
|
|
foreach ( $ranges as $date ) {
|
|
|
|
$datesAvailabilities[] = [
|
|
'date' => $date->format('Y-m-d'),
|
|
'day' => $date->dayName,
|
|
'slot' => $dailyAvailabilities[$date->dayName],
|
|
'timezone' => 'WIB'
|
|
];
|
|
|
|
}
|
|
|
|
return $datesAvailabilities;
|
|
|
|
}
|
|
}
|