clrghouz/app/Models/Zone.php

90 lines
1.8 KiB
PHP
Raw Permalink Normal View History

2019-04-26 04:30:00 +00:00
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
use App\Traits\{QueryCacheableConfig,ScopeActive};
2019-04-26 04:30:00 +00:00
class Zone extends Model
{
use QueryCacheableConfig,ScopeActive;
/* SCOPES */
public function scopeDomainZoneOrder($query)
{
return $query
->select('zones.*')
->join('domains',['domains.id'=>'zones.domain_id'])
->orderBy('domains.name')
->orderBy('zone_id');
}
2021-05-13 12:40:21 +00:00
/* RELATIONS */
public function addresses()
{
return $this->hasMany(Address::class)
->active()
->FTNorder()
->with(['system.sessions','system.setup','zone.domain']);
}
2021-05-13 12:40:21 +00:00
public function domain()
{
return $this->belongsTo(Domain::class);
}
public function hosts()
{
return $this->hasMany(Address::class)
->where(function($query) {
return $query
->where(fn($q)=>$q->where('node_id',0)->where('point_id',0))
->orWhere('role',Address::NODE_HC);
})
->FTNorder()
->with(['system','zone.domain']);
}
public function hubs()
{
// @todo we should be able to add to this query, to count children of an address by using a group by?
return $this->hasMany(Address::class)
->where(function($query) {
return $query
->where(fn($q)=>$q->where('point_id',0))
->orWhere('role',Address::NODE_HC);
})
->FTNorder()
->with(['system','zone.domain']);
}
public function regions()
{
return $this->hasMany(Address::class)
->where(function($query) {
return $query
->where(fn($q)=>$q->where('node_id',0)->where('point_id',0))
->orWhere('role',Address::NODE_RC);
})
->orderBy('region_id')
->active()
->with(['system','zone.domain']);
}
public function system()
{
return $this->belongsTo(System::class);
}
2021-08-09 13:35:22 +00:00
/**
* Get the default route for this zone
*/
public function systems()
{
return $this->belongsToMany(System::class)
->withPivot(['default']);
}
2019-04-26 04:30:00 +00:00
}