src/Entity/User.php line 19

  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\DBAL\Types\Types;
  7. use Doctrine\ORM\Mapping as ORM;
  8. use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
  9. use Symfony\Component\Security\Core\User\PasswordAuthenticatedUserInterface;
  10. use Symfony\Component\Security\Core\User\UserInterface;
  11. #[ORM\Entity(repositoryClassUserRepository::class)]
  12. #[ORM\Table(name'`user`')]
  13. #[UniqueEntity(fields: ['email'], message'There is already an account with this email')]
  14. # [UniqueEntity(fields: ['username'], message: 'There is already an account with this username')]
  15. class User implements UserInterfacePasswordAuthenticatedUserInterface
  16. {
  17.     public const ROLE_USER "ROLE_USER";
  18.     public const ROLE_MEMBER "ROLE_MEMBER";
  19.     public const ROLE_ADMIN "ROLE_ADMIN";
  20.     public const ROLE_SUPER_ADMIN "ROLE_SUPER_ADMIN";
  21.     const STATUS_DRAFT 1;
  22.     const STATUS_VALID 2;
  23.     const STATUS_FAILED 3;
  24.     const STATUS_WAITING 4;
  25.     const STATUS_REFUSED 5// ce status est ajouté pour le caas de refus d'administrateur
  26.     const STATUS_PAYMENT_PENDING "Pending";
  27.     const STATUS_PAYMENT_SUCCESS "Success";
  28.     const STATUS_PAYMENT_FAILED "Failed";
  29.     const NO_MEMBERSHIP_REQUEST=0;
  30.     const MEMBERSHIP_REQUEST_PENDING=1;
  31.     const MEMBERSHIP_REQUEST_ACCEPTED=2;
  32.     const SEXE_HOMME 1;
  33.     const SEXE_FEMME 2;
  34.     // const CV_MARRIED = 1;
  35.     // const CV_SINGLE = 2;
  36.     const CV_MR 1;
  37.     const CV_MME 2;
  38.     const CV_MLLE 3;
  39.     #[ORM\Id]
  40.     #[ORM\GeneratedValue]
  41.     #[ORM\Column]
  42.     private ?int $id null;
  43.     #[ORM\Column(length180uniquetrue)]
  44.     private ?string $username null;
  45.     #[ORM\Column(nullabletrue)]
  46.     private array $roles = [];
  47.     /**
  48.      * @var string The hashed password
  49.      */
  50.     #[ORM\Column]
  51.     private ?string $password null;
  52.     #[ORM\Column(length255)]
  53.     private ?string $firstname null;
  54.     #[ORM\Column(length255)]
  55.     private ?string $lastname null;
  56.     #[ORM\Column(length255)]
  57.     private ?string $email null;
  58.     #[ORM\Column]
  59.     private ?bool $status null;
  60.     #[ORM\Column(length255)]
  61.     private ?string $title null;
  62.     #[ORM\Column(typeTypes::SMALLINTnullabletrue)]
  63.     private ?int $civility null;
  64.     #[ORM\Column(typeTypes::SMALLINT)]
  65.     private ?int $sexe null;
  66.     #[ORM\Column(length200)]
  67.     private ?string $country null;
  68.     #[ORM\Column(length400)]
  69.     private ?string $adresse null;
  70.     #[ORM\Column(length255)]
  71.     private ?string $city null;
  72.     #[ORM\Column(nullabletrue)]
  73.     private ?int $postalCode null;
  74.     #[ORM\Column(length255)]
  75.     private ?string $workplace null;
  76.     #[ORM\Column(length20)]
  77.     private ?string $mobile null;
  78.     #[ORM\Column(length20nullabletrue)]
  79.     private ?string $phone null;
  80.     #[ORM\Column(length255)]
  81.     private ?string $speciality null;
  82.     #[ORM\Column(length255)]
  83.     private ?string $activity null;
  84.     #[ORM\OneToMany(mappedBy'user'targetEntityResetPassword::class)]
  85.     private Collection $resetPasswords;
  86.     #[ORM\OneToMany(mappedBy'user'targetEntityInscription::class)]
  87.     private Collection $inscriptions;
  88.     #[ORM\OneToOne(mappedBy'user'targetEntityParticipant::class)]
  89.     private ?Participant $participant;
  90.     #[ORM\Column(type'datetime')]
  91.     private $createdAt;
  92.     #[ORM\Column(type'datetime'nullabletrue)]
  93.     private $updatedAt;
  94.     #[ORM\Column(type'boolean')]
  95.     private $isVerified false;
  96.     #[ORM\Column(nullabletrue)]
  97.     private ?int $countryIdentifier null;
  98.     #[ORM\Column(typeTypes::DATETIME_MUTABLEnullabletrue)]
  99.     private ?\DateTimeInterface $expirationDate null;
  100.     #[ORM\Column(length255nullabletrue)]
  101.     private ?string $token null;
  102.     /** @var EventAbstract[]|ArrayCollection */
  103.     #[ORM\OneToMany(targetEntityEventAbstract::class, mappedBy'user')]
  104.     private Collection $eventAbstracts;
  105.     #[ORM\Column(typeTypes::BOOLEAN)]
  106.     private ?bool $isMember false;
  107.     #[ORM\Column(typeTypes::BOOLEAN)]
  108.     private ?bool $isMemberShip false;
  109.     #[ORM\Column(typeTypes::JSONoptions:[])] // 'default' => "[]"
  110.     private ?array $memberYears = [];
  111.     #[ORM\Column(typeTypes::DATETIME_MUTABLEnullabletrue)]
  112.     private ?\DateTime $lastLoginAt;
  113.     #[ORM\Column(typeTypes::INTEGERnullabletrueoptions: ['default' => 0])]
  114.     private ?int $demandeMembership null;
  115.     #[ORM\Column(typeTypes::DATETIME_MUTABLEnullabletrue)]
  116.     private ?\DateTime $demandeMembershipAt null;
  117.     public function __construct()
  118.     {
  119.         $this->resetPasswords = new ArrayCollection();
  120.         $this->inscriptions = new ArrayCollection();
  121.         $this->eventAbstracts = new ArrayCollection();
  122.         $this->participant null;
  123.         $this->isMember false;
  124.         $this->isMemberShip false;
  125.         $this->memberYears = [];
  126.         $this->demandeMembership=self::NO_MEMBERSHIP_REQUEST;
  127.         $this->lastLoginAt null;
  128.     }
  129.     public function getId(): ?int
  130.     {
  131.         return $this->id;
  132.     }
  133.     public function getUsername(): ?string
  134.     {
  135.         return $this->username;
  136.     }
  137.     public function setUsername(string $username): self
  138.     {
  139.         $this->username $username;
  140.         return $this;
  141.     }
  142.     /**
  143.      * A visual identifier that represents this user.
  144.      *
  145.      * @see UserInterface
  146.      */
  147.     public function getUserIdentifier(): string
  148.     {
  149.         return (string) $this->username;
  150.     }
  151.     /**
  152.      * @see UserInterface
  153.      */
  154.     public function getRoles(): array
  155.     {
  156.         $roles $this->roles;
  157.         // guarantee every user at least has ROLE_USER
  158.         $roles[] = 'ROLE_USER';
  159.         return array_unique($roles);
  160.     }
  161.     public function setRoles(array $roles): self
  162.     {
  163.         $this->roles $roles;
  164.         return $this;
  165.     }
  166.     public function hasRole(string $role): bool
  167.     {
  168.         if ($role && $this->getRoles()) {
  169.             return in_array($role$this->getRoles());
  170.         }
  171.         return false;
  172.     }
  173.     /**
  174.      * @see PasswordAuthenticatedUserInterface
  175.      */
  176.     public function getPassword(): string
  177.     {
  178.         return $this->password;
  179.     }
  180.     public function setPassword(string $password): self
  181.     {
  182.         $this->password $password;
  183.         return $this;
  184.     }
  185.     /**
  186.      * @see UserInterface
  187.      */
  188.     public function eraseCredentials()
  189.     {
  190.         // If you store any temporary, sensitive data on the user, clear it here
  191.         // $this->plainPassword = null;
  192.     }
  193.     public function getFirstname(): ?string
  194.     {
  195.         return $this->firstname;
  196.     }
  197.     public function setFirstname(string $firstname): self
  198.     {
  199.         $this->firstname $firstname;
  200.         return $this;
  201.     }
  202.     public function getLastname(): ?string
  203.     {
  204.         return $this->lastname;
  205.     }
  206.     public function setLastname(string $lastname): self
  207.     {
  208.         $this->lastname $lastname;
  209.         return $this;
  210.     }
  211.     public function getEmail(): ?string
  212.     {
  213.         return $this->email;
  214.     }
  215.     public function setEmail(string $email): self
  216.     {
  217.         $this->email $email;
  218.         return $this;
  219.     }
  220.     public function getTitle(): ?string
  221.     {
  222.         return $this->title;
  223.     }
  224.     public function setTitle(string $title): self
  225.     {
  226.         $this->title $title;
  227.         return $this;
  228.     }
  229.     public function isTitleResidant(): bool
  230.     {
  231.         return $this->title && $this->title == AppConstants::TITLE_RESIDENT;
  232.     }
  233.     public function getSexe(): ?int
  234.     {
  235.         return $this->sexe;
  236.     }
  237.     public function setSexe(int $sexe): self
  238.     {
  239.         $this->sexe $sexe;
  240.         return $this;
  241.     }
  242.     public function getCountry(): ?string
  243.     {
  244.         return $this->country;
  245.     }
  246.     public function setCountry(string $country): self
  247.     {
  248.         $this->country $country;
  249.         return $this;
  250.     }
  251.     public function getAdresse(): ?string
  252.     {
  253.         return $this->adresse;
  254.     }
  255.     public function setAdresse(string $adresse): self
  256.     {
  257.         $this->adresse $adresse;
  258.         return $this;
  259.     }
  260.     public function getCity(): ?string
  261.     {
  262.         return $this->city;
  263.     }
  264.     public function setCity(string $city): self
  265.     {
  266.         $this->city $city;
  267.         return $this;
  268.     }
  269.     public function getPostalCode(): ?int
  270.     {
  271.         return $this->postalCode;
  272.     }
  273.     public function setPostalCode(int $postalCode): self
  274.     {
  275.         $this->postalCode $postalCode;
  276.         return $this;
  277.     }
  278.     public function getWorkplace(): ?string
  279.     {
  280.         return $this->workplace;
  281.     }
  282.     public function setWorkplace(string $workplace): self
  283.     {
  284.         $this->workplace $workplace;
  285.         return $this;
  286.     }
  287.     public function getMobile(): ?string
  288.     {
  289.         return $this->mobile;
  290.     }
  291.     public function setMobile(string $mobile): self
  292.     {
  293.         $this->mobile $mobile;
  294.         return $this;
  295.     }
  296.     public function getPhone(): ?string
  297.     {
  298.         return $this->phone;
  299.     }
  300.     public function setPhone(string $phone): self
  301.     {
  302.         $this->phone $phone;
  303.         return $this;
  304.     }
  305.     public function getSpeciality(): ?string
  306.     {
  307.         return $this->speciality;
  308.     }
  309.     public function setSpeciality(string $speciality): self
  310.     {
  311.         $this->speciality $speciality;
  312.         return $this;
  313.     }
  314.     public function getActivity(): ?string
  315.     {
  316.         return $this->activity;
  317.     }
  318.     public function setActivity(string $activity): self
  319.     {
  320.         $this->activity $activity;
  321.         return $this;
  322.     }
  323.     public function getCivility(): ?int
  324.     {
  325.         if (is_null($this->civility)) {
  326.             if ($this->sexe == self::SEXE_HOMME) {
  327.                 $this->civility self::CV_MR;
  328.             } elseif ($this->sexe == self::SEXE_FEMME) {
  329.                 $this->civility self::CV_MME;
  330.             }
  331.         }
  332.         return $this->civility;
  333.     }
  334.     public function setCivility(int $civility): self
  335.     {
  336.         $this->civility $civility;
  337.         return $this;
  338.     }
  339.     public function isStatus(): ?bool
  340.     {
  341.         return $this->status;
  342.     }
  343.     public function getStatus(): ?string
  344.     {
  345.         return ($this->status);
  346.     }
  347.     public function setStatus(bool $status): self
  348.     {
  349.         $this->status $status;
  350.         return $this;
  351.     }
  352.     /**
  353.      * @return Collection<int, ResetPassword>
  354.      */
  355.     public function getResetPasswords(): Collection
  356.     {
  357.         return $this->resetPasswords;
  358.     }
  359.     public function addResetPassword(ResetPassword $resetPassword): self
  360.     {
  361.         if (!$this->resetPasswords->contains($resetPassword)) {
  362.             $this->resetPasswords->add($resetPassword);
  363.             $resetPassword->setUser($this);
  364.         }
  365.         return $this;
  366.     }
  367.     public function removeResetPassword(ResetPassword $resetPassword): self
  368.     {
  369.         if ($this->resetPasswords->removeElement($resetPassword)) {
  370.             // set the owning side to null (unless already changed)
  371.             if ($resetPassword->getUser() === $this) {
  372.                 $resetPassword->setUser(null);
  373.             }
  374.         }
  375.         return $this;
  376.     }
  377.     public function getCreatedAt(): ?\DateTimeInterface
  378.     {
  379.         return $this->createdAt;
  380.     }
  381.     public function setCreatedAt(\DateTimeInterface $createdAt): self
  382.     {
  383.         $this->createdAt $createdAt;
  384.         return $this;
  385.     }
  386.     public function getUpdatedAt(): ?\DateTimeInterface
  387.     {
  388.         return $this->updatedAt;
  389.     }
  390.     public function setUpdatedAt(?\DateTimeInterface $updatedAt): self
  391.     {
  392.         $this->updatedAt $updatedAt;
  393.         return $this;
  394.     }
  395.     /**
  396.      * Get the value of inscriptions
  397.      */
  398.     public function getInscriptions(): Collection
  399.     {
  400.         return $this->inscriptions;
  401.     }
  402.     /**
  403.      * Set the value of inscriptions
  404.      */
  405.     public function setInscriptions(Collection $inscriptions): self
  406.     {
  407.         $this->inscriptions $inscriptions;
  408.         return $this;
  409.     }
  410.     public function isVerified(): bool
  411.     {
  412.         return $this->isVerified;
  413.     }
  414.     public function setIsVerified(bool $isVerified): static
  415.     {
  416.         $this->isVerified $isVerified;
  417.         return $this;
  418.     }
  419.     public function getExpirationDate(): ?\DateTimeInterface
  420.     {
  421.         return $this->expirationDate;
  422.     }
  423.     public function setExpirationDate(?\DateTimeInterface $expirationDate): static
  424.     {
  425.         $this->expirationDate $expirationDate;
  426.         return $this;
  427.     }
  428.     public function getToken(): ?string
  429.     {
  430.         return $this->token;
  431.     }
  432.     public function setToken(?string $token): static
  433.     {
  434.         $this->token $token;
  435.         return $this;
  436.     }
  437.     /**
  438.      * @return Collection<int, EventAbstract>
  439.      */
  440.     public function getEventAbstracts(): Collection
  441.     {
  442.         return $this->eventAbstracts;
  443.     }
  444.     public function addEventAbstract(EventAbstract $eventAbstract): static
  445.     {
  446.         if (!$this->eventAbstracts->contains($eventAbstract)) {
  447.             $this->eventAbstracts->add($eventAbstract);
  448.             $eventAbstract->setUser($this);
  449.         }
  450.         return $this;
  451.     }
  452.     public function removeEventAbstract(EventAbstract $eventAbstract): static
  453.     {
  454.         if ($this->eventAbstracts->removeElement($eventAbstract)) {
  455.             // set the owning side to null (unless already changed)
  456.             if ($eventAbstract->getUser() === $this) {
  457.                 $eventAbstract->setUser(null);
  458.             }
  459.         }
  460.         return $this;
  461.     }
  462.     public function getCountryIdentifier(): ?int
  463.     {
  464.         return $this->countryIdentifier;
  465.     }
  466.     public function setCountryIdentifier(?int $countryIdentifier): static
  467.     {
  468.         $this->countryIdentifier $countryIdentifier;
  469.         return $this;
  470.     }
  471.     /**
  472.      * Get the value of isMember
  473.      */
  474.     public function isMember()
  475.     {
  476.         return $this->isMember;
  477.     }
  478.     /**
  479.      * Get the value of isMember
  480.      */
  481.     public function getIsMember()
  482.     {
  483.         return $this->isMember();
  484.     }
  485.     /**
  486.      * Set the value of isMember
  487.      *
  488.      * @return  self
  489.      */
  490.     public function setIsMember($isMember)
  491.     {
  492.         $this->isMember $isMember;
  493.         return $this;
  494.     }
  495.     /**
  496.      * Set the value of isMember
  497.      *
  498.      * @return  self
  499.      */
  500.     public function isMemberShip($year null)
  501.     {
  502.         if (is_null($year)) {
  503.             $year date('Y');
  504.             if ($this->memberYears) {
  505.                 foreach ($this->memberYears as $memberYear) {
  506.                     if (isset($memberYear['year']) && $memberYear['year'] == $year) {
  507.                         return true;
  508.                     }
  509.                 }
  510.             }
  511.         }
  512.         // return $this->isMemberShip;
  513.         return false;
  514.     }
  515.     /**
  516.      * Get the value of isMemberShip
  517.      */
  518.     public function getIsMemberShip()
  519.     {
  520.         return $this->isMemberShip();
  521.     }
  522.     /**
  523.      * Set the value of isMemberShip
  524.      *
  525.      * @return  self
  526.      */
  527.     public function setIsMemberShip($isMemberShip)
  528.     {
  529.         $this->isMemberShip $isMemberShip;
  530.         return $this;
  531.     }
  532.     /**
  533.      * Get the value of memberYears
  534.      */
  535.     public function getMemberYears()
  536.     {
  537.         if (is_null($this->memberYears)) {
  538.             $this->memberYears = [];
  539.         }
  540.         return $this->memberYears;
  541.     }
  542.     /**
  543.      * Set the value of memberYears
  544.      *
  545.      * @return  self
  546.      */
  547.     public function setMemberYears($memberYears = [])
  548.     {
  549.         if (is_null($memberYears)) {
  550.             $memberYears = [];
  551.         }
  552.         $this->memberYears $memberYears;
  553.         return $this;
  554.     }
  555.     /**
  556.      * Get the value of lastLoginAt
  557.      *
  558.      * @return  \DateTime
  559.      */
  560.     public function getLastLoginAt(): ?\DateTime
  561.     {
  562.         return $this->lastLoginAt;
  563.     }
  564.     /**
  565.      * Set the value of lastLoginAt
  566.      *
  567.      * @param  \DateTime  $lastLoginAt
  568.      *
  569.      * @return  self
  570.      */
  571.     public function setLastLoginAt(?\DateTime $lastLoginAt)
  572.     {
  573.         $this->lastLoginAt $lastLoginAt;
  574.         return $this;
  575.     }
  576.     public function getDemandeMembership(): ?int
  577.     {
  578.         return $this->demandeMembership;
  579.     }
  580.     public function setDemandeMembership(?int $demandeMembership): static
  581.     {
  582.         $this->demandeMembership $demandeMembership;
  583.         return $this;
  584.     }
  585.     /**
  586.      * Get the value of demandeMembershipAt
  587.      */
  588.     public function getDemandeMembershipAt(): ?\DateTime
  589.     {
  590.         return $this->demandeMembershipAt;
  591.     }
  592.     /**
  593.      * Set the value of demandeMembershipAt
  594.      *
  595.      * @return  self
  596.      */
  597.     public function setDemandeMembershipAt(?\DateTime $demandeMembershipAt)
  598.     {
  599.         $this->demandeMembershipAt $demandeMembershipAt;
  600.         return $this;
  601.     }
  602. }