<?php
namespace App\Entity;
use App\Repository\AppUserRepository;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
use Symfony\Component\Security\Core\User\PasswordAuthenticatedUserInterface;
use Symfony\Component\Security\Core\User\UserInterface;
#[ORM\Entity(repositoryClass: AppUserRepository::class)]
#[UniqueEntity(fields: ['email'], message: 'There is already an account with this email')]
class AppUser implements UserInterface, PasswordAuthenticatedUserInterface
{
#[ORM\Id]
#[ORM\GeneratedValue]
#[ORM\Column(type: 'integer')]
private $id;
#[ORM\Column(type: 'string', length: 180, unique: true)]
private ?string $email = null;
#[ORM\Column(type: 'json')]
private array $roles = [];
#[ORM\Column(type: 'string')]
private ?string $password = null;
#[ORM\OneToMany(targetEntity: VesselIssue::class, mappedBy: 'app_user')]
private Collection|array $vesselIssues;
#[ORM\OneToMany(targetEntity: VesselComparison::class, mappedBy: 'app_user')]
private Collection|array $vesselComparisons;
#[ORM\Column(type: 'string', length: 255, nullable: true)]
private ?string $name_first = null;
#[ORM\Column(type: 'string', length: 255, nullable: true)]
private ?string $name_last = null;
#[ORM\Column(type: 'string', length: 10, nullable: true)]
private ?string $name_prefix = null;
#[ORM\Column(type: 'string', length: 10, nullable: true)]
private ?string $address_country = null;
#[ORM\Column(type: 'string', length: 60, nullable: true)]
private ?string $address_region = null;
#[ORM\Column(type: 'string', length: 15, nullable: true)]
private ?string $address_zip = null;
#[ORM\Column(type: 'string', length: 255, nullable: true)]
private ?string $address_city = null;
#[ORM\Column(type: 'string', length: 255, nullable: true)]
private ?string $address_line1 = null;
#[ORM\Column(type: 'string', length: 255, nullable: true)]
private ?string $address_line2 = null;
#[ORM\Column(type: 'string', length: 15, nullable: true)]
private ?string $bank_swift = null;
#[ORM\Column(type: 'string', length: 255, nullable: true)]
private ?string $bank_iban = null;
#[ORM\Column(type: 'datetime', nullable: true)]
private ?\DateTimeInterface $date_birth = null;
#[ORM\OneToMany(targetEntity: AssignmentLog::class, mappedBy: 'app_user')]
private Collection|array $assignmentLog;
#[ORM\OneToMany(targetEntity: Bookmark::class, mappedBy: 'app_user')]
private Collection|array $bookmarks;
#[ORM\Column(type: 'string', length: 100, nullable: true)]
private ?string $xp_level = null;
#[ORM\Column(type: 'integer', nullable: true)]
private ?int $xp_years = null;
#[ORM\OneToMany(targetEntity: RedeemRequest::class, mappedBy: 'app_user', orphanRemoval: true)]
private Collection|array $redeemRequests;
#[ORM\OneToMany(targetEntity: AssignmentTasks::class, mappedBy: 'AppUser', orphanRemoval: true)]
private Collection|array $assignmentTasks;
#[ORM\OneToMany(targetEntity: Assignment::class, mappedBy: 'app_user', orphanRemoval: true)]
private Collection|array $assignments;
#[ORM\OneToMany(targetEntity: VesselErrorLog::class, mappedBy: 'reported_by')]
private Collection|array $vesselErrorLogs;
#[ORM\OneToMany(mappedBy: 'app_user', targetEntity: QuizEntry::class, orphanRemoval: true)]
private Collection $quizEntries;
#[ORM\OneToMany(mappedBy: 'app_user', targetEntity: MyWoundSuture::class)]
private Collection $myWoundSutures;
#[ORM\ManyToMany(targetEntity: Course::class, mappedBy: 'users')]
#[ORM\OrderBy(['name' => 'ASC'])]
private Collection $courses;
#[ORM\OneToMany(mappedBy: 'app_user', targetEntity: TrainEntry::class, orphanRemoval: true)]
private Collection $trainEntries;
#[ORM\OneToMany(mappedBy: 'app_user', targetEntity: ExcelEntry::class, orphanRemoval: true)]
private Collection $excelEntries;
#[ORM\OneToMany(mappedBy: 'app_user', targetEntity: ModuleProgess::class, orphanRemoval: true)]
private Collection $moduleProgesses;
#[ORM\OneToMany(mappedBy: 'app_user', targetEntity: IntroEntry::class, orphanRemoval: true)]
private Collection $introEntries;
#[ORM\OneToMany(mappedBy: 'app_user', targetEntity: CourseModuleUser::class, orphanRemoval: true)]
private Collection $courseModuleUsers;
public function __construct()
{
$this->quizEntries = new ArrayCollection();
$this->trainEntries = new ArrayCollection();
$this->excelEntries = new ArrayCollection();
$this->moduleProgesses = new ArrayCollection();
$this->introEntries = new ArrayCollection();
$this->courseModuleUsers = new ArrayCollection();
}
public function getId(): ?int
{
return $this->id;
}
public function getEmail(): ?string
{
return $this->email;
}
public function setEmail(string $email): self
{
$this->email = $email;
return $this;
}
/**
* A visual identifier that represents this user.
*
* @see UserInterface
*/
public function getUsername(): string
{
return (string) $this->email;
}
/**
* A visual identifier that represents this user.
*
* @see UserInterface
*/
public function getUserIdentifier(): string
{
return (string) $this->email;
}
/**
* @see UserInterface
*/
public function getRoles(): array
{
$roles = $this->roles;
// guarantee every user at least has ROLE_USER
$roles[] = 'ROLE_USER';
return array_unique($roles);
}
public function setRoles(array $roles): self
{
$this->roles = $roles;
return $this;
}
/**
* @see PasswordAuthenticatedUserInterface
*/
public function getPassword(): ?string
{
return $this->password;
}
public function setPassword(string $password): self
{
$this->password = $password;
return $this;
}
/**
* Returning a salt is only needed, if you are not using a modern
* hashing algorithm (e.g. bcrypt or sodium) in your security.yaml.
*
* @see UserInterface
*/
public function getSalt(): ?string
{
return null;
}
/**
* @see UserInterface
*/
public function eraseCredentials()
{
// If you store any temporary, sensitive data on the user, clear it here
// $this->plainPassword = null;
}
public function isComplete()
{
return
!empty($this->getNameFirst()) &&
!empty($this->getNameLast()) &&
!(empty($this->getXpYears()) && $this->getXpYears()!==0 ) &&
!empty($this->getXpLevel()) &&
!empty($this->getDateBirth())
;
}
/**
* @return Collection|VesselIssue[]
*/
public function getVesselIssues(): Collection
{
return $this->vesselIssues;
}
public function addVesselIssue(VesselIssue $vesselIssue): self
{
if (!$this->vesselIssues->contains($vesselIssue)) {
$this->vesselIssues[] = $vesselIssue;
$vesselIssue->setAppUser($this);
}
return $this;
}
public function removeVesselIssue(VesselIssue $vesselIssue): self
{
if ($this->vesselIssues->removeElement($vesselIssue)) {
// set the owning side to null (unless already changed)
if ($vesselIssue->getAppUser() === $this) {
$vesselIssue->setAppUser(null);
}
}
return $this;
}
/**
* @return Collection|VesselComparison[]
*/
public function getVesselComparisons(): Collection
{
return $this->vesselComparisons;
}
public function addVesselComparison(VesselComparison $vesselComparison): self
{
if (!$this->vesselComparisons->contains($vesselComparison)) {
$this->vesselComparisons[] = $vesselComparison;
$vesselComparison->setAppUser($this);
}
return $this;
}
public function removeVesselComparison(VesselComparison $vesselComparison): self
{
if ($this->vesselComparisons->removeElement($vesselComparison)) {
// set the owning side to null (unless already changed)
if ($vesselComparison->getAppUser() === $this) {
$vesselComparison->setAppUser(null);
}
}
return $this;
}
public function getNameFirst(): ?string
{
return $this->name_first;
}
public function setNameFirst(string $name_first): self
{
$this->name_first = $name_first;
return $this;
}
public function getNameLast(): ?string
{
return $this->name_last;
}
public function setNameLast(?string $name_last): self
{
$this->name_last = $name_last;
return $this;
}
public function getNamePrefix(): ?string
{
return $this->name_prefix;
}
public function setNamePrefix(?string $name_prefix): self
{
$this->name_prefix = $name_prefix;
return $this;
}
public function getNameFull(): ?string
{
$name = $this->name_prefix;
$name .= strlen((string) $this->name_prefix) > 0 ? ' ' : '';
$name .= $this->name_first;
$name .= ' '.$this->name_last;
return $name;
}
public function getAddressCountry(): ?string
{
return $this->address_country;
}
public function setAddressCountry(?string $address_country): self
{
$this->address_country = $address_country;
return $this;
}
public function getAddressRegion(): ?string
{
return $this->address_region;
}
public function setAddressRegion(?string $address_region): self
{
$this->address_region = $address_region;
return $this;
}
public function getAddressZip(): ?string
{
return $this->address_zip;
}
public function setAddressZip(?string $address_zip): self
{
$this->address_zip = $address_zip;
return $this;
}
public function getAddressCity(): ?string
{
return $this->address_city;
}
public function setAddressCity(?string $address_city): self
{
$this->address_city = $address_city;
return $this;
}
public function getAddressLine1(): ?string
{
return $this->address_line1;
}
public function setAddressLine1(?string $address_line1): self
{
$this->address_line1 = $address_line1;
return $this;
}
public function getAddressLine2(): ?string
{
return $this->address_line2;
}
public function setAddressLine2(?string $address_line2): self
{
$this->address_line2 = $address_line2;
return $this;
}
public function getBankSwift(): ?string
{
return $this->bank_swift;
}
public function setBankSwift(?string $bank_swift): self
{
$this->bank_swift = $bank_swift;
return $this;
}
public function getBankIban(): ?string
{
return $this->bank_iban;
}
public function setBankIban(?string $bank_iban): self
{
$this->bank_iban = $bank_iban;
return $this;
}
public function getDateBirth(): ?\DateTimeInterface
{
return $this->date_birth;
}
public function setDateBirth(?\DateTimeInterface $date_birth): self
{
$this->date_birth = $date_birth;
return $this;
}
/**
* @return Collection|AssignmentLog[]
*/
public function getAssignmentLog(): Collection
{
return $this->assignmentLog;
}
public function addAssignmentLog(AssignmentLog $assignmentLog): self
{
if (!$this->assignmentLog->contains($assignmentLog)) {
$this->assignmentLog[] = $assignmentLog;
$assignmentLog->setAppUser($this);
}
return $this;
}
public function removeAssignmentLog(AssignmentLog $assignmentLog): self
{
if ($this->assignmentLog->removeElement($assignmentLog)) {
// set the owning side to null (unless already changed)
if ($assignmentLog->getAppUser() === $this) {
$assignmentLog->setAppUser(null);
}
}
return $this;
}
/**
* @return Collection|Bookmark[]
*/
public function getBookmarks(): Collection
{
return $this->bookmarks;
}
public function addBookmark(Bookmark $bookmark): self
{
if (!$this->bookmarks->contains($bookmark)) {
$this->bookmarks[] = $bookmark;
$bookmark->setAppUser($this);
}
return $this;
}
public function removeBookmark(Bookmark $bookmark): self
{
if ($this->bookmarks->removeElement($bookmark)) {
// set the owning side to null (unless already changed)
if ($bookmark->getAppUser() === $this) {
$bookmark->setAppUser(null);
}
}
return $this;
}
public function getXpLevel(): ?string
{
return $this->xp_level;
}
public function setXpLevel(?string $xp_level): self
{
$this->xp_level = $xp_level;
return $this;
}
public function getXpYears(): ?int
{
return $this->xp_years;
}
public function setXpYears(?int $xp_years): self
{
$this->xp_years = $xp_years;
return $this;
}
/**
* @return Collection|RedeemRequest[]
*/
public function getRedeemRequests(): Collection
{
return $this->redeemRequests;
}
public function addRedeemRequest(RedeemRequest $redeemRequest): self
{
if (!$this->redeemRequests->contains($redeemRequest)) {
$this->redeemRequests[] = $redeemRequest;
$redeemRequest->setAppUser($this);
}
return $this;
}
public function removeRedeemRequest(RedeemRequest $redeemRequest): self
{
if ($this->redeemRequests->removeElement($redeemRequest)) {
// set the owning side to null (unless already changed)
if ($redeemRequest->getAppUser() === $this) {
$redeemRequest->setAppUser(null);
}
}
return $this;
}
/**
* @return Collection|AssignmentTasks[]
*/
public function getAssignmentTasks(): Collection
{
return $this->assignmentTasks;
}
public function addAssignmentTask(AssignmentTasks $assignmentTask): self
{
if (!$this->assignmentTasks->contains($assignmentTask)) {
$this->assignmentTasks[] = $assignmentTask;
$assignmentTask->setAppUser($this);
}
return $this;
}
public function removeAssignmentTask(AssignmentTasks $assignmentTask): self
{
if ($this->assignmentTasks->removeElement($assignmentTask)) {
// set the owning side to null (unless already changed)
if ($assignmentTask->getAppUser() === $this) {
$assignmentTask->setAppUser(null);
}
}
return $this;
}
/**
* @return Collection|Assignment[]
*/
public function getAssignments(): Collection
{
return $this->assignments;
}
public function addAssignment(Assignment $assignment): self
{
if (!$this->assignments->contains($assignment)) {
$this->assignments[] = $assignment;
$assignment->setAppUser($this);
}
return $this;
}
public function removeAssignment(Assignment $assignment): self
{
if ($this->assignments->removeElement($assignment)) {
// set the owning side to null (unless already changed)
if ($assignment->getAppUser() === $this) {
$assignment->setAppUser(null);
}
}
return $this;
}
/**
* @return Collection|VesselErrorLog[]
*/
public function getVesselErrorLogs(): Collection
{
return $this->vesselErrorLogs;
}
public function addVesselErrorLog(VesselErrorLog $vesselErrorLog): self
{
if (!$this->vesselErrorLogs->contains($vesselErrorLog)) {
$this->vesselErrorLogs[] = $vesselErrorLog;
$vesselErrorLog->setReportedBy($this);
}
return $this;
}
public function removeVesselErrorLog(VesselErrorLog $vesselErrorLog): self
{
if ($this->vesselErrorLogs->removeElement($vesselErrorLog)) {
// set the owning side to null (unless already changed)
if ($vesselErrorLog->getReportedBy() === $this) {
$vesselErrorLog->setReportedBy(null);
}
}
return $this;
}
/**
* @return Collection<int, QuizEntry>
*/
public function getQuizEntries(): Collection
{
return $this->quizEntries;
}
public function addQuizEntry(QuizEntry $quizEntry): self
{
if (!$this->quizEntries->contains($quizEntry)) {
$this->quizEntries->add($quizEntry);
$quizEntry->setAppUser($this);
}
return $this;
}
public function removeQuizEntry(QuizEntry $quizEntry): self
{
if ($this->quizEntries->removeElement($quizEntry)) {
// set the owning side to null (unless already changed)
if ($quizEntry->getAppUser() === $this) {
$quizEntry->setAppUser(null);
}
}
return $this;
}
/**
* @return Collection<int, MyWoundSuture>
*/
public function getMyWoundSutures(): Collection
{
return $this->myWoundSutures;
}
public function addMyWoundSuture(MyWoundSuture $myWoundSuture): self
{
if (!$this->myWoundSutures->contains($myWoundSuture)) {
$this->myWoundSutures->add($myWoundSuture);
$myWoundSuture->setAppUser($this);
}
return $this;
}
public function removeMyWoundSuture(MyWoundSuture $myWoundSuture): self
{
if ($this->myWoundSutures->removeElement($myWoundSuture)) {
// set the owning side to null (unless already changed)
if ($myWoundSuture->getAppUser() === $this) {
$myWoundSuture->setAppUser(null);
}
}
return $this;
}
/**
* @return Collection<int, Course>
*/
public function getCourses(): Collection
{
return $this->courses;
}
public function addCourse(Course $course): self
{
if (!$this->courses->contains($course)) {
$this->courses->add($course);
$course->addUser($this);
}
return $this;
}
public function removeCourse(Course $course): self
{
if ($this->courses->removeElement($course)) {
$course->removeUser($this);
}
return $this;
}
/**
* @return Collection<int, TrainEntry>
*/
public function getTrainEntries(): Collection
{
return $this->trainEntries;
}
public function addTrainEntry(TrainEntry $trainEntry): self
{
if (!$this->trainEntries->contains($trainEntry)) {
$this->trainEntries->add($trainEntry);
$trainEntry->setAppUser($this);
}
return $this;
}
public function removeTrainEntry(TrainEntry $trainEntry): self
{
if ($this->trainEntries->removeElement($trainEntry)) {
// set the owning side to null (unless already changed)
if ($trainEntry->getAppUser() === $this) {
$trainEntry->setAppUser(null);
}
}
return $this;
}
/**
* @return Collection<int, ExcelEntry>
*/
public function getExcelEntries(): Collection
{
return $this->excelEntries;
}
public function addExcelEntry(ExcelEntry $excelEntry): static
{
if (!$this->excelEntries->contains($excelEntry)) {
$this->excelEntries->add($excelEntry);
$excelEntry->setAppUser($this);
}
return $this;
}
public function removeExcelEntry(ExcelEntry $excelEntry): static
{
if ($this->excelEntries->removeElement($excelEntry)) {
// set the owning side to null (unless already changed)
if ($excelEntry->getAppUser() === $this) {
$excelEntry->setAppUser(null);
}
}
return $this;
}
/**
* @return Collection<int, ModuleProgess>
*/
public function getModuleProgesses(): Collection
{
return $this->moduleProgesses;
}
public function addModuleProgess(ModuleProgess $moduleProgess): static
{
if (!$this->moduleProgesses->contains($moduleProgess)) {
$this->moduleProgesses->add($moduleProgess);
$moduleProgess->setAppUser($this);
}
return $this;
}
public function removeModuleProgess(ModuleProgess $moduleProgess): static
{
if ($this->moduleProgesses->removeElement($moduleProgess)) {
// set the owning side to null (unless already changed)
if ($moduleProgess->getAppUser() === $this) {
$moduleProgess->setAppUser(null);
}
}
return $this;
}
/**
* @return Collection<int, IntroEntry>
*/
public function getIntroEntries(): Collection
{
return $this->introEntries;
}
public function addIntroEntry(IntroEntry $introEntry): static
{
if (!$this->introEntries->contains($introEntry)) {
$this->introEntries->add($introEntry);
$introEntry->setAppUser($this);
}
return $this;
}
public function removeIntroEntry(IntroEntry $introEntry): static
{
if ($this->introEntries->removeElement($introEntry)) {
// set the owning side to null (unless already changed)
if ($introEntry->getAppUser() === $this) {
$introEntry->setAppUser(null);
}
}
return $this;
}
/**
* @return Collection<int, CourseModuleUser>
*/
public function getCourseModuleUsers(): Collection
{
return $this->courseModuleUsers;
}
public function addCourseModuleUser(CourseModuleUser $courseModuleUser): static
{
if (!$this->courseModuleUsers->contains($courseModuleUser)) {
$this->courseModuleUsers->add($courseModuleUser);
$courseModuleUser->setAppUser($this);
}
return $this;
}
public function removeCourseModuleUser(CourseModuleUser $courseModuleUser): static
{
if ($this->courseModuleUsers->removeElement($courseModuleUser)) {
// set the owning side to null (unless already changed)
if ($courseModuleUser->getAppUser() === $this) {
$courseModuleUser->setAppUser(null);
}
}
return $this;
}
}