src/Entity/Channel.php line 88

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'Channel',
  26.     itemOperations: [
  27.         'get' => [
  28.             // 'security' => "is_granted('ROLE_USER')",
  29.             'normalization_context' => [
  30.                 'groups' => 'channel:item:get',
  31.                 'enable_max_depth' => true
  32.             ]
  33.         ],
  34.         'put' => [
  35.             // 'security' => "is_granted('ROLE_USER')",
  36.             'normalization_context' => [
  37.                 'groups' => 'channel:item:put',
  38.                 'enable_max_depth' => true
  39.             ],
  40.             'denormalization_context' => [
  41.                 'groups' => 'channel: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' => ['channel:collection:get''createdAt'],
  54.                 'enable_max_depth' => true
  55.             ]
  56.         ],
  57.         'post' => [
  58.             // 'security' => "is_granted('ROLE_USER')",
  59.             'normalization_context' => [
  60.                 'groups' => 'channel:collection:post',
  61.                 'enable_max_depth' => true
  62.             ],
  63.             'denormalization_context' => [
  64.                 'groups' => 'channel: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.     'type' => 'exact',
  76.     'broker' => 'exact'
  77. ])]
  78. #[ApiFilter(OrderFilter::class, properties: [
  79.     'name',
  80.     'taxID',
  81.     'legalName',
  82.     'createdAt'
  83. ])]
  84. class Channel
  85. {
  86.     use TimestampableEntity;
  87.     
  88.     #[ORM\Id]
  89.     #[ORM\GeneratedValue(strategy'AUTO')]
  90.     #[ORM\Column(type'integer')]
  91.     #[Groups([
  92.         'channel:collection:get',
  93.         'channel:item:get',
  94.         'user:collection:post',
  95.         'user:item:put',
  96.         'broker:item:get',
  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.         'channel:collection:get',
  109.         'channel:collection:post',
  110.         'channel:item:get',
  111.         'channel:item:put',
  112.         'user:item:get',
  113.         'broker:item:get',
  114.     ])]
  115.     private ?string $name null;
  116.     /**
  117.      * Email address.
  118.      *
  119.      * @see https://schema.org/email
  120.      */
  121.     #[ORM\Column(type'string')]
  122.     #[ApiProperty(iri'https://schema.org/email')]
  123.     #[Assert\Email]
  124.     #[Groups([
  125.         'channel:collection:post',
  126.         'channel:item:get',
  127.         'channel:item:put',
  128.     ])]
  129.     private ?string $email null;
  130.     /**
  131.      * The official name of the organization, e.g. the registered company name.
  132.      *
  133.      * @see https://schema.org/legalName
  134.      */
  135.     #[ORM\Column(type'string')]
  136.     #[ApiProperty(iri'https://schema.org/legalName')]
  137.     #[Assert\Type('string')]
  138.     #[Groups([
  139.         'channel:collection:get',
  140.         'channel:collection:post',
  141.         'channel:item:get',
  142.         'channel:item:put',
  143.     ])]
  144.     private ?string $legalName null;
  145.     #[ORM\Column(type'string'nullabletrue)]
  146.     #[ApiProperty()]
  147.     #[Assert\Type('string')]
  148.     #[Groups([
  149.         'channel:collection:get',
  150.         'channel:collection:post',
  151.         'channel:item:get',
  152.         'channel:item:put',
  153.     ])]
  154.     private ?string $taxIDType null;
  155.     
  156.     /**
  157.      * The Tax / Fiscal ID of the organization or person, e.g. the TIN in the US or the CIF/NIF in Spain.
  158.      *
  159.      * @see https://schema.org/taxID
  160.      */
  161.     #[ORM\Column(type'string')]
  162.     #[ApiProperty(iri'https://schema.org/taxID')]
  163.     #[Assert\Type('string')]
  164.     #[Groups([
  165.         'channel:collection:get',
  166.         'channel:collection:post',
  167.         'channel:item:get',
  168.         'channel:item:put',
  169.         'user:item:get',
  170.         'broker:item:get',
  171.     ])]
  172.     private ?string $taxID null;
  173.     /**
  174.      * The telephone number.
  175.      *
  176.      * @see https://schema.org/telephone
  177.      */
  178.     #[ORM\Column(type'string'nullabletrue)]
  179.     #[ApiProperty(iri'https://schema.org/telephone')]
  180.     #[Assert\Type('string')]
  181.     #[Groups([
  182.         'channel:collection:post',
  183.         'channel:item:get',
  184.         'channel:item:put',
  185.     ])]
  186.     private ?string $telephone null;
  187.     #[ORM\Column(type'string')]
  188.     #[ApiProperty(iri'https://schema.org/Text')]
  189.     #[Assert\Type('string')]
  190.     #[Groups([
  191.         'channel:collection:get',
  192.         'channel:collection:post',
  193.         'channel:item:get',
  194.         'channel:item:put',
  195.         'user:item:get',
  196.         'broker:item:get',
  197.     ])]
  198.     private ?string $type null;
  199.     #[ORM\OneToMany(mappedBy'channel'targetEntityChannelUser::class)]
  200.     #[Groups([
  201.         'channel:item:get',
  202.     ])]
  203.     #[MaxDepth(1)]
  204.     private $users;
  205.     #[ORM\ManyToOne(targetEntityBroker::class, inversedBy'channels')]
  206.     #[ApiProperty()]
  207.     #[Groups([
  208.         'channel:collection:get',
  209.         'channel:collection:post',
  210.         'channel:item:get',
  211.         'channel:item:put',
  212.     ])]
  213.     #[MaxDepth(1)]
  214.     private $broker;
  215.     public function __construct()
  216.     {
  217.         $this->users = new ArrayCollection();
  218.     }
  219.     public function getId(): ?int
  220.     {
  221.         return $this->id;
  222.     }
  223.     public function setName(?string $name): void
  224.     {
  225.         $this->name $name;
  226.     }
  227.     public function getName(): ?string
  228.     {
  229.         return $this->name;
  230.     }
  231.     public function setEmail(?string $email): void
  232.     {
  233.         $this->email $email;
  234.     }
  235.     public function getEmail(): ?string
  236.     {
  237.         return $this->email;
  238.     }
  239.     public function setLegalName(?string $legalName): void
  240.     {
  241.         $this->legalName $legalName;
  242.     }
  243.     public function getLegalName(): ?string
  244.     {
  245.         return $this->legalName;
  246.     }
  247.     public function setTaxID(?string $taxID): void
  248.     {
  249.         $this->taxID $taxID;
  250.     }
  251.     public function getTaxID(): ?string
  252.     {
  253.         return $this->taxID;
  254.     }
  255.     public function setTaxIDType(?string $taxIDType): void
  256.     {
  257.         $this->taxIDType $taxIDType;
  258.     }
  259.     public function getTaxIDType(): ?string
  260.     {
  261.         return $this->taxIDType;
  262.     }
  263.     public function setTelephone(?string $telephone): void
  264.     {
  265.         $this->telephone $telephone;
  266.     }
  267.     public function getTelephone(): ?string
  268.     {
  269.         return $this->telephone;
  270.     }
  271.     /**
  272.      * @return Collection|ChannelUser[]
  273.      */
  274.     public function getUsers(): Collection
  275.     {
  276.         return $this->users;
  277.     }
  278.     public function addUser(ChannelUser $user): self
  279.     {
  280.         if (!$this->users->contains($user)) {
  281.             $this->users[] = $user;
  282.             $user->setChannel($this);
  283.         }
  284.         return $this;
  285.     }
  286.     public function removeUser(ChannelUser $user): self
  287.     {
  288.         if ($this->users->removeElement($user)) {
  289.             // set the owning side to null (unless already changed)
  290.             if ($user->getChannel() === $this) {
  291.                 $user->setChannel(null);
  292.             }
  293.         }
  294.         return $this;
  295.     }
  296.     public function getBroker(): ?Broker
  297.     {
  298.         return $this->broker;
  299.     }
  300.     public function setBroker(?Broker $broker): self
  301.     {
  302.         $this->broker $broker;
  303.         return $this;
  304.     }
  305.     /**
  306.      * @param string|null $type
  307.      */
  308.     public function setType(?string $type): void
  309.     {
  310.         $this->type $type;
  311.     }
  312.     public function getType(): ?string
  313.     {
  314.         return $this->type;
  315.     }
  316. }