src/Entity/Broker.php line 86

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\Common\Collections\ArrayCollection;
  11. use Doctrine\Common\Collections\Collection;
  12. use Doctrine\ORM\Mapping as ORM;
  13. use Symfony\Component\Validator\Constraints as Assert;
  14. use Symfony\Component\Serializer\Annotation\Groups;
  15. use Symfony\Component\Serializer\Annotation\MaxDepth;
  16. /**
  17.  * An organization such as a school, NGO, corporation, club, etc.
  18.  *
  19.  * @see https://schema.org/Organization
  20.  *
  21.  * @author Jordi Fernandes Alves <jfadev@gmail.com>
  22.  */
  23. #[ORM\Entity]
  24. #[ApiResource(
  25.     iri'Broker',
  26.     itemOperations: [
  27.         'get' => [
  28.             // 'security' => "is_granted('ROLE_USER')",
  29.             'normalization_context' => [
  30.                 'groups' => 'broker:item:get',
  31.                 'enable_max_depth' => true
  32.             ]
  33.         ],
  34.         'put' => [
  35.             // 'security' => "is_granted('ROLE_USER')",
  36.             'normalization_context' => [
  37.                 'groups' => 'broker:item:put',
  38.                 'enable_max_depth' => true
  39.             ],
  40.             'denormalization_context' => [
  41.                 'groups' => 'broker:item:put',
  42.                 'enable_max_depth' => true
  43.             ]
  44.         ],
  45.         'delete' => [
  46.             // 'security' => "is_granted('ROLE_USER')",
  47.         ]
  48.     ],
  49.     collectionOperations: [
  50.         'get' => [
  51.             // 'security' => "is_granted('ROLE_USER')",
  52.             'normalization_context' => [
  53.                 'groups' => ['broker:collection:get''createdAt'],
  54.                 'enable_max_depth' => true
  55.             ]
  56.         ],
  57.         'post' => [
  58.             // 'security' => "is_granted('ROLE_USER')",
  59.             'normalization_context' => [
  60.                 'groups' => 'broker:collection:post',
  61.                 'enable_max_depth' => true
  62.             ],
  63.             'denormalization_context' => [
  64.                 'groups' => 'broker:collection:post',
  65.                 'enable_max_depth' => true
  66.             ]
  67.         ],
  68.     ]
  69. )]
  70. #[ApiFilter(SearchFilter::class, properties: [
  71.     'taxID' => 'start',
  72.     'name' => 'partial',
  73.     'legalName' => 'partial',
  74.     'createdAt' => 'start',
  75. ])]
  76. #[ApiFilter(OrderFilter::class, properties: [
  77.     'name',
  78.     'taxID',
  79.     'legalName',
  80.     'createdAt'
  81. ])]
  82. class Broker
  83. {
  84.     use TimestampableEntity;
  85.     
  86.     #[ORM\Id]
  87.     #[ORM\GeneratedValue(strategy'AUTO')]
  88.     #[ORM\Column(type'integer')]
  89.     #[Groups([
  90.         'broker:collection:get',
  91.         'broker:item:get',
  92.         'user:collection:post',
  93.         'user:item:put',
  94.         'channel:item:get',
  95.         'channel:item:put',
  96.         'insured:item:put',
  97.     ])]
  98.     private ?int $id null;
  99.     /**
  100.      * The name of the item.
  101.      *
  102.      * @see https://schema.org/name
  103.      */
  104.     #[ORM\Column(type'string')]
  105.     #[ApiProperty(iri'https://schema.org/name')]
  106.     #[Assert\Type('string')]
  107.     #[Groups([
  108.         'broker:collection:get',
  109.         'broker:collection:post',
  110.         'broker:item:get',
  111.         'broker:item:put',
  112.         'user:item:get',
  113.         'channel:item:get',
  114.         'channel:collection:get',
  115.         'insured:item:get',
  116.     ])]
  117.     private ?string $name null;
  118.     /**
  119.      * Email address.
  120.      *
  121.      * @see https://schema.org/email
  122.      */
  123.     #[ORM\Column(type'string')]
  124.     #[ApiProperty(iri'https://schema.org/email')]
  125.     #[Assert\Email]
  126.     #[Groups([
  127.         'broker:collection:post',
  128.         'broker:item:get',
  129.         'broker:item:put',
  130.     ])]
  131.     private ?string $email null;
  132.     /**
  133.      * The official name of the organization, e.g. the registered company name.
  134.      *
  135.      * @see https://schema.org/legalName
  136.      */
  137.     #[ORM\Column(type'string')]
  138.     #[ApiProperty(iri'https://schema.org/legalName')]
  139.     #[Assert\Type('string')]
  140.     #[Groups([
  141.         'broker:collection:get',
  142.         'broker:collection:post',
  143.         'broker:item:get',
  144.         'broker:item:put',
  145.     ])]
  146.     private ?string $legalName null;
  147.     /**
  148.      * The Tax / Fiscal ID of the organization or person, e.g. the TIN in the US or the CIF/NIF in Spain.
  149.      *
  150.      * @see https://schema.org/taxID
  151.      */
  152.     #[ORM\Column(type'string')]
  153.     #[ApiProperty(iri'https://schema.org/taxID')]
  154.     #[Assert\Type('string')]
  155.     #[Groups([
  156.         'broker:collection:get',
  157.         'broker:collection:post',
  158.         'broker:item:get',
  159.         'broker:item:put',
  160.         'user:item:get',
  161.         'channel:item:get',
  162.         'channel:collection:get',
  163.         'insured:item:get',
  164.     ])]
  165.     private ?string $taxID null;
  166.     /**
  167.      * The telephone number.
  168.      *
  169.      * @see https://schema.org/telephone
  170.      */
  171.     #[ORM\Column(type'string'nullabletrue)]
  172.     #[ApiProperty(iri'https://schema.org/telephone')]
  173.     #[Assert\Type('string')]
  174.     #[Groups([
  175.         'broker:collection:post',
  176.         'broker:item:get',
  177.         'broker:item:put',
  178.     ])]
  179.     private ?string $telephone null;
  180.     #[ORM\OneToMany(mappedBy'broker'targetEntityBrokerUser::class)]
  181.     #[Groups([
  182.         'broker:item:get',
  183.     ])]
  184.     #[MaxDepth(1)]
  185.     private $users;
  186.     #[ORM\OneToMany(mappedBy'broker'targetEntityChannel::class)]
  187.     #[Groups([
  188.         'broker:item:get',
  189.     ])]
  190.     #[MaxDepth(1)]
  191.     private $channels;
  192.     #[ORM\OneToMany(mappedBy'broker'targetEntityInsured::class)]
  193.     #[Groups([
  194.         'broker:item:get',
  195.     ])]
  196.     #[MaxDepth(1)]
  197.     private $insureds;
  198.     public function __construct()
  199.     {
  200.         $this->users = new ArrayCollection();
  201.         $this->channels = new ArrayCollection();
  202.         $this->insureds = new ArrayCollection();
  203.     }
  204.     public function getId(): ?int
  205.     {
  206.         return $this->id;
  207.     }
  208.     public function setName(?string $name): void
  209.     {
  210.         $this->name $name;
  211.     }
  212.     public function getName(): ?string
  213.     {
  214.         return $this->name;
  215.     }
  216.     public function setEmail(?string $email): void
  217.     {
  218.         $this->email $email;
  219.     }
  220.     public function getEmail(): ?string
  221.     {
  222.         return $this->email;
  223.     }
  224.     public function setLegalName(?string $legalName): void
  225.     {
  226.         $this->legalName $legalName;
  227.     }
  228.     public function getLegalName(): ?string
  229.     {
  230.         return $this->legalName;
  231.     }
  232.     public function setTaxID(?string $taxID): void
  233.     {
  234.         $this->taxID $taxID;
  235.     }
  236.     public function getTaxID(): ?string
  237.     {
  238.         return $this->taxID;
  239.     }
  240.     public function setTelephone(?string $telephone): void
  241.     {
  242.         $this->telephone $telephone;
  243.     }
  244.     public function getTelephone(): ?string
  245.     {
  246.         return $this->telephone;
  247.     }
  248.     /**
  249.      * @return Collection|BrokerUser[]
  250.      */
  251.     public function getUsers(): Collection
  252.     {
  253.         return $this->users;
  254.     }
  255.     public function addUser(BrokerUser $user): self
  256.     {
  257.         if (!$this->users->contains($user)) {
  258.             $this->users[] = $user;
  259.             $user->setBroker($this);
  260.         }
  261.         return $this;
  262.     }
  263.     public function removeUser(BrokerUser $user): self
  264.     {
  265.         if ($this->users->removeElement($user)) {
  266.             // set the owning side to null (unless already changed)
  267.             if ($user->getBroker() === $this) {
  268.                 $user->setBroker(null);
  269.             }
  270.         }
  271.         return $this;
  272.     }
  273.     /**
  274.      * @return Collection|Channel[]
  275.      */
  276.     public function getChannels(): Collection
  277.     {
  278.         return $this->channels;
  279.     }
  280.     public function addChannel(Channel $channel): self
  281.     {
  282.         if (!$this->channels->contains($channel)) {
  283.             $this->channels[] = $channel;
  284.             $channel->setBroker($this);
  285.         }
  286.         return $this;
  287.     }
  288.     public function removeChannel(Channel $channel): self
  289.     {
  290.         if ($this->channels->removeElement($channel)) {
  291.             // set the owning side to null (unless already changed)
  292.             if ($channel->getBroker() === $this) {
  293.                 $channel->setBroker(null);
  294.             }
  295.         }
  296.         return $this;
  297.     }
  298.     /**
  299.      * @return Collection|Insured[]
  300.      */
  301.     public function getInsureds(): Collection
  302.     {
  303.         return $this->insureds;
  304.     }
  305.     public function addInsured(Insured $insured): self
  306.     {
  307.         if (!$this->insureds->contains($insured)) {
  308.             $this->insureds[] = $insured;
  309.             $insured->setBroker($this);
  310.         }
  311.         return $this;
  312.     }
  313.     public function removeInsured(Insured $insured): self
  314.     {
  315.         if ($this->insureds->removeElement($insured)) {
  316.             // set the owning side to null (unless already changed)
  317.             if ($insured->getBroker() === $this) {
  318.                 $insured->setBroker(null);
  319.             }
  320.         }
  321.         return $this;
  322.     }
  323. }