File: D:/HostingSpaces/SBogers10/farmfun.komma.pro/app/Komma/Locations/Models/LocationAvailability.php
<?php
namespace App\Komma\Locations\Models;
use App\Komma\Locations\Types\DayInfo;
use Carbon\Carbon;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
final class LocationAvailability extends Model
{
protected $table = 'location_availability';
protected $guarded = ['id', 'location_id'];
public function location(): BelongsTo
{
return $this->belongsTo(Location::class);
}
/**
* Get an object with the info for the given day of the week
*
* @param Carbon $date
* @return object
*/
public function infoForDay(Carbon $date)
{
$date->dayOfWeek;
return new DayInfo($date,
$this->{'day_'.$date->dayOfWeek.'_open'},
$this->{'day_'.$date->dayOfWeek.'_from'},
$this->{'day_'.$date->dayOfWeek.'_till'},
$this->{'day_'.$date->dayOfWeek.'_latest_start'});
}
/**
* Get an array of the days of the week that this location is closed
*
* @return array
*/
public function daysOfTheWeekClosed(): array
{
$dayOfTheWeekClosed = [];
for ($d = 0; $d < 6; $d++) {
if ($this->{'day_'.$d.'_open'}) {
continue;
}
$dayOfTheWeekClosed[] = $d;
}
return $dayOfTheWeekClosed;
}
}