Move DomainController::NODE* to Address::NODE*, make role mandatory in the database, change logic so that mail generated by the host comes from a node address.
This commit is contained in:
@@ -7,8 +7,6 @@ use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Support\Collection;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
|
||||
use App\Http\Controllers\DomainController;
|
||||
|
||||
class System extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
@@ -103,17 +101,17 @@ class System extends Model
|
||||
public function full_name(Address $o): string
|
||||
{
|
||||
switch ($o->attributes['role']) {
|
||||
case DomainController::NODE_ZC;
|
||||
case Address::NODE_ZC;
|
||||
return sprintf('ZC-%s-%05d',$o->zone->domain->name,$o->zone->zone_id);
|
||||
|
||||
case DomainController::NODE_RC;
|
||||
case Address::NODE_RC;
|
||||
return sprintf('RC-%s-%05d',$o->zone->domain->name,$o->region_id);
|
||||
|
||||
case DomainController::NODE_NC;
|
||||
case Address::NODE_NC;
|
||||
return sprintf('NC-%s-%05d',$o->zone->domain->name,$o->host_id);
|
||||
|
||||
case DomainController::NODE_HC;
|
||||
case NULL:
|
||||
case Address::NODE_HC;
|
||||
case Address::NODE_ACTIVE;
|
||||
default:
|
||||
return $this->name;
|
||||
}
|
||||
@@ -121,12 +119,18 @@ class System extends Model
|
||||
|
||||
/**
|
||||
* Return the system's address in the same zone
|
||||
* This function can filter based on the address type needed.
|
||||
*
|
||||
* @param Zone $o
|
||||
* @param int $type
|
||||
* @return Collection
|
||||
*/
|
||||
public function match(Zone $o): Collection
|
||||
public function match(Zone $o,int $type=(Address::NODE_HC|Address::NODE_ACTIVE|Address::NODE_PVT|Address::NODE_POINT)): Collection
|
||||
{
|
||||
return $this->addresses->where('zone_id',$o->id);
|
||||
return $this->addresses
|
||||
->where('zone_id',$o->id)
|
||||
->filter(function($item) use ($type) {
|
||||
return $item->role & $type;
|
||||
});
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user