src/Entity/Contact.php line 61

Open in your IDE?
  1. <?php
  2. declare(strict_types=1);
  3. namespace App\Entity;
  4. use ApiPlatform\Core\Annotation\ApiProperty;
  5. use ApiPlatform\Core\Annotation\ApiResource;
  6. use ApiPlatform\Core\Annotation\ApiFilter;
  7. use ApiPlatform\Core\Bridge\Doctrine\Orm\Filter\SearchFilter;
  8. use ApiPlatform\Core\Bridge\Doctrine\Orm\Filter\OrderFilter;
  9. use App\Trait\TimestampableEntity;
  10. use Doctrine\ORM\Mapping as ORM;
  11. use Symfony\Component\Serializer\Annotation\Groups;
  12. use Symfony\Component\Validator\Constraints as Assert;
  13. use Symfony\Component\Serializer\Annotation\MaxDepth;
  14. use Ramsey\Uuid\Uuid;
  15. use Ramsey\Uuid\UuidInterface;
  16. /**
  17.  * Represents a contact person within an organization.
  18.  *
  19.  * @see https://schema.org/Person
  20.  * 
  21.  * @author Jordi Fernandes Alves <jfadev@gmail.com>
  22.  */
  23. #[ORM\Entity]
  24. #[ApiResource(
  25.     iri'Contact',
  26.     itemOperations: [
  27.         'get' => ['normalization_context' => ['groups' => 'contact:item:get''enable_max_depth' => true]],
  28.         'put' => [
  29.             'normalization_context' => ['groups' => 'contact:item:put''enable_max_depth' => true],
  30.             'denormalization_context' => ['groups' => 'contact:item:put''enable_max_depth' => true],
  31.         ],
  32.         'delete' => [],
  33.     ],
  34.     collectionOperations: [
  35.         'get' => [
  36.             'normalization_context' => [
  37.                 'groups' => ['contact:collection:get''createdAt'],
  38.                 'enable_max_depth' => true,
  39.             ],
  40.         ],
  41.         'post' => [
  42.             'normalization_context' => ['groups' => 'contact:collection:post''enable_max_depth' => true],
  43.             'denormalization_context' => ['groups' => 'contact:collection:post''enable_max_depth' => true],
  44.         ],
  45.     ],
  46. )]
  47. #[ApiFilter(SearchFilter::class, properties: [
  48.     'charterer' => 'exact',
  49.     'contactName' => 'partial',
  50.     'createdAt' => 'start',
  51. ])]
  52. #[ApiFilter(OrderFilter::class, properties: [
  53.     'contactName',
  54.     'createdAt'
  55. ])]
  56. class Contact
  57. {
  58.     use TimestampableEntity;
  59.     
  60.     #[ORM\Id]
  61.     #[ORM\GeneratedValue(strategy'NONE')]
  62.     #[ORM\Column(type'uuid'uniquetrue)]
  63.     // #[ApiProperty(iri: 'https://schema.org/identifier')]
  64.     private ?UuidInterface $id null;
  65.     #[ORM\Column(type'string'nullabletrue)]
  66.     #[ApiProperty(iri'https://schema.org/phoneNumber')]
  67.     #[Assert\Length(max255)]
  68.     #[Groups(['contact:collection:get''contact:collection:post''contact:item:get''contact:item:put''charterer:item:get'])]
  69.     private ?string $phoneNumbers null;
  70.     #[ORM\Column(type'text'nullabletrue)]
  71.     #[ApiProperty(iri'https://schema.org/email')]
  72.     ##[Assert\Email]
  73.     #[Groups(['contact:collection:get''contact:collection:post''contact:item:get''contact:item:put''charterer:item:get'])]
  74.     private ?string $emails null;
  75.     #[ORM\Column(type'string'nullablefalse)]
  76.     #[ApiProperty(iri'https://schema.org/name')]
  77.     #[Assert\NotBlank]
  78.     #[Assert\Type('string')]
  79.     #[Groups(['contact:collection:get''contact:collection:post''contact:item:get''contact:item:put''charterer:item:get'])]
  80.     private ?string $contactName null;
  81.     #[ORM\Column(type'string'nullablefalse)]
  82.     #[ApiProperty(iri'https://schema.org/position')]
  83.     #[Assert\NotBlank]
  84.     #[Assert\Type('string')]
  85.     #[Groups(['contact:collection:get''contact:collection:post''contact:item:get''contact:item:put''charterer:item:get'])]
  86.     private ?string $position null;
  87.     // #[ORM\ManyToOne(targetEntity: 'App\Entity\Charterer', inversedBy: 'contacts')]
  88.     // #[ORM\JoinColumn(nullable: true)]
  89.     // #[ApiProperty(iri: 'https://schema.org/charterer')]
  90.     // #[Groups(['contact:item:get', 'contact:item:put', 'contact:collection:get', 'contact:collection:post'])]
  91.     // #[MaxDepth(1)]
  92.     // private ?Charterer $charterer = null;
  93.     public function __construct()
  94.     {
  95.         $this->id Uuid::uuid4();
  96.     }
  97.     public function getId(): ?UuidInterface
  98.     {
  99.         return $this->id;
  100.     }
  101.     public function setPhoneNumbers(?string $phoneNumbers): void
  102.     {
  103.         $this->phoneNumbers $phoneNumbers;
  104.     }
  105.     public function getPhoneNumbers(): ?string
  106.     {
  107.         return $this->phoneNumbers;
  108.     }
  109.     public function setEmails(?string $emails): void
  110.     {
  111.         $this->emails $emails;
  112.     }
  113.     public function getEmails(): ?string
  114.     {
  115.         return $this->emails;
  116.     }
  117.     public function setContactName(?string $contactName): void
  118.     {
  119.         $this->contactName $contactName;
  120.     }
  121.     public function getContactName(): ?string
  122.     {
  123.         return $this->contactName;
  124.     }
  125.     public function setPosition(?string $position): void
  126.     {
  127.         $this->position $position;
  128.     }
  129.     public function getPosition(): ?string
  130.     {
  131.         return $this->position;
  132.     }
  133.     // public function setCharterer(?Charterer $charterer): void
  134.     // {
  135.     //     $this->charterer = $charterer;
  136.     // }
  137.     // public function getCharterer(): ?Charterer
  138.     // {
  139.     //     return $this->charterer;
  140.     // }
  141. }