<?php
namespace App\Entity;
use App\Entity\Localisation\CountryInfo;
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;
use Symfony\Component\Validator\Constraints as Assert;
use function Symfony\Component\String\u;
/**
* @ORM\Table(name="app_users")
* @ORM\Entity(repositoryClass="App\Repository\UserRepository")
* @ORM\HasLifecycleCallbacks()
* @UniqueEntity(
* fields={"email"},
* message="Cet email est déjà enregistré dans notre base de donnée, veuillez vous connecter"
* )
*/
class User implements UserInterface, PasswordAuthenticatedUserInterface
{
/**
* @ORM\Id()
* @ORM\GeneratedValue()
* @ORM\Column(type="integer")
*/
private $id;
/**
* @ORM\Column(type="string", length=180, unique=true)
* @Assert\NotBlank(message="Merci de renseigner votre email")
* @Assert\Email(message="Merci de renseigner un email valide")
*/
private $email;
/**
* @var string The hashed password
* @Assert\NotBlank(message="Merci de renseigner un mot de passe")
* @ORM\Column(type="string")
*/
private $password;
/**
* @ORM\Column(type="string", length=255)
* @Assert\NotBlank(message="Merci de renseigner votre prénom")
*/
private $firstname;
/**
* @ORM\Column(type="string", length=255)
* @Assert\NotBlank(message="Merci de renseigner votre nom de famille")
*/
private $lastname;
/**
* @ORM\Column(type="integer", nullable=true)
*/
private $phone;
/**
* @ORM\Column(type="datetime")
*/
private $registrationDate;
/**
* @ORM\OneToOne(targetEntity="App\Entity\Teacher", mappedBy="userId", cascade={"persist", "remove"})
*/
private $teacher;
/**
* @ORM\OneToMany(targetEntity="App\Entity\Child", mappedBy="parent", orphanRemoval=true)
*/
private $children;
/**
* @ORM\ManyToOne(targetEntity="App\Entity\Gender", inversedBy="users")
* @ORM\JoinColumn(nullable=true)
*/
private $gender;
/**
* @ORM\Column(type="json")
*/
private $roles = [];
/**
* @ORM\OneToMany(targetEntity="SessionOrder", mappedBy="students")
*/
private $sessionOrder;
/**
* @ORM\OneToMany(targetEntity="App\Entity\SubscriptionOrder", mappedBy="user")
*/
private $subscriptionOrders;
/**
* @ORM\Column(type="string", length=100, nullable=true)
*/
private $language;
/**
* @ORM\Column(type="string", length=50, nullable=true)
*/
private $pole;
/**
* @ORM\OneToMany(targetEntity="App\Entity\OldUserEmail", mappedBy="user")
*/
private $oldUserEmails;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $forumUrl;
/**
* @ORM\Column(type="datetime")
*/
private $agreedTermsAt;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $stripeCustomerIdForSubscription;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $stripeCustomerIdForGroupSession
;
/**
* @ORM\OneToMany(targetEntity="VideoCoursesRegistration", mappedBy="user")
*/
private $videoCoursesRegistration;
/**
* @ORM\OneToMany(targetEntity="App\Entity\Notifications", mappedBy="UserAccount")
*/
private $notifications;
/**
* @ORM\OneToMany(targetEntity="App\Entity\TicketOrder", mappedBy="user", orphanRemoval=true)
*/
private $ticketOrders;
/**
* @ORM\OneToMany(targetEntity=UserPlacementTest::class, mappedBy="user")
*/
private $userPlacementTests;
/**
* @ORM\OneToMany(targetEntity=Exam::class, mappedBy="user", orphanRemoval=true)
*/
private $exams;
/**
* @ORM\OneToMany(targetEntity=TrainingReport::class, mappedBy="user", orphanRemoval=true)
*/
private $trainingReports;
/**
* @ORM\ManyToOne(targetEntity=CountryInfo::class, inversedBy="users")
*/
private $country;
public function __construct()
{
$this->children = new ArrayCollection();
$this->sessionOrder = new ArrayCollection();
$this->subscriptionOrders = new ArrayCollection();
$this->oldUserEmails = new ArrayCollection();
$this->videoCoursesRegistration = new ArrayCollection();
$this->notifications = new ArrayCollection();
$this->ticketOrders = new ArrayCollection();
$this->userPlacementTests = new ArrayCollection();
$this->exams = new ArrayCollection();
$this->trainingReports = new ArrayCollection();
}
/**
* @ORM\PrePersist
* @ORM\PreUpdate
*/
public function prePersist() {
if(empty($this->registrationDate)) {
$this->registrationDate = new \DateTimeImmutable();
}
}
public function getId(): ?int
{
return $this->id;
}
public function getEmail(): ?string
{
return $this->email;
}
public function setEmail(string $email): self
{
$email = u($email)->lower()->toString();
$this->email = $email;
return $this;
}
/**
* A visual identifier that represents this user.
*
* @see UserInterface
*/
public function getUsername(): string
{
return (string) $this->email;
}
/**
* @see UserInterface
public function getRoles(): array
{
return [$this->getRole()];
}
*/
/**
* @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 UserInterface
*/
public function getPassword(): string
{
return (string) $this->password;
}
public function setPassword(string $password): self
{
$this->password = $password;
return $this;
}
/**
* @see UserInterface
*/
public function getSalt()
{
// not needed when using the "bcrypt" algorithm in security.yaml
}
/**
* @see UserInterface
*/
public function eraseCredentials()
{
// If you store any temporary, sensitive data on the user, clear it here
// $this->plainPassword = null;
}
public function getFirstname(): ?string
{
return $this->firstname;
}
public function setFirstname(string $firstname): self
{
$this->firstname = $firstname;
return $this;
}
public function getLastname(): ?string
{
return $this->lastname;
}
public function setLastname(string $lastname): self
{
$this->lastname = $lastname;
return $this;
}
public function getFullname(){
return trim($this->getFirstname().' '.$this->getLastname());
}
public function getPhone(): ?int
{
return $this->phone;
}
public function setPhone(?int $phone): self
{
$this->phone = $phone;
return $this;
}
public function getRegistrationDate(): ?\DateTimeInterface
{
return $this->registrationDate;
}
public function setRegistrationDate(\DateTimeInterface $registrationDate): self
{
$this->registrationDate = $registrationDate;
return $this;
}
public function getTeacher(): ?Teacher
{
return $this->teacher;
}
public function setTeacher(Teacher $teacher): self
{
$this->teacher = $teacher;
// set the owning side of the relation if necessary
if ($this !== $teacher->getUserId()) {
$teacher->setUserId($this);
}
return $this;
}
/**
* @ORM\PrePersist()
*
* @return void
*/
public function setRegistrationDateOnPersist()
{
$this->registrationDate = new \DateTime();
}
public function getGender(): ?Gender
{
return $this->gender;
}
public function setGender(?Gender $gender): self
{
$this->gender = $gender;
return $this;
}
/**
* @return Collection|Child[]
*/
public function getChildren(): Collection
{
return $this->children;
}
public function addChild(Child $child): self
{
if (!$this->children->contains($child)) {
$this->children[] = $child;
$child->setParent($this);
}
return $this;
}
public function removeChild(Child $child): self
{
if ($this->children->contains($child)) {
$this->children->removeElement($child);
// set the owning side to null (unless already changed)
if ($child->getParent() === $this) {
$child->setParent(null);
}
}
return $this;
}
/**
* @return Collection|SessionOrder[]
*/
public function getSessionOrder(): Collection
{
return $this->sessionOrder;
}
public function addSessionOrder(SessionOrder $sessionOrder): self
{
if (!$this->sessionOrder->contains($sessionOrder)) {
$this->sessionOrder[] = $sessionOrder;
$sessionOrder->setStudents($this);
}
return $this;
}
public function removeSessionOrder(SessionOrder $sessionOrder): self
{
if ($this->sessionOrder->contains($sessionOrder)) {
$this->sessionOrder->removeElement($sessionOrder);
// set the owning side to null (unless already changed)
if ($sessionOrder->getStudents() === $this) {
$sessionOrder->setStudents(null);
}
}
return $this;
}
public function __toString()
{
return $this->getFullname();
}
/**
* @return Collection|SubscriptionOrder[]
*/
public function getSubscriptionOrders(): Collection
{
return $this->subscriptionOrders;
}
public function addSubscriptionOrder(SubscriptionOrder $subscriptionOrder): self
{
if (!$this->subscriptionOrders->contains($subscriptionOrder)) {
$this->subscriptionOrders[] = $subscriptionOrder;
$subscriptionOrder->setUser($this);
}
return $this;
}
public function removeSubscriptionOrder(SubscriptionOrder $subscriptionOrder): self
{
if ($this->subscriptionOrders->contains($subscriptionOrder)) {
$this->subscriptionOrders->removeElement($subscriptionOrder);
// set the owning side to null (unless already changed)
if ($subscriptionOrder->getUser() === $this) {
$subscriptionOrder->setUser(null);
}
}
return $this;
}
public function getLanguage(): ?string
{
return $this->language;
}
public function setLanguage(?string $language): self
{
$this->language = $language;
return $this;
}
public function getPole(): ?string
{
return $this->pole;
}
public function setPole(?string $pole): self
{
$this->pole = $pole;
return $this;
}
/**
* @return Collection|OldUserEmail[]
*/
public function getOldUserEmails(): Collection
{
return $this->oldUserEmails;
}
public function addOldUserEmail(OldUserEmail $oldUserEmail): self
{
if (!$this->oldUserEmails->contains($oldUserEmail)) {
$this->oldUserEmails[] = $oldUserEmail;
$oldUserEmail->setUser($this);
}
return $this;
}
public function removeOldUserEmail(OldUserEmail $oldUserEmail): self
{
if ($this->oldUserEmails->contains($oldUserEmail)) {
$this->oldUserEmails->removeElement($oldUserEmail);
// set the owning side to null (unless already changed)
if ($oldUserEmail->getUser() === $this) {
$oldUserEmail->setUser(null);
}
}
return $this;
}
public function getForumUrl(): ?string
{
return $this->forumUrl;
}
public function setForumUrl(?string $forumUrl): self
{
$this->forumUrl = $forumUrl;
return $this;
}
public function getAgreedTermsAt(): ?\DateTimeInterface
{
return $this->agreedTermsAt;
}
public function agreedTerms(): self
{
$this->agreedTermsAt = new \DateTime();
return $this;
}
public function getStripeCustomerIdForSubscription(): ?string
{
return $this->stripeCustomerIdForSubscription;
}
public function setStripeCustomerIdForSubscription(?string $stripeCustomerIdForSubscription): self
{
$this->stripeCustomerIdForSubscription = $stripeCustomerIdForSubscription;
return $this;
}
public function getStripeCustomerIdForGroupSession(): ?string
{
return $this->stripeCustomerIdForGroupSession;
}
public function setStripeCustomerIdForGroupSession(?string $stripeCustomerIdForGroupSession): self
{
$this->stripeCustomerIdForGroupSession = $stripeCustomerIdForGroupSession;
return $this;
}
/**
* @return Collection|VideoCoursesRegistration[]
*/
public function getVideoCoursesRegistration(): Collection
{
return $this->videoCoursesRegistration;
}
public function addVideoCoursesStudent(VideoCoursesRegistration $videoCoursesRegistration): self
{
if (!$this->videoCoursesRegistration->contains($videoCoursesRegistration)) {
$this->videoCoursesRegistration[] = $videoCoursesRegistration;
$videoCoursesRegistration->setUser($this);
}
return $this;
}
public function removeVideoCoursesStudent(VideoCoursesRegistration $videoCoursesRegistration): self
{
if ($this->videoCoursesRegistration->contains($videoCoursesRegistration)) {
$this->videoCoursesRegistration->removeElement($videoCoursesRegistration);
// set the owning side to null (unless already changed)
if ($videoCoursesRegistration->getUser() === $this) {
$videoCoursesRegistration->setUser(null);
}
}
return $this;
}
/**
* @return Collection|Notifications[]
*/
public function getNotifications(): Collection
{
return $this->notifications;
}
public function addNotification(Notifications $notification): self
{
if (!$this->notifications->contains($notification)) {
$this->notifications[] = $notification;
$notification->setUserAccount($this);
}
return $this;
}
public function removeNotification(Notifications $notification): self
{
if ($this->notifications->contains($notification)) {
$this->notifications->removeElement($notification);
// set the owning side to null (unless already changed)
if ($notification->getUserAccount() === $this) {
$notification->setUserAccount(null);
}
}
return $this;
}
/**
* @return Collection|TicketOrder[]
*/
public function getTicketOrders(): Collection
{
return $this->ticketOrders;
}
public function addTicketOrder(TicketOrder $ticketOrder): self
{
if (!$this->ticketOrders->contains($ticketOrder)) {
$this->ticketOrders[] = $ticketOrder;
$ticketOrder->setUser($this);
}
return $this;
}
public function removeTicketOrder(TicketOrder $ticketOrder): self
{
if ($this->ticketOrders->contains($ticketOrder)) {
$this->ticketOrders->removeElement($ticketOrder);
// set the owning side to null (unless already changed)
if ($ticketOrder->getUser() === $this) {
$ticketOrder->setUser(null);
}
}
return $this;
}
/**
* @return Collection|UserPlacementTest[]
*/
public function getUserPlacementTests(): Collection
{
return $this->userPlacementTests;
}
public function addUserPlacementTest(UserPlacementTest $userPlacementTest): self
{
if (!$this->userPlacementTests->contains($userPlacementTest)) {
$this->userPlacementTests[] = $userPlacementTest;
$userPlacementTest->setUser($this);
}
return $this;
}
public function removeUserPlacementTest(UserPlacementTest $userPlacementTest): self
{
if ($this->userPlacementTests->removeElement($userPlacementTest)) {
// set the owning side to null (unless already changed)
if ($userPlacementTest->getUser() === $this) {
$userPlacementTest->setUser(null);
}
}
return $this;
}
/**
* @return Collection|Exam[]
*/
public function getExams(): Collection
{
return $this->exams;
}
public function addExam(Exam $exam): self
{
if (!$this->exams->contains($exam)) {
$this->exams[] = $exam;
$exam->setUser($this);
}
return $this;
}
public function removeExam(Exam $exam): self
{
if ($this->exams->removeElement($exam)) {
// set the owning side to null (unless already changed)
if ($exam->getUser() === $this) {
$exam->setUser(null);
}
}
return $this;
}
/**
* @return Collection|TrainingReport[]
*/
public function getTrainingReports(): Collection
{
return $this->trainingReports;
}
public function addTrainingReport(TrainingReport $trainingReport): self
{
if (!$this->trainingReports->contains($trainingReport)) {
$this->trainingReports[] = $trainingReport;
$trainingReport->setUser($this);
}
return $this;
}
public function removeTrainingReport(TrainingReport $trainingReport): self
{
if ($this->trainingReports->removeElement($trainingReport)) {
// set the owning side to null (unless already changed)
if ($trainingReport->getUser() === $this) {
$trainingReport->setUser(null);
}
}
return $this;
}
public function getCountry(): ?CountryInfo
{
return $this->country;
}
public function setCountry(?CountryInfo $country): self
{
$this->country = $country;
return $this;
}
}