src/Entity/User.php line 40

  1. <?php
  2. namespace App\Entity;
  3. use Doctrine\Common\Collections\ArrayCollection;
  4. use Doctrine\Common\Collections\Collection;
  5. use Symfony\Component\Uid\Ulid;
  6. use App\Controller\Auth\MeController;
  7. use Doctrine\ORM\Mapping as ORM;
  8. use App\Repository\UserRepository;
  9. use ApiPlatform\Core\Annotation\ApiResource;
  10. use Symfony\Component\Serializer\Annotation\Groups;
  11. use Symfony\Bridge\Doctrine\IdGenerator\UlidGenerator;
  12. use Symfony\Component\Security\Core\User\UserInterface;
  13. use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
  14. use Symfony\Component\Security\Core\User\PasswordAuthenticatedUserInterface;
  15. use Gedmo\Mapping\Annotation as Gedmo;
  16. #[ORM\Entity(repositoryClassUserRepository::class)]
  17. #[Gedmo\SoftDeleteable(fieldName'deletedAt'timeAwarefalsehardDeletetrue)]
  18. #[ORM\Table(name'`user`')]
  19. #[ORM\HasLifecycleCallbacks()]
  20. #[UniqueEntity(fields: ['email'], message'There is already an account with this email')]
  21. #[ApiResource(
  22.     normalizationContext: [
  23.         'groups' => ['read:user']
  24.     ],
  25.     collectionOperations: [],
  26.     itemOperations: [
  27.         'me' => [
  28.             'pagination_enabled' => false,
  29.             'path' => '/me',
  30.             'method' => 'get',
  31.             'requirements' => [],
  32.             'controller' => MeController::class,
  33.             'read' => false,
  34.         ]
  35.     ]
  36. )]
  37. class User implements UserInterfacePasswordAuthenticatedUserInterface
  38. {
  39.     use Timestamps;
  40.     #[ORM\Id]
  41.     #[ORM\Column(type'ulid'uniquetrue)]
  42.     #[ORM\GeneratedValue(strategy"CUSTOM")]
  43.     #[ORM\CustomIdGenerator(class: UlidGenerator::class)]
  44.     #[Groups(['read:user''read:user:profile'])]
  45.     private ?Ulid $id null;
  46.     #[ORM\Column(type'string'length180uniquetrue)]
  47.     #[Groups(['read:user'])]
  48.     private $email;
  49.     #[ORM\Column(type'json')]
  50.     #[Groups(['read:user'])]
  51.     private $roles = [];
  52.     #[ORM\Column(type'string')]
  53.     private $password;
  54.     #[ORM\Column(type'string'length255nullabletrue)]
  55.     #[Groups(['read:user'])]
  56.     private $first_name;
  57.     #[ORM\Column(type'string'length255nullabletrue)]
  58.     #[Groups(['read:user'])]
  59.     private $last_name;
  60.     #[ORM\Column(type'boolean')]
  61.     #[Groups(['read:user'])]
  62.     private $isVerified false;
  63.     #[ORM\ManyToOne(targetEntityCompany::class, inversedBy'users')]
  64.     private $company;
  65.     #[ORM\OneToMany(mappedBy'customer'targetEntityOrder::class, orphanRemovaltrue)]
  66.     private $orders;
  67.     #[ORM\OneToMany(mappedBy'created_by'targetEntitySubscription::class, orphanRemovaltrue)]
  68.     private $subscriptions;
  69.     #[ORM\OneToMany(mappedBy'created_by'targetEntityPayment::class, orphanRemovaltrue)]
  70.     private $payments;
  71.     #[ORM\OneToMany(mappedBy'created_by'targetEntityPost::class, orphanRemovaltrue)]
  72.     private $posts;
  73.     #[ORM\Column(type'string'length255nullabletrue)]
  74.     #[Groups(['read:user'])]
  75.     private $photo;
  76.     #[ORM\Column(type'string'length255nullabletrue)]
  77.     private $google_id;
  78.     #[ORM\Column(type'string'length255nullabletrue)]
  79.     private $facebook_id;
  80.     #[ORM\OneToMany(mappedBy'created_by'targetEntityPointing::class, orphanRemovaltrue)]
  81.     private $pointings;
  82.     #[ORM\OneToMany(mappedBy'created_by'targetEntityAbsenceEmployee::class, orphanRemovaltrue)]
  83.     private $absenceEmployees;
  84.     #[ORM\Column(type'datetime'nullabletrue)]
  85.     private $last_login;
  86.     #[ORM\OneToMany(mappedBy'made_by'targetEntityActivity::class)]
  87.     private Collection $activities;
  88.     #[ORM\Column(length255nullabletrue)]
  89.     private ?string $phone null;
  90.     #[ORM\Column(nullabletrue)]
  91.     private ?bool $isActive true;
  92.     public function __construct()
  93.     {
  94.         $this->orders = new ArrayCollection();
  95.         $this->subscriptions = new ArrayCollection();
  96.         $this->payments = new ArrayCollection();
  97.         $this->posts = new ArrayCollection();
  98.         $this->pointings = new ArrayCollection();
  99.         $this->absenceEmployees = new ArrayCollection();
  100.         $this->activities = new ArrayCollection();
  101.     }
  102.     public function __toString()
  103.     {
  104.         return $this->first_name " " $this->last_name;
  105.     }
  106.     public function getId(): ?Ulid
  107.     {
  108.         return $this->id;
  109.     }
  110.     public function getEmail(): ?string
  111.     {
  112.         return $this->email;
  113.     }
  114.     public function setEmail(string $email): self
  115.     {
  116.         $this->email $email;
  117.         return $this;
  118.     }
  119.     /**
  120.      * A visual identifier that represents this user.
  121.      *
  122.      * @see UserInterface
  123.      */
  124.     public function getUserIdentifier(): string
  125.     {
  126.         return (string) $this->email;
  127.     }
  128.     /**
  129.      * @see UserInterface
  130.      */
  131.     public function getRoles(): array
  132.     {
  133.         $roles $this->roles;
  134.         // guarantee every user at least has ROLE_USER
  135.         $roles[] = 'ROLE_USER';
  136.         return array_unique($roles);
  137.     }
  138.     public function setRoles(array $roles): self
  139.     {
  140.         $this->roles $roles;
  141.         return $this;
  142.     }
  143.     public function addRole(string $roles): self
  144.     {
  145.         $this->roles[] = $roles;
  146.         return $this;
  147.     }
  148.     /**
  149.      * @see PasswordAuthenticatedUserInterface
  150.      */
  151.     public function getPassword(): string
  152.     {
  153.         return $this->password;
  154.     }
  155.     public function setPassword(string $password): self
  156.     {
  157.         $this->password $password;
  158.         return $this;
  159.     }
  160.     /**
  161.      * @see UserInterface
  162.      */
  163.     public function eraseCredentials()
  164.     {
  165.         // If you store any temporary, sensitive data on the user, clear it here
  166.         // $this->plainPassword = null;
  167.     }
  168.     public function getFirstName(): ?string
  169.     {
  170.         return $this->first_name;
  171.     }
  172.     public function setFirstName(?string $first_name): self
  173.     {
  174.         $this->first_name $first_name;
  175.         return $this;
  176.     }
  177.     public function getLastName(): ?string
  178.     {
  179.         return $this->last_name;
  180.     }
  181.     public function setLastName(?string $last_name): self
  182.     {
  183.         $this->last_name $last_name;
  184.         return $this;
  185.     }
  186.     public function isVerified(): bool
  187.     {
  188.         return $this->isVerified;
  189.     }
  190.     public function setIsVerified(bool $isVerified): self
  191.     {
  192.         $this->isVerified $isVerified;
  193.         return $this;
  194.     }
  195.     public function getCompany(): ?Company
  196.     {
  197.         return $this->company;
  198.     }
  199.     public function setCompany(?Company $company): self
  200.     {
  201.         $this->company $company;
  202.         return $this;
  203.     }
  204.     // public function __toString() {
  205.     //     return $this->id;
  206.     // }
  207.     public function getIsVerified(): ?bool
  208.     {
  209.         return $this->isVerified;
  210.     }
  211.     /**
  212.      * @return Collection<int, Order>
  213.      */
  214.     public function getOrders(): Collection
  215.     {
  216.         return $this->orders;
  217.     }
  218.     public function addOrder(Order $order): self
  219.     {
  220.         if (!$this->orders->contains($order)) {
  221.             $this->orders[] = $order;
  222.             $order->setCustomer($this);
  223.         }
  224.         return $this;
  225.     }
  226.     public function removeOrder(Order $order): self
  227.     {
  228.         if ($this->orders->removeElement($order)) {
  229.             // set the owning side to null (unless already changed)
  230.             if ($order->getCustomer() === $this) {
  231.                 $order->setCustomer(null);
  232.             }
  233.         }
  234.         return $this;
  235.     }
  236.     /**
  237.      * @return Collection<int, Subscription>
  238.      */
  239.     public function getSubscriptions(): Collection
  240.     {
  241.         return $this->subscriptions;
  242.     }
  243.     public function addSubscription(Subscription $subscription): self
  244.     {
  245.         if (!$this->subscriptions->contains($subscription)) {
  246.             $this->subscriptions[] = $subscription;
  247.             $subscription->setCreatedBy($this);
  248.         }
  249.         return $this;
  250.     }
  251.     public function removeSubscription(Subscription $subscription): self
  252.     {
  253.         if ($this->subscriptions->removeElement($subscription)) {
  254.             // set the owning side to null (unless already changed)
  255.             if ($subscription->getCreatedBy() === $this) {
  256.                 $subscription->setCreatedBy(null);
  257.             }
  258.         }
  259.         return $this;
  260.     }
  261.     /**
  262.      * @return Collection<int, Payment>
  263.      */
  264.     public function getPayments(): Collection
  265.     {
  266.         return $this->payments;
  267.     }
  268.     public function addPayment(Payment $payment): self
  269.     {
  270.         if (!$this->payments->contains($payment)) {
  271.             $this->payments[] = $payment;
  272.             $payment->setCreatedBy($this);
  273.         }
  274.         return $this;
  275.     }
  276.     public function removePayment(Payment $payment): self
  277.     {
  278.         if ($this->payments->removeElement($payment)) {
  279.             // set the owning side to null (unless already changed)
  280.             if ($payment->getCreatedBy() === $this) {
  281.                 $payment->setCreatedBy(null);
  282.             }
  283.         }
  284.         return $this;
  285.     }
  286.     /**
  287.      * @return Collection<int, Post>
  288.      */
  289.     public function getPosts(): Collection
  290.     {
  291.         return $this->posts;
  292.     }
  293.     public function addPost(Post $post): self
  294.     {
  295.         if (!$this->posts->contains($post)) {
  296.             $this->posts[] = $post;
  297.             $post->setCreatedBy($this);
  298.         }
  299.         return $this;
  300.     }
  301.     public function removePost(Post $post): self
  302.     {
  303.         if ($this->posts->removeElement($post)) {
  304.             // set the owning side to null (unless already changed)
  305.             if ($post->getCreatedBy() === $this) {
  306.                 $post->setCreatedBy(null);
  307.             }
  308.         }
  309.         return $this;
  310.     }
  311.     public function getPhoto(): ?string
  312.     {
  313.         return $this->photo;
  314.     }
  315.     public function setPhoto(?string $photo): self
  316.     {
  317.         $this->photo $photo;
  318.         return $this;
  319.     }
  320.     public function getGoogleId(): ?string
  321.     {
  322.         return $this->google_id;
  323.     }
  324.     public function setGoogleId(?string $google_id): self
  325.     {
  326.         $this->google_id $google_id;
  327.         return $this;
  328.     }
  329.     public function getFacebookId(): ?string
  330.     {
  331.         return $this->facebook_id;
  332.     }
  333.     public function setFacebookId(?string $facebook_id): self
  334.     {
  335.         $this->facebook_id $facebook_id;
  336.         return $this;
  337.     }
  338.     /**
  339.      * @return Collection<int, Pointing>
  340.      */
  341.     public function getPointings(): Collection
  342.     {
  343.         return $this->pointings;
  344.     }
  345.     public function addPointing(Pointing $pointing): self
  346.     {
  347.         if (!$this->pointings->contains($pointing)) {
  348.             $this->pointings[] = $pointing;
  349.             $pointing->setCreatedBy($this);
  350.         }
  351.         return $this;
  352.     }
  353.     public function removePointing(Pointing $pointing): self
  354.     {
  355.         if ($this->pointings->removeElement($pointing)) {
  356.             // set the owning side to null (unless already changed)
  357.             if ($pointing->getCreatedBy() === $this) {
  358.                 $pointing->setCreatedBy(null);
  359.             }
  360.         }
  361.         return $this;
  362.     }
  363.     /**
  364.      * @return Collection<int, AbsenceEmployee>
  365.      */
  366.     public function getAbsenceEmployees(): Collection
  367.     {
  368.         return $this->absenceEmployees;
  369.     }
  370.     public function addAbsenceEmployee(AbsenceEmployee $absenceEmployee): self
  371.     {
  372.         if (!$this->absenceEmployees->contains($absenceEmployee)) {
  373.             $this->absenceEmployees[] = $absenceEmployee;
  374.             $absenceEmployee->setCreatedBy($this);
  375.         }
  376.         return $this;
  377.     }
  378.     public function removeAbsenceEmployee(AbsenceEmployee $absenceEmployee): self
  379.     {
  380.         if ($this->absenceEmployees->removeElement($absenceEmployee)) {
  381.             // set the owning side to null (unless already changed)
  382.             if ($absenceEmployee->getCreatedBy() === $this) {
  383.                 $absenceEmployee->setCreatedBy(null);
  384.             }
  385.         }
  386.         return $this;
  387.     }
  388.     public function isIsVerified(): ?bool
  389.     {
  390.         return $this->isVerified;
  391.     }
  392.     public function getLastLogin(): ?\DateTimeInterface
  393.     {
  394.         return $this->last_login;
  395.     }
  396.     public function setLastLogin(?\DateTimeInterface $last_login): self
  397.     {
  398.         $this->last_login $last_login;
  399.         return $this;
  400.     }
  401.     /**
  402.      * @return Collection<int, Activity>
  403.      */
  404.     public function getActivities(): Collection
  405.     {
  406.         return $this->activities;
  407.     }
  408.     public function addActivity(Activity $activity): static
  409.     {
  410.         if (!$this->activities->contains($activity)) {
  411.             $this->activities->add($activity);
  412.             $activity->setMadeBy($this);
  413.         }
  414.         return $this;
  415.     }
  416.     public function removeActivity(Activity $activity): static
  417.     {
  418.         if ($this->activities->removeElement($activity)) {
  419.             // set the owning side to null (unless already changed)
  420.             if ($activity->getMadeBy() === $this) {
  421.                 $activity->setMadeBy(null);
  422.             }
  423.         }
  424.         return $this;
  425.     }
  426.     public function getPhone(): ?string
  427.     {
  428.         return $this->phone;
  429.     }
  430.     public function setPhone(?string $phone): static
  431.     {
  432.         $this->phone $phone;
  433.         return $this;
  434.     }
  435.     public function isIsActive(): ?bool
  436.     {
  437.         return $this->isActive;
  438.     }
  439.     public function setIsActive(?bool $isActive): static
  440.     {
  441.         $this->isActive $isActive;
  442.         return $this;
  443.     }
  444. }