HEX
Server: Microsoft-IIS/8.5
System: Windows NT YDAWBH120 6.3 build 9600 (Windows Server 2012 R2 Standard Edition) AMD64
User: tentjecom_web (0)
PHP: 7.4.14
Disabled: NONE
Upload Files
File: D:/HostingSpaces/farmfun/reserveren.farmfun.be/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;
    }
}