src/Evo/Infrastructure/MappingORM/Mandatary.php line 21

Open in your IDE?
  1. <?php
  2. namespace Evo\Infrastructure\MappingORM;
  3. use ApiPlatform\Core\Annotation\ApiResource;
  4. use Doctrine\ORM\Mapping as ORM;
  5. use Gedmo\Mapping\Annotation as Gedmo;
  6. use Symfony\Component\Serializer\Annotation\Groups;
  7. /**
  8.  * @ApiResource(attributes={
  9.  *     "normalization_context"={"groups"={"read_mandatary"}, "enable_max_depth"=true},
  10.  *     "denormalization_context"={"groups"={"write_mandatary"}}
  11.  * }, itemOperations={
  12.  *     "get",
  13.  *     "put",
  14.  *     "delete"={"security"="is_granted('ROLE_ADMIN')"}
  15.  * })
  16.  * @ORM\Entity(repositoryClass="App\Repository\MandataryRepository")
  17.  */
  18. class Mandatary
  19. {
  20.     /**
  21.      * @Groups({"read_mandatary", "read_organization"})
  22.      * @ORM\Id()
  23.      * @ORM\GeneratedValue()
  24.      * @ORM\Column(type="integer")
  25.      */
  26.     private ?int $id null;
  27.     /**
  28.      * @Groups({"read_mandatary", "write_mandatary", "read_organization", "write_organization", "read_search"})
  29.      * @ORM\OneToOne(targetEntity="Evo\Infrastructure\MappingORM\Person", cascade={"persist"})
  30.      */
  31.     private ?Person $person null;
  32.     /**
  33.      * @Groups({"read_mandatary", "write_mandatary", "read_organization"})
  34.      * @ORM\ManyToOne(targetEntity="Evo\Infrastructure\MappingORM\Organization", inversedBy="mandataries")
  35.      * @ORM\JoinColumn(nullable=true)
  36.      */
  37.     private ?Organization $organization null;
  38.     /**
  39.      * @Groups({"read_mandatary", "read_organization"})
  40.      * @ORM\Column(name="created_at", type="datetime", nullable=true)
  41.      */
  42.     private $createdAt;
  43.     /**
  44.      * @Groups({"read_mandatary", "read_organization"})
  45.      * @Gedmo\Timestampable(on="update")
  46.      * @ORM\Column(type="datetime", options={"default": "CURRENT_TIMESTAMP"})
  47.      */
  48.     private ?\DateTimeInterface $updatedAt null;
  49.     public function __construct()
  50.     {
  51.         $this->createdAt = new \DateTime();
  52.     }
  53.     public function getId(): ?int
  54.     {
  55.         return $this->id;
  56.     }
  57.     public function getPerson(): ?Person
  58.     {
  59.         return $this->person;
  60.     }
  61.     public function setPerson(?Person $person): self
  62.     {
  63.         $this->person $person;
  64.         return $this;
  65.     }
  66.     public function getOrganization(): ?Organization
  67.     {
  68.         return $this->organization;
  69.     }
  70.     public function setOrganization(?Organization $organization): self
  71.     {
  72.         $this->organization $organization;
  73.         return $this;
  74.     }
  75.     public function getCreatedAt(): ?\DateTimeInterface
  76.     {
  77.         return $this->createdAt;
  78.     }
  79.     public function setCreatedAt(?\DateTimeInterface $createdAt): self
  80.     {
  81.         $this->createdAt $createdAt;
  82.         return $this;
  83.     }
  84.     public function getUpdatedAt(): ?\DateTimeInterface
  85.     {
  86.         return $this->updatedAt;
  87.     }
  88.     public function setUpdatedAt(?\DateTimeInterface $updatedAt): self
  89.     {
  90.         $this->updatedAt $updatedAt;
  91.         return $this;
  92.     }
  93.     public function __toString()
  94.     {
  95.         return $this->getPerson()->getGivenName().' '.$this->getPerson()->getFamilyName();
  96.     }
  97.     public static function createFixture(array $data): Mandatary
  98.     {
  99.         $self = new self();
  100.         $self->person Person::createFixture($data);
  101.         return $self;
  102.     }
  103. }