clrghouz/app/Models/System.php
2021-06-25 22:21:19 +10:00

50 lines
1016 B
PHP

<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use App\Http\Controllers\DomainController;
use App\Traits\ScopeActive;
class System extends Model
{
use HasFactory,ScopeActive;
/* RELATIONS */
public function addresses()
{
return $this->hasMany(Address::class)
->orderBy('region_id')
->orderBy('host_id')
->orderBy('node_id')
->orderBy('point_id');
}
/* GENERAL METHODS */
/**
* Return the system name, or role name for the zone
*
* @param Address $o
* @return string
*/
public function full_name(Address $o): string
{
switch ($o->attributes['role']) {
case DomainController::NODE_ZC;
return sprintf('ZC-%s-%05d',$o->zone->domain->name,$o->zone->zone_id);
case DomainController::NODE_RC;
return sprintf('RC-%s-%05d',$o->zone->domain->name,$o->region_id);
case DomainController::NODE_NC;
case DomainController::NODE_HC;
case NULL:
default:
return $this->name;
}
}
}