src/Entity/Attendee.php line 20

  1. <?php
  2. namespace App\Entity;
  3. use ApiPlatform\Metadata\ApiResource;
  4. use App\Repository\AttendeeRepository;
  5. use Doctrine\Common\Collections\ArrayCollection;
  6. use Doctrine\Common\Collections\Collection;
  7. use Doctrine\DBAL\Types\Types;
  8. use Doctrine\ORM\Mapping as ORM;
  9. use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
  10. use Symfony\Component\Security\Core\User\PasswordAuthenticatedUserInterface;
  11. use Symfony\Component\Security\Core\User\UserInterface;
  12. use Symfony\UX\Turbo\Attribute\Broadcast;
  13. #[ORM\Entity(repositoryClassAttendeeRepository::class)]
  14. #[Broadcast]
  15. #[ApiResource]
  16. #[UniqueEntity(fields: ['username'], message'There is already an account with this username')]
  17. class Attendee implements UserInterfacePasswordAuthenticatedUserInterface
  18. {
  19.     #[ORM\Id]
  20.     #[ORM\GeneratedValue]
  21.     #[ORM\Column]
  22.     private ?int $id null;
  23.     #[ORM\Column(length180uniquetrue)]
  24.     private ?string $username null;
  25.     #[ORM\Column]
  26.     private array $roles = [];
  27.     /**
  28.      * @var string The hashed password
  29.      */
  30.     #[ORM\Column]
  31.     private ?string $password null;
  32.     #[ORM\Embedded(class: UserInformation::class)]
  33.     private UserInformation $userInformation;
  34.     #[ORM\Embedded(class: Adress::class)]
  35.     private $billingAdress;
  36.     #[ORM\ManyToOne(inversedBy'attendees')]
  37.     private ?Corporation $corporation null;
  38.     #[ORM\ManyToMany(targetEntityCourse::class, mappedBy'attendees')]
  39.     private Collection $courses;
  40.     #[ORM\OneToMany(mappedBy'attendee'targetEntityLessonProgress::class)]
  41.     private Collection $lessonProgress;
  42.     #[ORM\ManyToOne(inversedBy'attendees')]
  43.     private ?Portal $portal null;
  44.     #[ORM\OneToMany(mappedBy'attendee'targetEntityCourseEvaluation::class)]
  45.     private Collection $courseEvaluations;
  46.     #[ORM\ManyToMany(targetEntityBadge::class, inversedBy'attendees')]
  47.     private Collection $badges;
  48.     #[ORM\Column]
  49.     private ?int $mood null;
  50.     #[ORM\OneToMany(mappedBy'attendee'targetEntityGivenAnswere::class)]
  51.     private Collection $givenAnsweres;
  52.     #[ORM\OneToMany(mappedBy'sender'targetEntityMessage::class)]
  53.     private Collection $sendMessages;
  54.     #[ORM\OneToMany(mappedBy'receiver'targetEntityMessage::class)]
  55.     private Collection $reveivedMessages;
  56.     #[ORM\Column(type'boolean')]
  57.     private $isVerified false;
  58.     #[ORM\OneToMany(mappedBy'attendee'targetEntityBooking::class)]
  59.     private Collection $bookings;
  60.     #[ORM\OneToMany(mappedBy'attendee'targetEntityLicenseStatus::class)]
  61.     private Collection $licenseStatuses;
  62.     #[ORM\OneToMany(mappedBy'attendee'targetEntityCertificate::class)]
  63.     private Collection $certificates;
  64.     #[ORM\OneToMany(mappedBy'attendee'targetEntityLoggedTime::class)]
  65.     private Collection $loggedTimes;
  66.     #[ORM\Column(typeTypes::DATETIME_MUTABLE)]
  67.     private ?\DateTimeInterface $lastLogin null;
  68.     public function __construct()
  69.     {
  70.         $this->userInformation = new UserInformation();
  71.         $this->getUserInformation()->setCreatedAt(new \DateTimeImmutable());
  72.         $this->courses = new ArrayCollection();
  73.         $this->lessonProgress = new ArrayCollection();
  74.         $this->courseEvaluations = new ArrayCollection();
  75.         $this->badges = new ArrayCollection();
  76.         $this->givenAnsweres = new ArrayCollection();
  77.         $this->sendMessages = new ArrayCollection();
  78.         $this->reveivedMessages = new ArrayCollection();
  79.         $this->billingAdress = new Adress();
  80.         $this->bookings = new ArrayCollection();
  81.         $this->licenseStatuses = new ArrayCollection();
  82.         $this->certificates = new ArrayCollection();
  83.         $this->loggedTimes = new ArrayCollection();
  84.         $this->lastLogin = new \DateTimeImmutable();
  85.     }
  86.     public function getEmail(): ?string
  87.     {
  88.         return $this->getUserInformation()->getEmail();
  89.     }
  90.     public function getId(): ?int
  91.     {
  92.         return $this->id;
  93.     }
  94.     public function __toString(): string
  95.     {
  96.         return $this->getUserInformation()->getFirstName() . ' ' $this->getUserInformation()->getLastName();
  97.     }
  98.     public function getUsername(): ?string
  99.     {
  100.         return $this->username;
  101.     }
  102.     public function setUsername(string $username): self
  103.     {
  104.         $this->username $username;
  105.         return $this;
  106.     }
  107.     /**
  108.      * A visual identifier that represents this user.
  109.      *
  110.      * @see UserInterface
  111.      */
  112.     public function getUserIdentifier(): string
  113.     {
  114.         return (string)$this->username;
  115.     }
  116.     /**
  117.      * @see UserInterface
  118.      */
  119.     public function getRoles(): array
  120.     {
  121.         $roles $this->roles;
  122.         // guarantee every user at least has ROLE_USER
  123.         $roles[] = 'ROLE_USER';
  124.         return array_unique($roles);
  125.     }
  126.     public function setRoles(array $roles): self
  127.     {
  128.         $this->roles $roles;
  129.         return $this;
  130.     }
  131.     /**
  132.      * @see PasswordAuthenticatedUserInterface
  133.      */
  134.     public function getPassword(): string
  135.     {
  136.         return $this->password;
  137.     }
  138.     public function setPassword(string $password): self
  139.     {
  140.         $this->password $password;
  141.         return $this;
  142.     }
  143.     /**
  144.      * @see UserInterface
  145.      */
  146.     public function eraseCredentials()
  147.     {
  148.         // If you store any temporary, sensitive data on the user, clear it here
  149.         // $this->plainPassword = null;
  150.     }
  151.     public function getUserInformation(): UserInformation
  152.     {
  153.         return $this->userInformation;
  154.     }
  155.     public function setUserInformation(UserInformation $userInformation): self
  156.     {
  157.         $this->userInformation $userInformation;
  158.         return $this;
  159.     }
  160.     public function getCorporation(): ?Corporation
  161.     {
  162.         return $this->corporation;
  163.     }
  164.     public function setCorporation(?Corporation $corporation): self
  165.     {
  166.         $this->corporation $corporation;
  167.         return $this;
  168.     }
  169.     /**
  170.      * @return Collection<int, Course>
  171.      */
  172.     public function getCourses(): Collection
  173.     {
  174.         return $this->courses;
  175.     }
  176.     public function addCourse(Course $course): self
  177.     {
  178.         if (!$this->courses->contains($course)) {
  179.             $this->courses->add($course);
  180.             $course->addAttendee($this);
  181.         }
  182.         return $this;
  183.     }
  184.     public function removeCourse(Course $course): self
  185.     {
  186.         if ($this->courses->removeElement($course)) {
  187.             $course->removeAttendee($this);
  188.         }
  189.         return $this;
  190.     }
  191.     /**
  192.      * @return Collection<int, LessonProgress>
  193.      */
  194.     public function getLessonProgress(): Collection
  195.     {
  196.         return $this->lessonProgress;
  197.     }
  198.     public function addLessonProgress(LessonProgress $lessonProgress): self
  199.     {
  200.         if (!$this->lessonProgress->contains($lessonProgress)) {
  201.             $this->lessonProgress->add($lessonProgress);
  202.             $lessonProgress->setAttendee($this);
  203.         }
  204.         return $this;
  205.     }
  206.     public function removeLessonProgress(LessonProgress $lessonProgress): self
  207.     {
  208.         if ($this->lessonProgress->removeElement($lessonProgress)) {
  209.             // set the owning side to null (unless already changed)
  210.             if ($lessonProgress->getAttendee() === $this) {
  211.                 $lessonProgress->setAttendee(null);
  212.             }
  213.         }
  214.         return $this;
  215.     }
  216.     public function getPortal(): ?Portal
  217.     {
  218.         return $this->portal;
  219.     }
  220.     public function setPortal(?Portal $portal): self
  221.     {
  222.         $this->portal $portal;
  223.         return $this;
  224.     }
  225.     /**
  226.      * @return Collection<int, CourseEvaluation>
  227.      */
  228.     public function getCourseEvaluations(): Collection
  229.     {
  230.         return $this->courseEvaluations;
  231.     }
  232.     public function addCourseEvaluation(CourseEvaluation $courseEvaluation): self
  233.     {
  234.         if (!$this->courseEvaluations->contains($courseEvaluation)) {
  235.             $this->courseEvaluations->add($courseEvaluation);
  236.             $courseEvaluation->setAttendee($this);
  237.         }
  238.         return $this;
  239.     }
  240.     public function removeCourseEvaluation(CourseEvaluation $courseEvaluation): self
  241.     {
  242.         if ($this->courseEvaluations->removeElement($courseEvaluation)) {
  243.             // set the owning side to null (unless already changed)
  244.             if ($courseEvaluation->getAttendee() === $this) {
  245.                 $courseEvaluation->setAttendee(null);
  246.             }
  247.         }
  248.         return $this;
  249.     }
  250.     /**
  251.      * @return Collection<int, Badge>
  252.      */
  253.     public function getBadges(): Collection
  254.     {
  255.         return $this->badges;
  256.     }
  257.     public function addBadge(Badge $badge): self
  258.     {
  259.         if (!$this->badges->contains($badge)) {
  260.             $this->badges->add($badge);
  261.         }
  262.         return $this;
  263.     }
  264.     public function removeBadge(Badge $badge): self
  265.     {
  266.         $this->badges->removeElement($badge);
  267.         return $this;
  268.     }
  269.     public function getMood(): ?int
  270.     {
  271.         return $this->mood;
  272.     }
  273.     public function setMood(int $mood): self
  274.     {
  275.         $this->mood $mood;
  276.         return $this;
  277.     }
  278.     /**
  279.      * @return Collection<int, GivenAnswere>
  280.      */
  281.     public function getGivenAnsweres(): Collection
  282.     {
  283.         return $this->givenAnsweres;
  284.     }
  285.     public function addGivenAnswere(GivenAnswere $givenAnswere): self
  286.     {
  287.         if (!$this->givenAnsweres->contains($givenAnswere)) {
  288.             $this->givenAnsweres->add($givenAnswere);
  289.             $givenAnswere->setAttendee($this);
  290.         }
  291.         return $this;
  292.     }
  293.     public function removeGivenAnswere(GivenAnswere $givenAnswere): self
  294.     {
  295.         if ($this->givenAnsweres->removeElement($givenAnswere)) {
  296.             // set the owning side to null (unless already changed)
  297.             if ($givenAnswere->getAttendee() === $this) {
  298.                 $givenAnswere->setAttendee(null);
  299.             }
  300.         }
  301.         return $this;
  302.     }
  303.     /**
  304.      * @return Collection<int, Message>
  305.      */
  306.     public function getSendMessages(): Collection
  307.     {
  308.         return $this->sendMessages;
  309.     }
  310.     public function addSendMessage(Message $sendMessage): self
  311.     {
  312.         if (!$this->sendMessages->contains($sendMessage)) {
  313.             $this->sendMessages->add($sendMessage);
  314.             $sendMessage->setSender($this);
  315.         }
  316.         return $this;
  317.     }
  318.     public function removeSendMessage(Message $sendMessage): self
  319.     {
  320.         if ($this->sendMessages->removeElement($sendMessage)) {
  321.             // set the owning side to null (unless already changed)
  322.             if ($sendMessage->getSender() === $this) {
  323.                 $sendMessage->setSender(null);
  324.             }
  325.         }
  326.         return $this;
  327.     }
  328.     /**
  329.      * @return Collection<int, Message>
  330.      */
  331.     public function getReveivedMessages(): Collection
  332.     {
  333.         return $this->reveivedMessages;
  334.     }
  335.     public function addReveivedMessage(Message $reveivedMessage): self
  336.     {
  337.         if (!$this->reveivedMessages->contains($reveivedMessage)) {
  338.             $this->reveivedMessages->add($reveivedMessage);
  339.             $reveivedMessage->setReceiver($this);
  340.         }
  341.         return $this;
  342.     }
  343.     public function removeReveivedMessage(Message $reveivedMessage): self
  344.     {
  345.         if ($this->reveivedMessages->removeElement($reveivedMessage)) {
  346.             // set the owning side to null (unless already changed)
  347.             if ($reveivedMessage->getReceiver() === $this) {
  348.                 $reveivedMessage->setReceiver(null);
  349.             }
  350.         }
  351.         return $this;
  352.     }
  353.     public function isVerified(): bool
  354.     {
  355.         return $this->isVerified;
  356.     }
  357.     public function setIsVerified(bool $isVerified): self
  358.     {
  359.         $this->isVerified $isVerified;
  360.         return $this;
  361.     }
  362.     public function getBillingAdress(): Adress
  363.     {
  364.         return $this->billingAdress;
  365.     }
  366.     public function setBillingAdress(Adress $billingadress): self
  367.     {
  368.         $this->billingAdress $billingadress;
  369.         return $this;
  370.     }
  371.     /**
  372.      * @return Collection<int, Booking>
  373.      */
  374.     public function getBookings(): Collection
  375.     {
  376.         return $this->bookings;
  377.     }
  378.     public function addBooking(Booking $booking): self
  379.     {
  380.         if (!$this->bookings->contains($booking)) {
  381.             $this->bookings->add($booking);
  382.             $booking->setAttendee($this);
  383.         }
  384.         return $this;
  385.     }
  386.     public function removeBooking(Booking $booking): self
  387.     {
  388.         if ($this->bookings->removeElement($booking)) {
  389.             // set the owning side to null (unless already changed)
  390.             if ($booking->getAttendee() === $this) {
  391.                 $booking->setAttendee(null);
  392.             }
  393.         }
  394.         return $this;
  395.     }
  396.     /**
  397.      * @return Collection<int, LicenseStatus>
  398.      */
  399.     public function getLicenseStatuses(): Collection
  400.     {
  401.         return $this->licenseStatuses;
  402.     }
  403.     public function addLicenseStatus(LicenseStatus $licenseStatus): self
  404.     {
  405.         if (!$this->licenseStatuses->contains($licenseStatus)) {
  406.             $this->licenseStatuses->add($licenseStatus);
  407.             $licenseStatus->setAttendee($this);
  408.         }
  409.         return $this;
  410.     }
  411.     public function removeLicenseStatus(LicenseStatus $licenseStatus): self
  412.     {
  413.         if ($this->licenseStatuses->removeElement($licenseStatus)) {
  414.             // set the owning side to null (unless already changed)
  415.             if ($licenseStatus->getAttendee() === $this) {
  416.                 $licenseStatus->setAttendee(null);
  417.             }
  418.         }
  419.         return $this;
  420.     }
  421.     /**
  422.      * @return Collection<int, Certificate>
  423.      */
  424.     public function getCertificates(): Collection
  425.     {
  426.         return $this->certificates;
  427.     }
  428.     public function addCertificate(Certificate $certificate): self
  429.     {
  430.         if (!$this->certificates->contains($certificate)) {
  431.             $this->certificates->add($certificate);
  432.             $certificate->setAttendee($this);
  433.         }
  434.         return $this;
  435.     }
  436.     public function removeCertificate(Certificate $certificate): self
  437.     {
  438.         if ($this->certificates->removeElement($certificate)) {
  439.             // set the owning side to null (unless already changed)
  440.             if ($certificate->getAttendee() === $this) {
  441.                 $certificate->setAttendee(null);
  442.             }
  443.         }
  444.         return $this;
  445.     }
  446.     /**
  447.      * @return Collection<int, LoggedTime>
  448.      */
  449.     public function getLoggedTimes(): Collection
  450.     {
  451.         return $this->loggedTimes;
  452.     }
  453.     public function addLoggedTime(LoggedTime $loggedTime): self
  454.     {
  455.         if (!$this->loggedTimes->contains($loggedTime)) {
  456.             $this->loggedTimes->add($loggedTime);
  457.             $loggedTime->setAttendee($this);
  458.         }
  459.         return $this;
  460.     }
  461.     public function removeLoggedTime(LoggedTime $loggedTime): self
  462.     {
  463.         if ($this->loggedTimes->removeElement($loggedTime)) {
  464.             // set the owning side to null (unless already changed)
  465.             if ($loggedTime->getAttendee() === $this) {
  466.                 $loggedTime->setAttendee(null);
  467.             }
  468.         }
  469.         return $this;
  470.     }
  471.     public function getLastLogin(): ?\DateTimeInterface
  472.     {
  473.         return $this->lastLogin;
  474.     }
  475.     public function setLastLogin(\DateTimeInterface $lastLogin): self
  476.     {
  477.         $this->lastLogin $lastLogin;
  478.         return $this;
  479.     }
  480. }