src/Entity/User.php line 19

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Repository\UserRepository;
  4. use Doctrine\Common\Collections\ArrayCollection;
  5. use Doctrine\Common\Collections\Collection;
  6. use Doctrine\ORM\Mapping as ORM;
  7. use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
  8. use Symfony\Component\Security\Core\User\PasswordAuthenticatedUserInterface;
  9. use Symfony\Component\Security\Core\User\UserInterface;
  10. use Symfony\Component\Validator\Constraints as Assert;
  11. /**
  12.  * @ORM\Entity(repositoryClass=UserRepository::class)
  13.  * @UniqueEntity("email")
  14.  * @ORM\HasLifecycleCallbacks()
  15.  */
  16. class User implements UserInterfacePasswordAuthenticatedUserInterface
  17. {
  18.     use RemoveImageTrait;
  19.     /**
  20.      * @ORM\Id
  21.      * @ORM\GeneratedValue
  22.      * @ORM\Column(type="integer")
  23.      */
  24.     private $id;
  25.     /**
  26.      * @ORM\Column(type="string", length=180, unique=true)
  27.      * @Assert\NotBlank()
  28.      * @Assert\Email()
  29.      */
  30.     private $email;
  31.     /**
  32.      * @ORM\Column(type="boolean")
  33.      */
  34.     private $emailConfirmed false;
  35.     /**
  36.      * @ORM\Column(type="json")
  37.      */
  38.     private $roles = [];
  39.     /**
  40.      * @var string The hashed password
  41.      * @ORM\Column(type="string")
  42.      */
  43.     private $password;
  44.     /**
  45.      * @ORM\ManyToMany(targetEntity=Speaker::class, mappedBy="subscribers")
  46.      */
  47.     private $subscribedToSpeakers;
  48.     /**
  49.      * @ORM\OneToMany(targetEntity=Review::class, mappedBy="user", orphanRemoval=true)
  50.      */
  51.     private $reviews;
  52.     /**
  53.      * @ORM\Column(type="string", length=255)
  54.      */
  55.     private $firstName;
  56.     /**
  57.      * @ORM\Column(type="string", length=255, nullable=true)
  58.      */
  59.     private $lastName;
  60.     /**
  61.      * @ORM\Column(type="string", length=255, nullable=true)
  62.      */
  63.     private $phone;
  64.     /**
  65.      * @ORM\OneToMany(targetEntity=Order::class, mappedBy="user")
  66.      */
  67.     private $orders;
  68.     /**
  69.      * @ORM\Column(type="string", length=255, nullable=true)
  70.      */
  71.     private $timezone;
  72.     /**
  73.      * @ORM\OneToOne(targetEntity="Speaker", mappedBy="user", cascade={"persist"})
  74.      * @Assert\Valid()
  75.      */
  76.     private $speaker;
  77.     /**
  78.      * @ORM\Column(type="float")
  79.      */
  80.     private $rating 0;
  81.     /**
  82.      * @ORM\Column(type="integer")
  83.      */
  84.     private $ratingVote 0;
  85.     /**
  86.      * @ORM\ManyToMany(targetEntity=SpeakerConsultation::class, mappedBy="participants")
  87.      */
  88.     private $consultations;
  89.     /**
  90.      * @ORM\OneToMany(targetEntity=Notification::class, mappedBy="user", orphanRemoval=true)
  91.      */
  92.     private $notifications;
  93.     /**
  94.      * @ORM\Column(type="string", length=255, nullable=true)
  95.      */
  96.     private $zoomUserId;
  97.     /**
  98.      * @ORM\Column(type="text", nullable=true)
  99.      */
  100.     private $googleAccessToken;
  101.     /**
  102.      * @ORM\Column(type="string", length=255, nullable=true)
  103.      */
  104.     private $googleCalendarId;
  105.     /**
  106.      * @ORM\Column(type="string", length=255, nullable=true)
  107.      */
  108.     private $avatar;
  109.     /**
  110.      * @ORM\Column(type="string", length=255, nullable=true)
  111.      * @Assert\Email()
  112.      */
  113.     private $notificationEmail;
  114.     /**
  115.      * @ORM\Column(type="string", length=255, nullable=true)
  116.      */
  117.     private $notificationSms;
  118.     /**
  119.      * @ORM\Column(type="string", length=255, nullable=true)
  120.      */
  121.     private $rebillId;
  122.     /**
  123.      * @ORM\Column(type="json", nullable=true)
  124.      */
  125.     private $rebillPaymentInfo;
  126.     /**
  127.      * @ORM\OneToMany(targetEntity=Complaint::class, mappedBy="author", orphanRemoval=true)
  128.      */
  129.     private $complaints;
  130.     /**
  131.      * @ORM\ManyToMany(targetEntity=SpeakerCourse::class, mappedBy="participants")
  132.      */
  133.     private $courses;
  134.     /**
  135.      * @ORM\Column(type="string", length=255, nullable=true)
  136.      */
  137.     private $telegramId;
  138.     /**
  139.      * @ORM\OneToMany(targetEntity="App\Entity\Speaker", mappedBy="user", cascade={"remove"})
  140.      */
  141.     private $speakers;
  142.     public function __construct()
  143.     {
  144.         $this->speakers = new ArrayCollection();
  145.         $this->subscribedToSpeakers = new ArrayCollection();
  146.         $this->reviews = new ArrayCollection();
  147.         $this->orders = new ArrayCollection();
  148.         $this->consultations = new ArrayCollection();
  149.         $this->notifications = new ArrayCollection();
  150.         $this->complaints = new ArrayCollection();
  151.         $this->courses = new ArrayCollection();
  152.     }
  153.     /**
  154.      * @ORM\PostRemove()
  155.      */
  156.     public function postRemoveEvent()
  157.     {
  158.         $this->removeImage($this->getAvatar());
  159.     }
  160.     public function getId(): ?int
  161.     {
  162.         return $this->id;
  163.     }
  164.     public function getEmail(): ?string
  165.     {
  166.         return $this->email;
  167.     }
  168.     public function setEmail(string $email): self
  169.     {
  170.         $this->email $email;
  171.         return $this;
  172.     }
  173.     public function getEmailConfirmed(): ?bool
  174.     {
  175.         return $this->emailConfirmed;
  176.     }
  177.     public function setEmailConfirmed(bool $emailConfirmed): self
  178.     {
  179.         $this->emailConfirmed $emailConfirmed;
  180.         return $this;
  181.     }
  182.     /**
  183.      * A visual identifier that represents this user.
  184.      *
  185.      * @see UserInterface
  186.      */
  187.     public function getUserIdentifier(): string
  188.     {
  189.         return (string) $this->email;
  190.     }
  191.     /**
  192.      * @deprecated since Symfony 5.3, use getUserIdentifier instead
  193.      */
  194.     public function getUsername(): string
  195.     {
  196.         return (string) $this->email;
  197.     }
  198.     /**
  199.      * @see UserInterface
  200.      */
  201.     public function getRoles(): array
  202.     {
  203.         $roles $this->roles;
  204.         // guarantee every user at least has ROLE_USER
  205.         $roles[] = 'ROLE_USER';
  206.         return array_unique($roles);
  207.     }
  208.     public function setRoles(array $roles): self
  209.     {
  210.         $this->roles $roles;
  211.         return $this;
  212.     }
  213.     public function addRole(string $role): self
  214.     {
  215.         $roles $this->getRoles();
  216.         if (!in_array($role$roles)) {
  217.             $roles[] = $role;
  218.             $this->setRoles($roles);
  219.         }
  220.         return $this;
  221.     }
  222.     public function removeRole(string $role): self
  223.     {
  224.         $roles $this->getRoles();
  225.         $index array_search($role$roles);
  226.         if ($index) {
  227.             unset($roles[$index]);
  228.             $this->setRoles($roles);
  229.         }
  230.         return $this;
  231.     }
  232.     /**
  233.      * @see PasswordAuthenticatedUserInterface
  234.      */
  235.     public function getPassword(): string
  236.     {
  237.         return $this->password;
  238.     }
  239.     public function setPassword(string $password): self
  240.     {
  241.         $this->password $password;
  242.         return $this;
  243.     }
  244.     /**
  245.      * Returning a salt is only needed, if you are not using a modern
  246.      * hashing algorithm (e.g. bcrypt or sodium) in your security.yaml.
  247.      *
  248.      * @see UserInterface
  249.      */
  250.     public function getSalt(): ?string
  251.     {
  252.         return null;
  253.     }
  254.     /**
  255.      * @see UserInterface
  256.      */
  257.     public function eraseCredentials()
  258.     {
  259.         // If you store any temporary, sensitive data on the user, clear it here
  260.         // $this->plainPassword = null;
  261.     }
  262.     /**
  263.      * @return Collection|Speaker[]
  264.      */
  265.     public function getSubscribedToSpeakers(): Collection
  266.     {
  267.         return $this->subscribedToSpeakers;
  268.     }
  269.     public function addSubscribedToSpeaker(Speaker $subscribedToSpeaker): self
  270.     {
  271.         if (!$this->subscribedToSpeakers->contains($subscribedToSpeaker)) {
  272.             $this->subscribedToSpeakers[] = $subscribedToSpeaker;
  273.             $subscribedToSpeaker->addSubscriber($this);
  274.         }
  275.         return $this;
  276.     }
  277.     public function removeSubscribedToSpeaker(Speaker $subscribedToSpeaker): self
  278.     {
  279.         if ($this->subscribedToSpeakers->removeElement($subscribedToSpeaker)) {
  280.             $subscribedToSpeaker->removeSubscriber($this);
  281.         }
  282.         return $this;
  283.     }
  284.     /**
  285.      * @return Collection|Review[]
  286.      */
  287.     public function getReviews(): Collection
  288.     {
  289.         return $this->reviews;
  290.     }
  291.     public function addReview(Review $review): self
  292.     {
  293.         if (!$this->reviews->contains($review)) {
  294.             $this->reviews[] = $review;
  295.             $review->setUser($this);
  296.         }
  297.         return $this;
  298.     }
  299.     public function removeReview(Review $review): self
  300.     {
  301.         if ($this->reviews->removeElement($review)) {
  302.             // set the owning side to null (unless already changed)
  303.             if ($review->getUser() === $this) {
  304.                 $review->setUser(null);
  305.             }
  306.         }
  307.         return $this;
  308.     }
  309.     public function getFirstName(): ?string
  310.     {
  311.         return $this->firstName;
  312.     }
  313.     public function setFirstName(string $firstName): self
  314.     {
  315.         $this->firstName $firstName;
  316.         return $this;
  317.     }
  318.     public function __toString(): string
  319.     {
  320.         return trim($this->getFirstName() . ' ' $this->getLastName());
  321.     }
  322.     public function getPhone(): ?string
  323.     {
  324.         return $this->phone;
  325.     }
  326.     public function setPhone(?string $phone): self
  327.     {
  328.         $this->phone $phone;
  329.         return $this;
  330.     }
  331.     /**
  332.      * @return Collection|Order[]
  333.      */
  334.     public function getOrders(): Collection
  335.     {
  336.         return $this->orders;
  337.     }
  338.     public function addOrder(Order $order): self
  339.     {
  340.         if (!$this->orders->contains($order)) {
  341.             $this->orders[] = $order;
  342.             $order->setUser($this);
  343.         }
  344.         return $this;
  345.     }
  346.     public function removeOrder(Order $order): self
  347.     {
  348.         if ($this->orders->removeElement($order)) {
  349.             // set the owning side to null (unless already changed)
  350.             if ($order->getUser() === $this) {
  351.                 $order->setUser(null);
  352.             }
  353.         }
  354.         return $this;
  355.     }
  356.     public function getLastName(): ?string
  357.     {
  358.         return $this->lastName;
  359.     }
  360.     public function setLastName(?string $lastName): self
  361.     {
  362.         $this->lastName $lastName;
  363.         return $this;
  364.     }
  365.     public function getTimezone(): ?string
  366.     {
  367.         return empty($this->timezone) ? date_default_timezone_get() : $this->timezone;
  368.     }
  369.     public function setTimezone(?string $timezone): self
  370.     {
  371.         $this->timezone $timezone;
  372.         return $this;
  373.     }
  374.     /**
  375.      * @return ?Speaker
  376.      */
  377.     public function getSpeaker(): ?Speaker
  378.     {
  379.         return $this->speaker;
  380.     }
  381.     /**
  382.      * @param Speaker $speaker
  383.      * @return User
  384.      */
  385.     public function setSpeaker(Speaker $speaker): self
  386.     {
  387.         $this->speaker $speaker;
  388.         $this->speaker->setUser($this);
  389.         return $this;
  390.     }
  391.     public function getRating(): ?float
  392.     {
  393.         return $this->rating;
  394.     }
  395.     public function setRating(float $rating): self
  396.     {
  397.         $this->rating $rating;
  398.         return $this;
  399.     }
  400.     public function getRatingVote(): ?int
  401.     {
  402.         return $this->ratingVote;
  403.     }
  404.     public function setRatingVote(int $ratingVote): self
  405.     {
  406.         $this->ratingVote $ratingVote;
  407.         return $this;
  408.     }
  409.     /**
  410.      * @return Collection|SpeakerConsultation[]
  411.      */
  412.     public function getConsultations(): Collection
  413.     {
  414.         return $this->consultations;
  415.     }
  416.     public function addConsultation(SpeakerConsultation $consultation): self
  417.     {
  418.         if (!$this->consultations->contains($consultation)) {
  419.             $this->consultations[] = $consultation;
  420.             $consultation->addParticipant($this);
  421.         }
  422.         return $this;
  423.     }
  424.     public function removeConsultation(SpeakerConsultation $consultation): self
  425.     {
  426.         if ($this->consultations->removeElement($consultation)) {
  427.             // set the owning side to null (unless already changed)
  428.             if ($consultation->getSpeaker() === $this) {
  429.                 $consultation->removeParticipant($this);
  430.             }
  431.         }
  432.         return $this;
  433.     }
  434.     /**
  435.      * @return Collection|Notification[]
  436.      */
  437.     public function getNotifications(): Collection
  438.     {
  439.         return $this->notifications;
  440.     }
  441.     public function addNotification(Notification $notification): self
  442.     {
  443.         if (!$this->notifications->contains($notification)) {
  444.             $this->notifications[] = $notification;
  445.             $notification->setUser($this);
  446.         }
  447.         return $this;
  448.     }
  449.     public function removeNotification(Notification $notification): self
  450.     {
  451.         if ($this->notifications->removeElement($notification)) {
  452.             // set the owning side to null (unless already changed)
  453.             if ($notification->getUser() === $this) {
  454.                 $notification->setUser(null);
  455.             }
  456.         }
  457.         return $this;
  458.     }
  459.     public function getZoomUserId(): ?string
  460.     {
  461.         return $this->zoomUserId;
  462.     }
  463.     public function setZoomUserId(?string $zoomUserId): self
  464.     {
  465.         $this->zoomUserId $zoomUserId;
  466.         return $this;
  467.     }
  468.     public function getGoogleAccessToken(): ?string
  469.     {
  470.         return $this->googleAccessToken;
  471.     }
  472.     public function setGoogleAccessToken(?string $googleAccessToken): self
  473.     {
  474.         $this->googleAccessToken $googleAccessToken;
  475.         return $this;
  476.     }
  477.     public function getGoogleCalendarId(): ?string
  478.     {
  479.         return $this->googleCalendarId;
  480.     }
  481.     public function setGoogleCalendarId(?string $googleCalendarId): self
  482.     {
  483.         $this->googleCalendarId $googleCalendarId;
  484.         return $this;
  485.     }
  486.     public function getAvatar(): ?string
  487.     {
  488.         return $this->avatar;
  489.     }
  490.     public function setAvatar(?string $avatar): self
  491.     {
  492.         $this->avatar $avatar;
  493.         if ($this->getSpeaker() && $this->getSpeaker()->getPhotoAvatar() != $avatar) {
  494.             $this->removeImage($this->getSpeaker()->getPhotoAvatar());
  495.             $this->getSpeaker()->setPhotoAvatar($avatar);
  496.         }
  497.         return $this;
  498.     }
  499.     public function getNotificationEmail(): ?string
  500.     {
  501.         return $this->notificationEmail;
  502.     }
  503.     public function setNotificationEmail(?string $notificationEmail): self
  504.     {
  505.         $this->notificationEmail $notificationEmail;
  506.         return $this;
  507.     }
  508.     public function getNotificationSms(): ?string
  509.     {
  510.         return $this->notificationSms;
  511.     }
  512.     public function setNotificationSms(?string $notificationSms): self
  513.     {
  514.         $this->notificationSms $notificationSms;
  515.         return $this;
  516.     }
  517.     public function getRebillId(): ?string
  518.     {
  519.         return $this->rebillId;
  520.     }
  521.     public function setRebillId(?string $rebillId): self
  522.     {
  523.         $this->rebillId $rebillId;
  524.         return $this;
  525.     }
  526.     public function getRebillPaymentInfo(): ?array
  527.     {
  528.         return $this->rebillPaymentInfo;
  529.     }
  530.     public function setRebillPaymentInfo(?array $rebillPaymentInfo): self
  531.     {
  532.         $this->rebillPaymentInfo $rebillPaymentInfo;
  533.         return $this;
  534.     }
  535.     /**
  536.      * @return Collection<int, Complaint>
  537.      */
  538.     public function getComplaints(): Collection
  539.     {
  540.         return $this->complaints;
  541.     }
  542.     public function addComplaint(Complaint $complaint): self
  543.     {
  544.         if (!$this->complaints->contains($complaint)) {
  545.             $this->complaints[] = $complaint;
  546.             $complaint->setAuthor($this);
  547.         }
  548.         return $this;
  549.     }
  550.     public function removeComplaint(Complaint $complaint): self
  551.     {
  552.         if ($this->complaints->removeElement($complaint)) {
  553.             // set the owning side to null (unless already changed)
  554.             if ($complaint->getAuthor() === $this) {
  555.                 $complaint->setAuthor(null);
  556.             }
  557.         }
  558.         return $this;
  559.     }
  560.     /**
  561.      * @return Collection<int, SpeakerCourse>
  562.      */
  563.     public function getCourses(): Collection
  564.     {
  565.         return $this->courses;
  566.     }
  567.     public function addCourse(SpeakerCourse $course): self
  568.     {
  569.         if (!$this->courses->contains($course)) {
  570.             $this->courses[] = $course;
  571.             $course->addParticipant($this);
  572.         }
  573.         return $this;
  574.     }
  575.     public function removeCourse(SpeakerCourse $course): self
  576.     {
  577.         if ($this->courses->removeElement($course)) {
  578.             $course->removeParticipant($this);
  579.         }
  580.         return $this;
  581.     }
  582.     public function getTelegramId(): ?string
  583.     {
  584.         return $this->telegramId;
  585.     }
  586.     public function setTelegramId(?string $telegramId): self
  587.     {
  588.         $this->telegramId $telegramId;
  589.         return $this;
  590.     }
  591. }