diff --git a/src/Dto/Input/ClientInput.php b/src/Dto/Input/ClientInput.php index c48812c..f8cdac7 100644 --- a/src/Dto/Input/ClientInput.php +++ b/src/Dto/Input/ClientInput.php @@ -85,7 +85,7 @@ final class ClientInput #[ApiProperty( description: 'La plantilla PXE del cliente' )] - public ?PxeTemplateOutput $template = null; + public ?PxeTemplateOutput $pxeTemplate = null; #[Groups(['client:write'])] #[ApiProperty( @@ -143,7 +143,7 @@ final class ClientInput } if ($client->getTemplate()) { - $this->template = new PxeTemplateOutput($client->getTemplate()); + $this->pxeTemplate = new PxeTemplateOutput($client->getTemplate()); } if ($client->getHardwareProfile()) { @@ -165,7 +165,7 @@ final class ClientInput $ogLive = $this->ogLive?->getEntity() ?? $client->getOrganizationalUnit()?->getNetworkSettings()?->getOgLive(); $hardwareProfile = $this->hardwareProfile?->getEntity() ?? $client->getOrganizationalUnit()?->getNetworkSettings()?->getHardwareProfile(); $repository = $this->repository?->getEntity() ?? $client->getOrganizationalUnit()?->getNetworkSettings()?->getRepository(); - $template = $this->template?->getEntity() ?? $client->getOrganizationalUnit()?->getNetworkSettings()?->getPxeTemplate(); + $template = $this->pxeTemplate?->getEntity() ?? $client->getOrganizationalUnit()?->getNetworkSettings()?->getPxeTemplate(); $client->setName($this->name); $client->setSerialNumber($this->serialNumber); diff --git a/src/Dto/Output/ClientOutput.php b/src/Dto/Output/ClientOutput.php index c859ee8..8e600d7 100644 --- a/src/Dto/Output/ClientOutput.php +++ b/src/Dto/Output/ClientOutput.php @@ -123,11 +123,27 @@ final class ClientOutput extends AbstractOutput $this->pxeTemplate = $template ? new PxeTemplateOutput($template) : null; $this->hardwareProfile = $client->getHardwareProfile() ? new HardwareProfileOutput($client->getHardwareProfile()) : null; - $this->subnet = $client->getSubnet()?->getIpAddress(); + + if ($client->getSubnet()){ + $this->subnet = $client->getSubnet()?->getIpAddress().'/' + . $this->convertMaskToCIDR($client->getSubnet() ? $client->getSubnet()->getNetmask() : $client->getOrganizationalUnit()->getNetworkSettings()->getNetmask()); + } + $this->status = $client->getStatus(); $this->createdAt = $client->getCreatedAt(); $this->createdBy = $client->getCreatedBy(); $this->maintenance = $client->isMaintenance(); $this->pxeSync = $client->isPxeSync(); } + + public function convertMaskToCIDR($mask): int + { + $bits = 0; + $mask = explode(".", $mask); + + foreach ($mask as $oct) + $bits += strlen(str_replace("0", "", decbin($oct))); + + return $bits; + } } \ No newline at end of file diff --git a/src/Entity/Client.php b/src/Entity/Client.php index a3930ca..023fcf8 100644 --- a/src/Entity/Client.php +++ b/src/Entity/Client.php @@ -64,6 +64,7 @@ class Client extends AbstractEntity private ?array $position = ['x' => 0, 'y' => 0]; #[ORM\ManyToOne(inversedBy: 'clients')] + #[ORM\JoinColumn( onDelete: 'SET NULL')] private ?PxeTemplate $template = null; #[ORM\ManyToOne()]