src/Entity/Broker.php line 58

Open in your IDE?
  1. <?php
  2. // @deprecated
  3. declare(strict_types=1);
  4. namespace App\Entity;
  5. use ApiPlatform\Core\Annotation\ApiFilter;
  6. use ApiPlatform\Core\Annotation\ApiProperty;
  7. use ApiPlatform\Core\Annotation\ApiResource;
  8. use ApiPlatform\Core\Bridge\Doctrine\Orm\Filter\OrderFilter;
  9. use ApiPlatform\Core\Bridge\Doctrine\Orm\Filter\SearchFilter;
  10. use App\Trait\TimestampableEntity;
  11. use Doctrine\Common\Collections\ArrayCollection;
  12. use Doctrine\Common\Collections\Collection;
  13. use Doctrine\ORM\Mapping as ORM;
  14. use Ramsey\Uuid\Uuid;
  15. use Ramsey\Uuid\UuidInterface;
  16. use Symfony\Component\Serializer\Annotation\Groups;
  17. use Symfony\Component\Serializer\Annotation\MaxDepth;
  18. use Symfony\Component\Validator\Constraints as Assert;
  19. /**
  20.  * @see https://schema.org/Organization
  21.  *
  22.  * @author Jordi Fernandes Alves <jfadev@gmail.com>
  23.  */
  24. #[ORM\Entity]
  25. #[ApiResource(
  26.     iri'Broker',
  27.     itemOperations: [
  28.         'get' => ['normalization_context' => ['groups' => 'broker:item:get''enable_max_depth' => true]],
  29.         'put' => [
  30.             'normalization_context' => ['groups' => 'broker:item:put''enable_max_depth' => true],
  31.             'denormalization_context' => ['groups' => 'broker:item:put''enable_max_depth' => true],
  32.         ],
  33.         'delete' => [],
  34.     ],
  35.     collectionOperations: [
  36.         'get' => [
  37.             'normalization_context' => ['groups' => ['broker:collection:get''createdAt'], 'enable_max_depth' => true],
  38.         ],
  39.         'post' => [
  40.             'normalization_context' => ['groups' => 'broker:collection:post''enable_max_depth' => true],
  41.             'denormalization_context' => ['groups' => 'broker:collection:post''enable_max_depth' => true],
  42.         ],
  43.     ],
  44. )]
  45. #[ApiFilter(
  46.     SearchFilter::class,
  47.     properties: ['companyName' => 'partial''createdAt' => 'start'],
  48. )]
  49. #[ApiFilter(
  50.     OrderFilter::class,
  51.     properties: ['companyName''createdAt'],
  52. )]
  53. class Broker
  54. {
  55.     use TimestampableEntity;
  56.     #[ORM\Id]
  57.     #[ORM\GeneratedValue(strategy'NONE')]
  58.     #[ORM\Column(type'uuid'uniquetrue)]
  59.     private ?UuidInterface $id null;
  60.     #[ORM\Column(type'string'nullablefalse)]
  61.     #[ApiProperty(iri'https://schema.org/name')]
  62.     #[Assert\NotBlank]
  63.     #[Assert\Type('string')]
  64.     #[Groups(['broker:collection:get''broker:collection:post''broker:item:get''broker:item:put''contract:collection:get'])]
  65.     private ?string $companyName null;
  66.     #[ORM\Column(type'string'nullablefalse)]
  67.     #[ApiProperty(iri'https://schema.org/desk')]
  68.     #[Assert\NotBlank]
  69.     #[Assert\Type('string')]
  70.     #[Groups(['broker:collection:get''broker:collection:post''broker:item:get''broker:item:put'])]
  71.     private ?string $desk null;
  72.     #[ORM\ManyToMany(targetEntity'App\Entity\Contact')]
  73.     #[ApiProperty(iri'https://schema.org/Contact')]
  74.     #[Groups(['broker:collection:get''broker:collection:post''broker:item:get''broker:item:put'])]
  75.     private Collection $contacts;
  76.     #[ORM\OneToOne(targetEntity'App\Entity\Contact')]
  77.     #[ApiProperty(iri'https://schema.org/Contact')]
  78.     #[Groups(['broker:collection:get''broker:collection:post''broker:item:get''broker:item:put'])]
  79.     private ?Contact $primaryContact null;
  80.     #[ORM\ManyToMany(targetEntity'App\Entity\Contract')]
  81.     #[ORM\InverseJoinColumn(uniquetrue)]
  82.     #[ApiProperty(iri'https://schema.org/Contract')]
  83.     #[Groups(['broker:collection:get''broker:collection:post''broker:item:get''broker:item:put'])]
  84.     private ?Collection $contracts null;
  85.     public function __construct()
  86.     {
  87.         $this->id Uuid::uuid4();
  88.         $this->contacts = new ArrayCollection();
  89.         $this->contracts = new ArrayCollection();
  90.     }
  91.     public function getId(): ?UuidInterface
  92.     {
  93.         return $this->id;
  94.     }
  95.     public function setCompanyName(?string $companyName): void
  96.     {
  97.         $this->companyName $companyName;
  98.     }
  99.     public function getCompanyName(): ?string
  100.     {
  101.         return $this->companyName;
  102.     }
  103.     public function setDesk(?string $desk): void
  104.     {
  105.         $this->desk $desk;
  106.     }
  107.     public function getDesk(): ?string
  108.     {
  109.         return $this->desk;
  110.     }
  111.     public function addContact(Contact $contact): void
  112.     {
  113.         if (!$this->contacts->contains($contact)) {
  114.             $this->contacts->add($contact);
  115.         }
  116.     }
  117.     public function removeContact(Contact $contact): void
  118.     {
  119.         $this->contacts->removeElement($contact);
  120.     }
  121.     public function getContacts(): Collection
  122.     {
  123.         return $this->contacts;
  124.     }
  125.     public function setPrimaryContact(?Contact $primaryContact): void
  126.     {
  127.         $this->primaryContact $primaryContact;
  128.     }
  129.     public function getPrimaryContact(): ?Contact
  130.     {
  131.         return $this->primaryContact;
  132.     }
  133.     public function addContract(Contract $contract): void
  134.     {
  135.         $this->contracts[] = $contract;
  136.     }
  137.     public function removeContract(Contract $contract): void
  138.     {
  139.         $this->contracts->removeElement($contract);
  140.     }
  141.     public function getContracts(): Collection
  142.     {
  143.         return $this->contracts;
  144.     }
  145. }