*/ class ZoneLinked { private $connectedZone; private $zone; private $serverID; public function __construct($newZone = false, $serverID = false) { $this->zone = $newZone; $this->serverID = $serverID; if(!$this->serverID) { $this->serverID = $this->zone->serverid; } } private function checkAppendingZone() { if(!$this->zone || !$this->serverID) { return; } $repo = Repository::factory()->byName($this->zone->name)->byServerID($this->serverID)->one(); if(empty($repo)) { return; } $this->connectedZone->connectedWithType = 0; $this->connectedZone->connectedWithRelid = 0; if($repo->type == ZoneTypeEnum::DOMAIN && $this->zone->type == ZoneTypeEnum::HOSTING) { $this->connectedZone->connectedWithType = $this->zone->type; $this->connectedZone->connectedWithRelid = $this->zone->relid; } else if($repo->type == ZoneTypeEnum::HOSTING && $this->zone->type == ZoneTypeEnum::DOMAIN) { $this->connectedZone->connectedWithType = $this->zone->type; $this->connectedZone->connectedWithRelid = $this->zone->relid; } } private function checkIfZoneNeedConnect() { if(!$this->zone) { return; } $this->connectedZone->connectedWithType = 0; $this->connectedZone->connectedWithRelid = 0; if($this->zone->type == ZoneTypeEnum::HOSTING) { $rep = DomainRepository::factory()->byDomainName($this->zone->name)->one(); if(!$rep) { return; } $this->connectedZone->connectedWithType = ZoneTypeEnum::DOMAIN; $this->connectedZone->connectedWithRelid = $rep->id; } else if($this->zone->type == ZoneTypeEnum::DOMAIN) { $rep = ServiceRepository::factory()->byDomainName($this->zone->name)->one(); if(!$rep) { return; } $this->connectedZone->connectedWithType = ZoneTypeEnum::HOSTING; $this->connectedZone->connectedWithRelid = $rep->id; } } private function connectZones() { if(!$this->connectedZone || !$this->zone) { return false; } if($this->connectedZone->connectedWithType == 0 || $this->connectedZone->connectedWithRelid == 0) { return false; } $rep = Repository::factory()->byName($this->zone->name)->byServerID($this->serverID)->one(); if(!$rep || $rep->connectedWithRelid == $this->connectedZone->connectedWithRelid) { return false; } $rep->connectedWithType = $this->connectedZone->connectedWithType; $rep->connectedWithRelid = $this->connectedZone->connectedWithRelid; $rep->save(); return true; } public function connectByNewZone() { $this->checkAppendingZone(); return $this->connectZones(); } public function connectByService() { $this->checkIfZoneNeedConnect(); $this->connectZones(); } }