<?php
namespace Evo\Infrastructure\MappingORM;
use ApiPlatform\Core\Annotation\ApiResource;
use Doctrine\ORM\Mapping as ORM;
use Gedmo\Mapping\Annotation as Gedmo;
use Symfony\Component\Serializer\Annotation\Groups;
/**
* @ApiResource(attributes={
* "normalization_context"={"groups"={"read_mandatary"}, "enable_max_depth"=true},
* "denormalization_context"={"groups"={"write_mandatary"}}
* }, itemOperations={
* "get",
* "put",
* "delete"={"security"="is_granted('ROLE_ADMIN')"}
* })
* @ORM\Entity(repositoryClass="App\Repository\MandataryRepository")
*/
class Mandatary
{
/**
* @Groups({"read_mandatary", "read_organization"})
* @ORM\Id()
* @ORM\GeneratedValue()
* @ORM\Column(type="integer")
*/
private ?int $id = null;
/**
* @Groups({"read_mandatary", "write_mandatary", "read_organization", "write_organization", "read_search"})
* @ORM\OneToOne(targetEntity="Evo\Infrastructure\MappingORM\Person", cascade={"persist"})
*/
private ?Person $person = null;
/**
* @Groups({"read_mandatary", "write_mandatary", "read_organization"})
* @ORM\ManyToOne(targetEntity="Evo\Infrastructure\MappingORM\Organization", inversedBy="mandataries")
* @ORM\JoinColumn(nullable=true)
*/
private ?Organization $organization = null;
/**
* @Groups({"read_mandatary", "read_organization"})
* @ORM\Column(name="created_at", type="datetime", nullable=true)
*/
private $createdAt;
/**
* @Groups({"read_mandatary", "read_organization"})
* @Gedmo\Timestampable(on="update")
* @ORM\Column(type="datetime", options={"default": "CURRENT_TIMESTAMP"})
*/
private ?\DateTimeInterface $updatedAt = null;
public function __construct()
{
$this->createdAt = new \DateTime();
}
public function getId(): ?int
{
return $this->id;
}
public function getPerson(): ?Person
{
return $this->person;
}
public function setPerson(?Person $person): self
{
$this->person = $person;
return $this;
}
public function getOrganization(): ?Organization
{
return $this->organization;
}
public function setOrganization(?Organization $organization): self
{
$this->organization = $organization;
return $this;
}
public function getCreatedAt(): ?\DateTimeInterface
{
return $this->createdAt;
}
public function setCreatedAt(?\DateTimeInterface $createdAt): self
{
$this->createdAt = $createdAt;
return $this;
}
public function getUpdatedAt(): ?\DateTimeInterface
{
return $this->updatedAt;
}
public function setUpdatedAt(?\DateTimeInterface $updatedAt): self
{
$this->updatedAt = $updatedAt;
return $this;
}
public function __toString()
{
return $this->getPerson()->getGivenName().' '.$this->getPerson()->getFamilyName();
}
public static function createFixture(array $data): Mandatary
{
$self = new self();
$self->person = Person::createFixture($data);
return $self;
}
}