clrghouz/app/Models/Node.php

72 lines
1.3 KiB
PHP
Raw Normal View History

2019-04-26 04:30:00 +00:00
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
class Node extends Model
{
2021-05-13 12:40:21 +00:00
protected $casts = [
'is_zc'=>'boolean',
'is_rc'=>'boolean',
'is_hub'=>'boolean',
'is_host'=>'boolean',
];
2019-04-27 13:57:39 +00:00
protected $fillable = ['zone_id','host_id','node_id','point_id'];
2019-04-26 04:30:00 +00:00
2021-05-13 12:40:21 +00:00
/* SCOPES */
public function scopeHost()
{
}
/* RELATIONS */
/**
* Node nodelist flags
*
* @return \Illuminate\Database\Eloquent\Relations\BelongsToMany
*/
public function flags()
{
2019-04-26 04:30:00 +00:00
return $this->belongsToMany(Flag::class);
}
2021-05-13 12:40:21 +00:00
public function zone()
{
return $this->belongsTo(Zone::class);
}
/* ATTRIBUTES */
/**
* Render the node name in full 5D
*
* @return string
*/
2019-04-27 13:57:39 +00:00
public function getFTNAttribute()
{
2021-05-13 12:40:21 +00:00
return $this->zone_id
? sprintf('%s:%s/%s.%s',$this->zone->zone_id,$this->host_id,$this->node_id,$this->point_id)
: '-';
2019-04-27 13:57:39 +00:00
}
2021-05-13 12:40:21 +00:00
/**
* Get this nodes uplink
*/
public function getUplinkAttribute()
{
// @todo Need to work this out properly
return static::where('zone_id','10')->where('host_id',1)->where('node_id',0)->where('point_id',0)->first();
}
/* METHODS */
public function hasFlag($relation,$model)
2019-04-26 04:30:00 +00:00
{
return (bool) $this->{$relation}()
->wherePivot($model->getForeignKey(),$model->{$model->getKeyName()})
->count();
}
}