File: D:/HostingSpaces/SBogers10/farmfun.komma.pro/app/Komma/Locations/Models/Location.php
<?php
namespace App\Komma\Locations\Models;
use App\Komma\Documents\DocumentsTrait;
use App\Komma\Documents\Kms\DocumentableInterface;
use App\Komma\Globalization\Languages\Models\Language;
use App\Komma\Kms\Core\AbstractTranslatableModel;
use App\Komma\Kms\Core\Entities\DisplayNameInterface;
use App\Komma\Kms\Core\Entities\DisplayNameTrait;
use App\Komma\LocationProducts\Models\LocationProduct;
use App\Komma\Products\Models\Product;
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
use Illuminate\Database\Eloquent\Relations\HasMany;
use Illuminate\Database\Eloquent\Relations\HasOne;
/**
* Class Location
*
* @property-read \App\Komma\Globalization\Languages\Models\Language[] $languages
* @property-read \App\Komma\Locations\Models\LocationTranslation $translation
* @property-read \Illuminate\Database\Eloquent\Collection|\App\Komma\Locations\Models\LocationTranslation[] $translations
* @mixin \Eloquent
* @property int $id
* @property int $active
* @property \Carbon\Carbon|null $created_at
* @property \Carbon\Carbon|null $updated_at
* @method static \Illuminate\Database\Eloquent\Builder|\App\Komma\Locations\Models\Location whereActive($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\Komma\Locations\Models\Location whereCreatedAt($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\Komma\Locations\Models\Location whereId($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\Komma\Locations\Models\Location whereUpdatedAt($value)
* @property-read \Illuminate\Database\Eloquent\Collection|\App\Komma\Documents\Models\Document[] $documents
* @property-read \Illuminate\Database\Eloquent\Collection|\App\Komma\Documents\Models\Document[] $images
* @method static \Illuminate\Database\Eloquent\Builder|\App\Komma\Locations\Models\Location newModelQuery()
* @method static \Illuminate\Database\Eloquent\Builder|\App\Komma\Locations\Models\Location newQuery()
* @method static \Illuminate\Database\Eloquent\Builder|\App\Komma\Locations\Models\Location query()
*/
final class Location extends AbstractTranslatableModel implements DocumentableInterface, DisplayNameInterface
{
use DocumentsTrait;
use DisplayNameTrait;
protected $class = self::class;
protected $protected = ['id', 'created_at', 'updated_at', 'map_left', 'map_top'];
/**
* Gets the translation models for this model
*
* @return HasMany that resolves to AbstractTranslationModel instances
*/
public function translations(): HasMany
{
return $this->hasMany(LocationTranslation::class);
}
public function languages(): BelongsToMany
{
return $this->belongsToMany(Language::class, 'location_translations')
->withPivot('slug', 'name', 'description')
->withTimestamps();
}
public function productSettings(): HasMany
{
return $this->hasMany(LocationProduct::class)
->orderBy('sort_order');
}
public function boundProducts(): BelongsToMany
{
return $this->belongsToMany(Product::class, 'location_products')
->wherePivot('active', 1)
->withPivot('max_persons_each_block', 'available_each_block', 'capacity_type')
->where('products.active', 1)
->orderBy('location_products.sort_order');
}
/**
* @param $links
* @return string|null
*/
public function getLocationLink($links): ? string
{
if (! isset($this->province_page_id)) {
return null;
}
if (! $provinceNode = collect($links)
->where('page_id', $this->province_page_id)
->first()) {
return null;
}
return $provinceNode->route.'/'.$this->translation->slug;
}
public function availability(): HasOne
{
return $this->hasOne(LocationAvailability::class);
}
/**
* @return string
*/
public function getCityNameForTeamleader():string
{
if (! in_array($this->id, [8])) {
return $this->city;
}
switch ($this->id) {
case 8:
return 'Beveren';
}
throw new \UnexpectedValueException('Id not mapped to custom city name');
}
}