File: D:/HostingSpaces/SBogers10/ste.komma.pro/app/Locations/Models/Location.php
<?php
namespace App\Locations\Models;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Support\Str;
use Komma\KMS\Core\AbstractTranslatableModel;
use Komma\KMS\Core\Attributes\Models\Traits\HasThumbnailInterface;
use Komma\KMS\Core\Attributes\Models\Traits\HasThumbnailTrait;
use Komma\KMS\Core\Tree\NestedSets\Nodes\TreeModelInterface;
use Komma\KMS\Core\Tree\NestedSets\Nodes\TreeModelLogicTrait;
use Komma\KMS\Documents\DocumentsTrait;
use Komma\KMS\Documents\Kms\DocumentableInterface;
use Komma\KMS\Core\Entities\DisplayNameInterface;
use Komma\KMS\Core\Entities\DisplayNameTrait;
use Komma\KMS\Helpers\KommaHelpers;
use Komma\KMS\Sites\HasSiteInterface;
use Illuminate\Support\Carbon;
use Komma\KMS\Sites\Models\SiteInterface;
/**
* Class Page
*
* @package App\Pages\Models
* @property int site_id
* @property int lft
* @property int rgt
* @property int tree
* @property-read Carbon $date
* @property-read \Illuminate\Database\Eloquent\Collection|\App\Sites\Models\Site $site
* @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\Locations\Models\Location whereActive($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\Locations\Models\Location whereCreatedAt($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\Locations\Models\Location whereDate($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\Locations\Models\Location whereId($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\Locations\Models\Location whereUpdatedAt($value)
* @property-read \Illuminate\Database\Eloquent\Collection|\Komma\KMS\Documents\Models\Document[] $documents
* @property-read \Illuminate\Database\Eloquent\Collection|\Komma\KMS\Documents\Models\Document[] $images
* @method static \Illuminate\Database\Eloquent\Builder|\App\Locations\Models\Location newModelQuery()
* @method static \Illuminate\Database\Eloquent\Builder|\App\Locations\Models\Location newQuery()
* @method static \Illuminate\Database\Eloquent\Builder|\App\Locations\Models\Location query()
*/
final class Location extends Model implements HasSiteInterface, DocumentableInterface, DisplayNameInterface, TreeModelInterface, HasThumbnailInterface
{
use HasThumbnailTrait;
use TreeModelLogicTrait;
use DocumentsTrait;
use DisplayNameTrait;
protected $class = Location::class;
const ONLINE_ID = 12;
protected $fillable = [
'active',
'name',
'address',
'zip',
'city',
'phone_display',
'phone_tel',
'email',
'hours_weekdays',
'hours_friday',
'hours_saturday',
'site_id',
'lft',
'rgt',
'tree'
];
/**
* Get the site for this this model
*
* @return belongsTo
*/
public function site(): BelongsTo
{
return $this->belongsTo(get_class(app(SiteInterface::class)), 'site_id'); //Model must have site_id attribute
}
/**
* Return a number, representing some color that represents
* the status if the TreeModel. Used at the frontend
*
* @return mixed
*/
public function getColorStatusNumber(): int
{
return $this->active ?: 0;
}
/**
* Get the name of this model by model or translation model
*
* @return null|string
*/
public function getDisplayName():?string
{
// If it is a new model the section name will filled by model.section.new
if(!$this->exists) return null;
// First try to get the name of the model
// if(isset($this->name) && $this->name != '') { //When you do an isset like this, you cannot use a magic method like in orders to set and return the name of a model
if(isset($this->name) && $this->name != '') {
return $this->name . ' - ' . $this->city;
}
return null;
}
}