src/Entity/User.php line 87

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use ApiPlatform\Core\Annotation\ApiProperty;
  4. use ApiPlatform\Core\Annotation\ApiResource;
  5. use ApiPlatform\Core\Annotation\ApiFilter;
  6. use ApiPlatform\Core\Bridge\Doctrine\Orm\Filter\SearchFilter;
  7. use ApiPlatform\Core\Bridge\Doctrine\Orm\Filter\OrderFilter;
  8. use ApiPlatform\Core\Serializer\Filter\PropertyFilter;
  9. use App\Repository\UserRepository;
  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 Symfony\Component\Security\Core\User\PasswordAuthenticatedUserInterface;
  15. use Symfony\Component\Security\Core\User\UserInterface;
  16. use Symfony\Component\Validator\Constraints as Assert;
  17. use Symfony\Component\Serializer\Annotation\Groups;
  18. use Symfony\Component\Serializer\Annotation\MaxDepth;
  19. use Ramsey\Uuid\Uuid;
  20. use Ramsey\Uuid\UuidInterface;
  21. #[ORM\Entity(repositoryClassUserRepository::class)]
  22. #[ApiResource(
  23.     iri'User'
  24.     itemOperations: [
  25.         'get' => [
  26.             // 'security' => "is_granted('ROLE_USER')",
  27.             'normalization_context' => [
  28.                 'groups' => 'user:item:get',
  29.                 'enable_max_depth' => true
  30.             ]
  31.         ],
  32.         'put' => [
  33.             // 'security' => "is_granted('ROLE_USER')",
  34.             'normalization_context' => [
  35.                 'groups' => 'user:item:put',
  36.                 'enable_max_depth' => true
  37.             ],
  38.             'denormalization_context' => [
  39.                 'groups' => 'user:item:put',
  40.                 'enable_max_depth' => true
  41.             ]
  42.         ],
  43.         'delete' => [
  44.             // 'security' => "is_granted('ROLE_USER')",
  45.         ]
  46.     ],
  47.     collectionOperations: [
  48.         'get' => [
  49.             // 'security' => "is_granted('ROLE_USER')",
  50.             'normalization_context' => [
  51.                 'groups' => ['user:collection:get''createdAt'],
  52.                 'enable_max_depth' => true
  53.             ]
  54.         ],
  55.         'post' => [
  56.             // 'security' => "is_granted('ROLE_USER')",
  57.             'normalization_context' => [
  58.                 'groups' => 'user:collection:post',
  59.                 'enable_max_depth' => true
  60.             ],
  61.             'denormalization_context' => [
  62.                 'groups' => 'user:collection:post',
  63.                 'enable_max_depth' => true
  64.             ]
  65.         ],
  66.     ]
  67. )]
  68. #[ApiFilter(SearchFilter::class, properties: [
  69.     'brokers.broker' => 'exact'
  70.     'insureds.insured' => 'exact',
  71.     'insurers.insurer' => 'exact',
  72.     // 'channels.channel' => 'exact',
  73.     'roles' => 'partial',
  74.     'email' => 'partial',
  75.     'name' => 'partial',
  76.     'createdAt' => 'start',
  77. ])]
  78. #[ApiFilter(OrderFilter::class, properties: [
  79.     'name',
  80.     'email'
  81.     'createdAt',
  82. ])]
  83. #[ApiFilter(PropertyFilter::class)]
  84. class User implements UserInterfacePasswordAuthenticatedUserInterface
  85. {
  86.     use TimestampableEntity;
  87.     
  88.     #[ORM\Id]
  89.     #[ORM\GeneratedValue(strategy'NONE')]
  90.     #[ORM\Column(type'uuid'uniquetrue)]
  91.     #[ApiProperty(iri'https://schema.org/identifier')]
  92.     #[Groups([
  93.         'user:collection:get',
  94.         'user:item:get',
  95.     ])]
  96.     private ?UuidInterface $id null;
  97.     /**
  98.      * The name of the item.
  99.      *
  100.      * @see https://schema.org/name
  101.      */
  102.     #[ORM\Column(type'string'nullablefalse)]
  103.     #[ApiProperty(iri'https://schema.org/name')]
  104.     #[Assert\Type('string')]
  105.     #[Groups([
  106.         'user:collection:get',
  107.         'user:collection:post',
  108.         'user:item:get',
  109.         'user:item:put',
  110.         'contract:item:get'
  111.         'contract:item:put'
  112.         'contract:collection:get'
  113.         'contract:collection:post'
  114.     ])]
  115.     private ?string $name null;
  116.     #[ORM\Column(type'string'length180uniquetrue)]
  117.     #[ApiProperty(iri'https://schema.org/email')]
  118.     #[Groups([
  119.         'user:collection:get',
  120.         'user:collection:post',
  121.         'user:item:get',
  122.         'user:item:put',
  123.     ])]
  124.     private $email;
  125.     #[ORM\Column(type'json')]
  126.     #[ApiProperty()]
  127.     #[Groups([
  128.         'user:collection:get',
  129.         'user:collection:post',
  130.         'user:item:get',
  131.         'user:item:put',
  132.     ])]
  133.     private array $roles = [];
  134.     #[ORM\Column(type'string')]
  135.     private $password;
  136.     #[Groups([
  137.         'user:collection:post',
  138.         'user:item:put',
  139.     ])]
  140.     protected $plainPassword;
  141.     #[ORM\Column(type'string'length255nullabletrue)]
  142.     private $confirmationToken;
  143.     // #[ORM\OneToMany(mappedBy: 'user', targetEntity: BrokerUser::class, cascade: ['persist', 'remove'], orphanRemoval: true)]
  144.     // #[Groups([
  145.     //     'user:collection:post',
  146.     //     'user:item:get',
  147.     //     'user:item:put',
  148.     // ])]
  149.     // #[MaxDepth(1)]
  150.     // private $brokers;
  151.     // #[ORM\OneToMany(mappedBy: 'user', targetEntity: InsuredUser::class, cascade: ['persist', 'remove'], orphanRemoval: true)]
  152.     // #[Groups([
  153.     //     'user:collection:post',
  154.     //     'user:item:get',
  155.     //     'user:item:put',
  156.     // ])]
  157.     // #[MaxDepth(1)]
  158.     // private $insureds;
  159.     // #[ORM\OneToMany(mappedBy: 'user', targetEntity: InsurerUser::class, cascade: ['persist', 'remove'], orphanRemoval: true)]
  160.     // #[Groups([
  161.     //     'user:collection:post',
  162.     //     'user:item:get',
  163.     //     'user:item:put',
  164.     // ])]
  165.     // #[MaxDepth(1)]
  166.     // private $insurers;
  167.     // #[ORM\OneToMany(mappedBy: 'user', targetEntity: ChannelUser::class, cascade: ['persist', 'remove'], orphanRemoval: true)]
  168.     // #[Groups([
  169.     //     'user:collection:post',
  170.     //     'user:item:get',
  171.     //     'user:item:put',
  172.     // ])]
  173.     // #[MaxDepth(1)]
  174.     // private $channels;
  175.     #[ApiProperty(iri'https://schema.org/image')]
  176.     #[ORM\ManyToOne(targetEntityMedia::class, cascade: ["persist""remove"])]
  177.     #[ORM\JoinColumn(nullabletrue)]
  178.     #[Groups([
  179.         'user:collection:get',
  180.         'user:collection:post',
  181.         'user:item:get',
  182.         'user:item:put',
  183.     ])]
  184.     #[MaxDepth(1)]
  185.     private $avatar;
  186.     #[ORM\Column(type'string'nullabletrue)]
  187.     #[ApiProperty(iri'https://schema.org/desk')]
  188.     #[Assert\Type('string')]
  189.     #[Groups([
  190.         'user:collection:get',
  191.         'user:collection:post',
  192.         'user:item:get',
  193.         'user:item:put',
  194.     ])]
  195.     private ?string $desk null;
  196.     #[ORM\OneToMany(targetEntity'App\Entity\Contract'mappedBy'broker')]
  197.     #[ApiProperty(iri'https://schema.org/Contract')]
  198.     #[Groups(['user:collection:get''user:collection:post''user:item:get''user:item:put'])]
  199.     #[MaxDepth(1)]
  200.     private ?Collection $contracts null;
  201.     #[ORM\OneToMany(targetEntity'App\Entity\Contract'mappedBy'operator')]
  202.     #[ApiProperty(iri'https://schema.org/Contract')]
  203.     #[Groups(['user:collection:get''user:collection:post''user:item:get''user:item:put'])]
  204.     #[MaxDepth(1)]
  205.     private ?Collection $operations null;
  206.     // #[ORM\OneToMany(targetEntity: 'App\Entity\Lifting', mappedBy: 'operator')]
  207.     // #[ApiProperty(iri: 'https://schema.org/Lifting')]
  208.     // #[Groups(['user:collection:get', 'user:collection:post', 'user:item:get', 'user:item:put'])]
  209.     // #[MaxDepth(1)]
  210.     // private ?Collection $liftings = null;
  211.     public function __construct()
  212.     {
  213.         $this->id Uuid::uuid4();
  214.         // $this->brokers = new ArrayCollection();
  215.         // $this->insureds = new ArrayCollection();
  216.         // $this->insurers = new ArrayCollection();
  217.         // $this->channels = new ArrayCollection();
  218.         $this->contracts = new ArrayCollection();
  219.         $this->operations = new ArrayCollection();
  220.         // $this->liftings = new ArrayCollection();
  221.     }
  222.     public function getId(): ?UuidInterface
  223.     {
  224.         return $this->id;
  225.     }
  226.     public function setName(?string $name): void
  227.     {
  228.         $this->name $name;
  229.     }
  230.     public function getName(): ?string
  231.     {
  232.         return $this->name;
  233.     }
  234.     public function getEmail(): ?string
  235.     {
  236.         return $this->email;
  237.     }
  238.     public function setEmail(string $email): self
  239.     {
  240.         $this->email $email;
  241.         return $this;
  242.     }
  243.     /**
  244.      * A visual identifier that represents this user.
  245.      *
  246.      * @see UserInterface
  247.      */
  248.     public function getUserIdentifier(): string
  249.     {
  250.         return (string) $this->email;
  251.     }
  252.     /**
  253.      * @see UserInterface
  254.      */
  255.     public function getRoles(): array
  256.     {
  257.         $roles $this->roles;
  258.         // guarantee every user at least has ROLE_USER
  259.         $roles[] = 'ROLE_USER';
  260.         return array_unique($roles);
  261.     }
  262.     public function setRoles(array $roles): self
  263.     {
  264.         $this->roles $roles;
  265.         return $this;
  266.     }
  267.     /**
  268.      * @see PasswordAuthenticatedUserInterface
  269.      */
  270.     public function getPassword(): string
  271.     {
  272.         return $this->password;
  273.     }
  274.     public function setPassword(string $password): self
  275.     {
  276.         $this->password $password;
  277.         return $this;
  278.     }
  279.     public function getPlainPassword(): ?string
  280.     {
  281.         return $this->plainPassword;
  282.     }
  283.     public function setPlainPassword(?string $plainPassword): self
  284.     {
  285.         $this->plainPassword $plainPassword;
  286.         return $this;
  287.     }
  288.     /**
  289.      * @see UserInterface
  290.      */
  291.     public function eraseCredentials(): void
  292.     {
  293.         // If you store any temporary, sensitive data on the user, clear it here
  294.         // $this->plainPassword = null;
  295.     }
  296.     // /**
  297.     //  * @return Collection|BrokerUser[]
  298.     //  */
  299.     // public function getBrokers(): Collection
  300.     // {
  301.     //     return $this->brokers;
  302.     // }
  303.     // public function addBroker(BrokerUser $broker): self
  304.     // {
  305.     //     if (!$this->brokers->contains($broker)) {
  306.     //         $this->brokers[] = $broker;
  307.     //         $broker->setUser($this);
  308.     //     }
  309.     //     return $this;
  310.     // }
  311.     // public function removeBroker(BrokerUser $broker): self
  312.     // {
  313.     //     if ($this->brokers->removeElement($broker)) {
  314.     //         // set the owning side to null (unless already changed)
  315.     //         if ($broker->getUser() === $this) {
  316.     //             $broker->setUser(null);
  317.     //         }
  318.     //     }
  319.     //     return $this;
  320.     // }
  321.     // /**
  322.     //  * @return Collection|InsuredUser[]
  323.     //  */
  324.     // public function getInsureds(): Collection
  325.     // {
  326.     //     return $this->insureds;
  327.     // }
  328.     // public function addInsured(InsuredUser $insured): self
  329.     // {
  330.     //     if (!$this->insureds->contains($insured)) {
  331.     //         $this->insureds[] = $insured;
  332.     //         $insured->setUser($this);
  333.     //     }
  334.     //     return $this;
  335.     // }
  336.     // public function removeInsured(InsuredUser $insured): self
  337.     // {
  338.     //     if ($this->insureds->removeElement($insured)) {
  339.     //         // set the owning side to null (unless already changed)
  340.     //         if ($insured->getUser() === $this) {
  341.     //             $insured->setUser(null);
  342.     //         }
  343.     //     }
  344.     //     return $this;
  345.     // }
  346.     // /**
  347.     //  * @return Collection|InsurerUser[]
  348.     //  */
  349.     // public function getInsurers(): Collection
  350.     // {
  351.     //     return $this->insurers;
  352.     // }
  353.     // public function addInsurer(InsurerUser $insurer): self
  354.     // {
  355.     //     if (!$this->insurers->contains($insurer)) {
  356.     //         $this->insurers[] = $insurer;
  357.     //         $insurer->setUser($this);
  358.     //     }
  359.     //     return $this;
  360.     // }
  361.     // public function removeInsurer(InsurerUser $insurer): self
  362.     // {
  363.     //     if ($this->insurers->removeElement($insurer)) {
  364.     //         // set the owning side to null (unless already changed)
  365.     //         if ($insurer->getUser() === $this) {
  366.     //             $insurer->setUser(null);
  367.     //         }
  368.     //     }
  369.     //     return $this;
  370.     // }
  371.     public function getConfirmationToken(): ?string
  372.     {
  373.         return $this->confirmationToken;
  374.     }
  375.     public function setConfirmationToken(?string $confirmationToken): self
  376.     {
  377.         $this->confirmationToken $confirmationToken;
  378.         return $this;
  379.     }
  380.     // /**
  381.     //  * @return Collection|ChannelUser[]
  382.     //  */
  383.     // public function getChannels(): Collection
  384.     // {
  385.     //     return $this->channels;
  386.     // }
  387.     // public function addChannel(ChannelUser $channel): self
  388.     // {
  389.     //     if (!$this->channels->contains($channel)) {
  390.     //         $this->channels[] = $channel;
  391.     //         $channel->setUser($this);
  392.     //     }
  393.     //     return $this;
  394.     // }
  395.     // public function removeChannel(ChannelUser $channel): self
  396.     // {
  397.     //     if ($this->channels->removeElement($channel)) {
  398.     //         // set the owning side to null (unless already changed)
  399.     //         if ($channel->getUser() === $this) {
  400.     //             $channel->setUser(null);
  401.     //         }
  402.     //     }
  403.     //     return $this;
  404.     // }
  405.     public function setAvatar(?Media $avatar): self
  406.     {
  407.         $this->avatar $avatar;
  408.         return $this;
  409.     }
  410.     public function getAvatar(): ?Media
  411.     {
  412.         return $this->avatar;
  413.     }
  414.     public function setDesk(?string $desk): void
  415.     {
  416.         $this->desk $desk;
  417.     }
  418.     public function getDesk(): ?string
  419.     {
  420.         return $this->desk;
  421.     }
  422.     
  423.     public function getContracts(): Collection
  424.     {
  425.         return $this->contracts;
  426.     }
  427.     public function addContract(Contract $contract): self
  428.     {
  429.         if (!$this->contracts->contains($contract)) {
  430.             $this->contracts[] = $contract;
  431.             $contract->setBroker($this);
  432.         }
  433.         return $this;
  434.     }
  435.     public function removeContract(Contract $contract): self
  436.     {
  437.         if ($this->contracts->removeElement($contract)) {
  438.             if ($contract->getBroker() === $this) {
  439.                 $contract->setBroker(null);
  440.             }
  441.         }
  442.         return $this;
  443.     }
  444.     public function getOperations(): Collection
  445.     {
  446.         return $this->operations;
  447.     }
  448.     public function addOperation(Contract $operation): self
  449.     {
  450.         if (!$this->operations->contains($operation)) {
  451.             $this->operations[] = $operation;
  452.             $operation->setOperator($this);
  453.         }
  454.         return $this;
  455.     }
  456.     public function removeOperation(Contract $operation): self
  457.     {
  458.         if ($this->operations->removeElement($operation)) {
  459.             if ($operation->getOperator() === $this) {
  460.                 $operation->setOperator(null);
  461.             }
  462.         }
  463.         return $this;
  464.     }
  465.     // public function getLiftings(): Collection
  466.     // {
  467.     //     return $this->liftings;
  468.     // }
  469.     // public function addLifting(Lifting $lifting): self
  470.     // {
  471.     //     if (!$this->liftings->contains($lifting)) {
  472.     //         $this->liftings[] = $lifting;
  473.     //         $lifting->setOperator($this);
  474.     //     }
  475.     //     return $this;
  476.     // }
  477.     // public function removeLifting(Lifting $lifting): self
  478.     // {
  479.     //     if ($this->liftings->removeElement($lifting)) {
  480.     //         if ($lifting->getOperator() === $this) {
  481.     //             $lifting->setOperator(null);
  482.     //         }
  483.     //     }
  484.     //     return $this;
  485.     // }
  486. }