<?php
/**
* @author Leo BANNHOLTZER (contact@scaledev.fr)
* @copyright 2021 - ScaleDEV SAS, 12 RUE CHARLES MORET, 10120 ST ANDRE LES VERGERS
* @license commercial
*/
declare(strict_types=1);
namespace App\Entity;
use Symfony\Component\Uid\Uuid;
use Doctrine\ORM\Mapping as ORM;
use Gedmo\Mapping\Annotation as Gedmo;
use App\DoctrineExtensions\IsActiveEntity;
use App\Repository\CountryStateRepository;
use Doctrine\Common\Collections\Collection;
use Doctrine\Common\Collections\ArrayCollection;
use Symfony\Bridge\Doctrine\IdGenerator\UuidGenerator;
use App\DoctrineExtensions\Timestampable\Traits\UserTimestampableEntity;
use App\DoctrineExtensions\SoftDeleteable\Traits\UserSoftDeleteableEntity;
/**
* @ORM\Entity(repositoryClass=CountryStateRepository::class)
* @ORM\Table(name="country_state", indexes={
* @ORM\Index(name="name", columns={"name"}),
* @ORM\Index(name="iso_code", columns={"iso_code"}),
* @ORM\Index(name="is_active", columns={"is_active"}),
* @ORM\Index(name="deleted_at", columns={"deleted_at"}),
* @ORM\Index(name="created_at", columns={"created_at"}),
* @ORM\Index(name="updated_at", columns={"updated_at"})
* })
* @Gedmo\SoftDeleteable(fieldName="deletedAt", timeAware=false, hardDelete=false)
*/
class CountryState implements \JsonSerializable
{
use UserTimestampableEntity;
use UserSoftDeleteableEntity;
use IsActiveEntity;
/**
* @ORM\Id
* @ORM\Column(type="uuid")
* @ORM\GeneratedValue(strategy="CUSTOM")
* @ORM\CustomIdGenerator(class=UuidGenerator::class)
*/
private ?Uuid $id = null;
/**
* @ORM\Column(type="string", length=64)
*/
private string $name;
/**
* @ORM\Column(type="string", length=7, nullable=true)
*/
private ?string $iso_code;
/**
* @ORM\ManyToOne(targetEntity=Country::class, inversedBy="countryStates")
* @ORM\JoinColumn(nullable=false)
*/
private Country $country;
/**
* @ORM\OneToMany(targetEntity=Context::class, mappedBy="country_state", fetch="EXTRA_LAZY")
*/
private Collection $contexts;
public function __construct()
{
$this->contexts = new ArrayCollection();
}
/**
* @return Uuid|null
*/
public function getId(): ?Uuid
{
return $this->id;
}
/**
* @return string
*/
public function getName(): string
{
return $this->name;
}
/**
* @param string $name
* @return $this
*/
public function setName(string $name): self
{
$this->name = $name;
return $this;
}
/**
* @return string|null
*/
public function getIsoCode(): ?string
{
return $this->iso_code;
}
/**
* @param string|null $iso_code
* @return $this
*/
public function setIsoCode(?string $iso_code): self
{
$this->iso_code = $iso_code;
return $this;
}
/**
* @return Country
*/
public function getCountry(): Country
{
return $this->country;
}
/**
* @param Country $country
* @return $this
*/
public function setCountry(Country $country): self
{
$this->country = $country;
return $this;
}
/**
* @return Collection|Context[]
*/
public function getContexts(): Collection
{
return $this->contexts;
}
/**
* @param Context $context
* @return $this
*/
public function addContext(Context $context): self
{
if (!$this->contexts->contains($context)) {
$this->contexts[] = $context;
$context->setCountryState($this);
}
return $this;
}
/**
* @return mixed
*/
#[\ReturnTypeWillChange]
public function jsonSerialize()
{
return [
'id' => $this->id,
'name' => $this->name,
'iso_code' => $this->iso_code,
'country' => $this->country
];
}
}