ogcore/src/Entity/PxeTemplate.php

117 lines
2.7 KiB
PHP

<?php
namespace App\Entity;
use App\Repository\PxeTemplateRepository;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\DBAL\Types\Types;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
#[ORM\Entity(repositoryClass: PxeTemplateRepository::class)]
#[ORM\UniqueConstraint(name: 'UNIQ_PXE_TEMPLATE_NAME_SERVER', fields: ['name', 'bootServer'])]
#[UniqueEntity(fields: ['name', 'bootServer'], message: 'La plantilla ya existe en este servidor')]
class PxeTemplate extends AbstractEntity
{
use NameableTrait;
use SynchronizedTrait;
#[ORM\Column(type: Types::TEXT)]
private ?string $templateContent = null;
/**
* @var Collection<int, Client>
*/
#[ORM\OneToMany(mappedBy: 'template', targetEntity: Client::class)]
private Collection $clients;
#[ORM\Column(nullable: true)]
private ?bool $isDefault = null;
#[ORM\ManyToOne(inversedBy: 'templates')]
#[ORM\JoinColumn(nullable: true)]
private ?BootServer $bootServer = null;
public function __construct()
{
parent::__construct();
$this->clients = new ArrayCollection();
}
public function getTemplateContent(): ?string
{
return $this->templateContent;
}
public function setTemplateContent(string $templateContent): static
{
$this->templateContent = $templateContent;
return $this;
}
/**
* @return Collection<int, Client>
*/
public function getClients(): Collection
{
return $this->clients;
}
public function setClients(array $clients): static
{
$this->clients->clear();
foreach ($clients as $client){
$this->addClient($client);
}
return $this;
}
public function addClient(Client $client): static
{
if (!$this->clients->contains($client)) {
$this->clients->add($client);
}
return $this;
}
public function removeClient(Client $client): static
{
if ($this->clients->removeElement($client)) {
if ($client->getTemplate() === $this) {
$client->setTemplate(null);
}
}
return $this;
}
public function isDefault(): ?bool
{
return $this->isDefault;
}
public function setDefault(?bool $isDefault): static
{
$this->isDefault = $isDefault;
return $this;
}
public function getBootServer(): ?BootServer
{
return $this->bootServer;
}
public function setBootServer(?BootServer $bootServer): static
{
$this->bootServer = $bootServer;
return $this;
}
}