src/Entity/User.php line 18

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use Doctrine\Common\Collections\ArrayCollection;
  4. use Doctrine\Common\Collections\Collection;
  5. use Doctrine\ORM\Mapping as ORM;
  6. use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
  7. use Symfony\Component\Validator\Constraints as Assert;
  8. use Symfony\Component\Security\Core\User\UserInterface;
  9. /**
  10.  * @ORM\Table(name="user")
  11.  * @ORM\Entity(repositoryClass="App\Repository\UserRepository")
  12.  * @ORM\HasLifecycleCallbacks()
  13.  * @UniqueEntity("email")
  14.  */
  15. class User implements UserInterface, \Serializable
  16. {
  17.     public const ROLE_ADMIN 'ROLE_ADMIN';
  18.     public const ROLE_RH 'ROLE_RH';
  19.     public const ROLE_USER_ACTIF 'ROLE_USER_ACTIF';
  20.     public const ROLE_USER_INACTIF 'ROLE_USER_INACTIF';
  21.     /**
  22.      * @ORM\Id
  23.      * @ORM\GeneratedValue
  24.      * @ORM\Column(type="integer")
  25.      */
  26.     private $id;
  27.     /**
  28.      * @Assert\Length(max=50,min=6,minMessage="Le mot de passe doit faire minimum {{ limit }} caractères.")
  29.      */
  30.     private $plainPassword;
  31.     /**
  32.      * @ORM\Column(type="string", length=255, nullable=true)
  33.      */
  34.     private $password;
  35.     /**
  36.      * @ORM\Column(type="string", length=60, unique=true)
  37.      * @Assert\Email
  38.      */
  39.     private $email;
  40.     /**
  41.      * @ORM\ManyToOne(targetEntity="Company", inversedBy="users", fetch="EAGER")
  42.      * @ORM\JoinColumn(name="company_id", referencedColumnName="id")
  43.      */
  44.     private $company;
  45.     /**
  46.      * @ORM\ManyToOne(targetEntity="Role", fetch="EAGER")
  47.      * @ORM\JoinColumn(name="role_id", referencedColumnName="id")
  48.      */
  49.     private $roles;
  50.     /**
  51.      * @ORM\Column(type="string", length=90, nullable=true)
  52.      */
  53.     private $firstname;
  54.     /**
  55.      * @ORM\Column(type="string", length=90, nullable=true)
  56.      */
  57.     private $lastname;
  58.     /**
  59.      * @ORM\Column(type="date", nullable=true)
  60.      */
  61.     private $birth;
  62.     /**
  63.      * @ORM\Column(type="string", length=2, nullable=true)
  64.      */
  65.     private $gender;
  66.     /**
  67.      * @ORM\Column(type="integer", nullable=true)
  68.      */
  69.     private $weight null;
  70.     /**
  71.      * @ORM\Column(type="float", nullable=true)
  72.      */
  73.     private $height null;
  74.     /**
  75.      * @ORM\Column(type="json", nullable=true)
  76.      */
  77.     private $punctual_sport;
  78.     /**
  79.      * @ORM\Column(type="boolean", nullable=true)
  80.      */
  81.     private $work_handicapped null;
  82.     /**
  83.      * @ORM\Column(type="datetime", nullable=true, options={"default": "CURRENT_TIMESTAMP"})
  84.      */
  85.     private $createdAt;
  86.     /**
  87.      * @ORM\Column(type="datetime", nullable=true, options={"default": "CURRENT_TIMESTAMP"})
  88.      */
  89.     private $updatedAt;
  90.     /**
  91.      * @ORM\Column(type="datetime", nullable=true, options={"default": "CURRENT_TIMESTAMP"})
  92.      */
  93.     private $updatedDataConfirmedAt;
  94.     /**
  95.      * @ORM\OneToMany(targetEntity="App\Entity\UserActivity", mappedBy="user", cascade={"persist","remove"})
  96.      */
  97.     private $userActivities;
  98.     /**
  99.      * @ORM\OneToMany(targetEntity=FormationRegistration::class, mappedBy="User",cascade={"remove"})
  100.      */
  101.     private $formations;
  102.     /**
  103.      * @ORM\OneToMany(targetEntity=Formation::class, mappedBy="owner", cascade={"remove"})
  104.      */
  105.     private $ownedFormations;
  106.     /**
  107.      * @ORM\OneToMany(targetEntity=UserFavorites::class, mappedBy="user",cascade={"remove"})
  108.      */
  109.     private $favorites;
  110.     /**
  111.      * @ORM\OneToMany(targetEntity=Notification::class, mappedBy="userTo",cascade={"remove"})
  112.      */
  113.     private $notifications;
  114.     /**
  115.      * @ORM\Column(type="boolean", options={"default": "0"} )
  116.      */
  117.     private $intro false;
  118.     /**
  119.      * @ORM\Column(type="boolean", options={"default": "0"} )
  120.      */
  121.     private $cgu false;
  122.     /**
  123.      * @ORM\OneToMany(targetEntity=Log::class, mappedBy="user", cascade={"remove"})
  124.      */
  125.     private $logs;
  126.     /**
  127.      * @ORM\Column(type="boolean", nullable=true)
  128.      */
  129.     private $isContact;
  130.     /**
  131.      * @ORM\Column(type="datetime", nullable=true, options={"default": null})
  132.      */
  133.     private $lastLoginAt;
  134.     /**
  135.      * @ORM\Column(type="string", length=255, nullable=true)
  136.      */
  137.     private $keycloakId;
  138.     /**
  139.      * @ORM\Column(type="datetime", nullable=true)
  140.      */
  141.     private $agreeTermsAt;
  142.     /**
  143.      * @ORM\Column(type="datetime", nullable=true)
  144.      */
  145.     private $agreePrivateDataAt;
  146.     public function __construct()
  147.     {
  148.         $this->userActivities = new ArrayCollection();
  149.         $this->formations = new ArrayCollection();
  150.         $this->ownedFormations = new ArrayCollection();
  151.         $this->notifications = new ArrayCollection();
  152.         $this->logs = new ArrayCollection();
  153.     }
  154.     /**
  155.      * @return mixed
  156.      */
  157.     public function getId()
  158.     {
  159.         return $this->id;
  160.     }
  161.     /**
  162.      * @return mixed
  163.      */
  164.     public function getFirstname()
  165.     {
  166.         return $this->firstname;
  167.     }
  168.     /**
  169.      * @param mixed $firstname
  170.      */
  171.     public function setFirstname($firstname)
  172.     {
  173.         $this->firstname $firstname;
  174.     }
  175.     /**
  176.      * @return mixed
  177.      */
  178.     public function getLastname()
  179.     {
  180.         return $this->lastname;
  181.     }
  182.     /**
  183.      * @param mixed $lastname
  184.      */
  185.     public function setLastname($lastname)
  186.     {
  187.         $this->lastname $lastname;
  188.     }
  189.     /**
  190.      * @return mixed
  191.      */
  192.     public function getBirth()
  193.     {
  194.         return $this->birth;
  195.     }
  196.     /**
  197.      * @param mixed $birth
  198.      */
  199.     public function setBirth($birth)
  200.     {
  201.         $this->birth $birth;
  202.     }
  203.     /**
  204.      * @return mixed
  205.      */
  206.     public function getGender()
  207.     {
  208.         return $this->gender;
  209.     }
  210.     /**
  211.      * @param mixed $gender
  212.      */
  213.     public function setGender($gender)
  214.     {
  215.         $this->gender $gender;
  216.     }
  217.     /**
  218.      * @return mixed
  219.      */
  220.     public function getWeight()
  221.     {
  222.         return $this->weight;
  223.     }
  224.     /**
  225.      * @param mixed $weight
  226.      */
  227.     public function setWeight($weight)
  228.     {
  229.         $this->weight $weight;
  230.     }
  231.     /**
  232.      * @return mixed
  233.      */
  234.     public function getHeight()
  235.     {
  236.         return $this->height;
  237.     }
  238.     /**
  239.      * @param mixed $height
  240.      */
  241.     public function setHeight($height)
  242.     {
  243.         $this->height $height;
  244.     }
  245.     /**
  246.      * @return mixed
  247.      */
  248.     public function getCompany()
  249.     {
  250.         return $this->company;
  251.     }
  252.     /**
  253.      * @param mixed $company
  254.      */
  255.     public function setCompany($company)
  256.     {
  257.         $this->company $company;
  258.     }
  259.     /**
  260.      * @return mixed
  261.      */
  262.     public function getEmail()
  263.     {
  264.         return $this->email;
  265.     }
  266.     /**
  267.      * Returns the roles granted to the user.
  268.      *
  269.      * <code>
  270.      * public function getRoles()
  271.      * {
  272.      *     return array('ROLE_USER_ACTIF');
  273.      * }
  274.      * </code>
  275.      *
  276.      * Alternatively, the roles might be stored on a ``roles`` property,
  277.      * and populated in any number of different ways when the user object
  278.      * is created.
  279.      *
  280.      * @return (Role|string)[] The user roles
  281.      */
  282.     public function getRoles()
  283.     {
  284.         return $this->roles ? [$this->roles->getName()] : [];
  285.     }
  286.     public static function getStandardRoleNames(): array
  287.     {
  288.         return [
  289.             self::ROLE_USER_ACTIF,
  290.             self::ROLE_USER_INACTIF,
  291.         ];
  292.     }
  293.     public static function getAssignableRoleNames(): array
  294.     {
  295.         return array_merge(self::getStandardRoleNames(), [self::ROLE_RH]);
  296.     }
  297.     public static function getStandardAndManagerRoleNames(): array
  298.     {
  299.         return array_merge(self::getStandardRoleNames(), [self::ROLE_RH]);
  300.     }
  301.     public function isStandardUser(): bool
  302.     {
  303.         return in_array($this->getRoles()[0], self::getStandardRoleNames(), true);
  304.     }
  305.     public function getRoleLabel(): string
  306.     {
  307.         switch ($this->getRoles()[0]) {
  308.             case self::ROLE_USER_ACTIF:
  309.                 return 'Utilisateur actif';
  310.             case self::ROLE_USER_INACTIF:
  311.                 return 'Utilisateur non actif';
  312.             case self::ROLE_RH:
  313.                 return 'Gestionnaire';
  314.             case self::ROLE_ADMIN:
  315.                 return 'Administrateur';
  316.             default:
  317.                 return $this->getRoles()[0];
  318.         }
  319.     }
  320.     /**
  321.      * @param string|Role $role
  322.      * @return bool
  323.      */
  324.     public function hasRole($role)
  325.     {
  326.         $roles $this->getRoles();
  327.         foreach ($roles as $_role) {
  328.             if($_role == (is_string($role) ? $role $role->getName()))
  329.                 return true;
  330.         }
  331.         return false;
  332.     }
  333.     /**
  334.      * @return Collection|UserActivity[]
  335.      */
  336.     public function getUserActivities(): Collection
  337.     {
  338.         return $this->userActivities;
  339.     }
  340.     public function addUserActivity(UserActivity $userActivity): self
  341.     {
  342.         if (!$this->userActivities->contains($userActivity)) {
  343.             $this->userActivities[] = $userActivity;
  344.             $userActivity->setUser($this);
  345.         }
  346.         return $this;
  347.     }
  348.     public function removeUserActivity(UserActivity $userActivity): self
  349.     {
  350.         if ($this->userActivities->contains($userActivity)) {
  351.             $this->userActivities->removeElement($userActivity);
  352.             // set the owning side to null (unless already changed)
  353.             if ($userActivity->getUser() === $this) {
  354.                 $userActivity->setUser(null);
  355.             }
  356.         }
  357.         return $this;
  358.     }
  359.     /** Entité associée au compte, distincte des noms retournés pour la sécurité. */
  360.     public function getRole(): ?Role
  361.     {
  362.         return $this->roles;
  363.     }
  364.     public function setRole(?Role $role): void
  365.     {
  366.         $this->roles $role;
  367.     }
  368.     /**
  369.      * @param mixed $roles
  370.      */
  371.     public function setRoles(Role $roles)
  372.     {
  373.         $this->roles $roles;
  374.     }
  375.     /**
  376.      * Returns the password used to authenticate the user.
  377.      *
  378.      * This should be the encoded password. On authentication, a plain-text
  379.      * password will be salted, encoded, and then compared to this value.
  380.      *
  381.      * @return string The password
  382.      */
  383.     public function getPassword()
  384.     {
  385.         return $this->password;
  386.     }
  387.     /**
  388.      * Returns the salt that was originally used to encode the password.
  389.      *
  390.      * This can return null if the password was not encoded using a salt.
  391.      *
  392.      * @return string|null The salt
  393.      */
  394.     public function getSalt()
  395.     {
  396.         return null;
  397.     }
  398.     /**
  399.      * Returns the username used to authenticate the user.
  400.      *
  401.      * @return string The username
  402.      */
  403.     public function getUsername()
  404.     {
  405.         return $this->getEmail();
  406.     }
  407.     /**
  408.      * @param mixed $password
  409.      */
  410.     public function setPassword($password)
  411.     {
  412.         $this->password $password;
  413.     }
  414.     /**
  415.      * @param mixed $email
  416.      */
  417.     public function setEmail($email)
  418.     {
  419.         $this->email $email;
  420.     }
  421.     /**
  422.      * @return mixed
  423.      */
  424.     public function getCreatedAt()
  425.     {
  426.         return $this->createdAt;
  427.     }
  428.     /**
  429.      * @param mixed $createdAt
  430.      */
  431.     public function setCreatedAt($createdAt): void
  432.     {
  433.         $this->createdAt $createdAt;
  434.     }
  435.     /**
  436.      * @return mixed
  437.      */
  438.     public function getUpdatedAt()
  439.     {
  440.         return $this->updatedAt;
  441.     }
  442.     /**
  443.      * @param mixed $updatedAt
  444.      */
  445.     public function setUpdatedAt($updatedAt): void
  446.     {
  447.         $this->updatedAt $updatedAt;
  448.     }
  449.     /**
  450.      * Removes sensitive data from the user.
  451.      *
  452.      * This is important if, at any given point, sensitive information like
  453.      * the plain-text password is stored on this object.
  454.      */
  455.     public function eraseCredentials()
  456.     {
  457.         // TODO: Implement eraseCredentials() method.
  458.     }
  459.     /**
  460.      * String representation of object
  461.      * @link http://php.net/manual/en/serializable.serialize.php
  462.      * @return string the string representation of the object or null
  463.      * @since 5.1.0
  464.      */
  465.     public function serialize()
  466.     {
  467.         return serialize(array(
  468.             $this->id,
  469.             $this->email,
  470.             $this->password,
  471.             $this->roles,
  472.             // see section on salt below
  473.             // $this->salt,
  474.         ));
  475.     }
  476.     /**
  477.      * Constructs the object
  478.      * @link http://php.net/manual/en/serializable.unserialize.php
  479.      * @param string $serialized <p>
  480.      * The string representation of the object.
  481.      * </p>
  482.      * @return void
  483.      * @since 5.1.0
  484.      */
  485.     public function unserialize($serialized)
  486.     {
  487.         list(
  488.             $this->id,
  489.             $this->email,
  490.             $this->password,
  491.             $this->roles,
  492.             // see section on salt below
  493.             // $this->salt
  494.         ) = unserialize($serialized);
  495.     }
  496.     /** @ORM\PrePersist */
  497.     public function onPrePersist()
  498.     {
  499.         $this->createdAt = new \DateTime("now", new \DateTimeZone("Europe/Paris"));
  500.         $this->updatedAt = new \DateTime("now", new \DateTimeZone("Europe/Paris"));
  501.     }
  502.     /** @ORM\PreUpdate */
  503.     public function onPreUpdate()
  504.     {
  505.         $this->updatedAt = new \DateTime("now", new \DateTimeZone("Europe/Paris"));
  506.     }
  507.     /**
  508.      * @return mixed
  509.      */
  510.     public function getPlainPassword()
  511.     {
  512.         return $this->plainPassword;
  513.     }
  514.     /**
  515.      * @param mixed $plainPassword
  516.      */
  517.     public function setPlainPassword($plainPassword): void
  518.     {
  519.         $this->plainPassword $plainPassword;
  520.     }
  521.     /**
  522.      * @return Collection|FormationRegistration[]
  523.      */
  524.     public function getFormations(): Collection
  525.     {
  526.         return $this->formations;
  527.     }
  528.     public function addFormation(FormationRegistration $formation): self
  529.     {
  530.         if (!$this->formations->contains($formation)) {
  531.             $this->formations[] = $formation;
  532.             $formation->setUser($this);
  533.         }
  534.         return $this;
  535.     }
  536.     public function removeFormation(FormationRegistration $formation): self
  537.     {
  538.         if ($this->formations->removeElement($formation)) {
  539.             // set the owning side to null (unless already changed)
  540.             if ($formation->getUser() === $this) {
  541.                 $formation->setUser(null);
  542.             }
  543.         }
  544.         return $this;
  545.     }
  546.     public function getOwnedFormations(): Collection
  547.     {
  548.         return $this->ownedFormations;
  549.     }
  550.     public function addOwnedFormation(Formation $formation): self
  551.     {
  552.         if (!$this->ownedFormations->contains($formation)) {
  553.             $this->ownedFormations[] = $formation;
  554.             $formation->setOwner($this);
  555.         }
  556.         return $this;
  557.     }
  558.     public function removeOwnedFormation(Formation $formation): self
  559.     {
  560.         if ($this->ownedFormations->removeElement($formation)) {
  561.             if ($formation->getOwner() === $this) {
  562.                 $formation->setOwner(null);
  563.             }
  564.         }
  565.         return $this;
  566.     }
  567.     /**
  568.      * @return Collection|Notification[]
  569.      */
  570.     public function getNotifications(): Collection
  571.     {
  572.         return $this->notifications;
  573.     }
  574.     public function addNotification(Notification $notification): self
  575.     {
  576.         if (!$this->notifications->contains($notification)) {
  577.             $this->notifications[] = $notification;
  578.             $notification->setUserTo($this);
  579.         }
  580.         return $this;
  581.     }
  582.     public function removeNotification(Notification $notification): self
  583.     {
  584.         if ($this->notifications->removeElement($notification)) {
  585.             // set the owning side to null (unless already changed)
  586.             if ($notification->getUserTo() === $this) {
  587.                 $notification->setUserTo(null);
  588.             }
  589.         }
  590.         return $this;
  591.     }
  592.     /**
  593.      * @return bool
  594.      */
  595.     public function isIntro(): bool
  596.     {
  597.         return $this->intro;
  598.     }
  599.     /**
  600.      * @param bool $intro
  601.      */
  602.     public function setIntro(bool $intro): void
  603.     {
  604.         $this->intro $intro;
  605.     }
  606.     /**
  607.      * @return bool
  608.      */
  609.     public function getCgu(): bool
  610.     {
  611.         return $this->cgu;
  612.     }
  613.     /**
  614.      * @param bool $cgu
  615.      */
  616.     public function setCgu(bool $cgu): void
  617.     {
  618.         $this->cgu $cgu;
  619.     }
  620.     /**
  621.      * @return null
  622.      */
  623.     public function getWorkHandicapped()
  624.     {
  625.         return $this->work_handicapped;
  626.     }
  627.     /**
  628.      * @param null $work_handicapped
  629.      */
  630.     public function setWorkHandicapped($work_handicapped): void
  631.     {
  632.         $this->work_handicapped $work_handicapped;
  633.     }
  634.     /**
  635.      * @return
  636.      */
  637.     public function getPunctualSport()
  638.     {
  639.         return $this->punctual_sport;
  640.     }
  641.     /**
  642.      * @param $punctual_sport
  643.      */
  644.     public function setPunctualSport($punctual_sport): void
  645.     {
  646.         $this->punctual_sport $punctual_sport;
  647.     }
  648.     /**
  649.      * @return mixed
  650.      */
  651.     public function getUpdatedDataConfirmedAt()
  652.     {
  653.         return $this->updatedDataConfirmedAt;
  654.     }
  655.     /**
  656.      * @param mixed $updatedDataConfirmedAt
  657.      */
  658.     public function setUpdatedDataConfirmedAt($updatedDataConfirmedAt): void
  659.     {
  660.         $this->updatedDataConfirmedAt $updatedDataConfirmedAt;
  661.     }
  662.     public function getIsContact(): ?bool
  663.     {
  664.         return $this->isContact;
  665.     }
  666.     public function setIsContact(?bool $isContact): self
  667.     {
  668.         $this->isContact $isContact;
  669.         return $this;
  670.     }
  671.     /**
  672.      * @return mixed
  673.      */
  674.     public function getLastLoginAt()
  675.     {
  676.         return $this->lastLoginAt;
  677.     }
  678.     /**
  679.      * @param mixed $lastLoginAt
  680.      */
  681.     public function setLastLoginAt($lastLoginAt): void
  682.     {
  683.         $this->lastLoginAt $lastLoginAt;
  684.     }
  685.     //    /**
  686. //     * @ORM\PrePersist
  687. //     * @ORM\PreUpdate
  688. //     */
  689. //    public function updatedTimestamps(): void
  690. //    {
  691. //        $this->setUpdatedDataConfirmedAt(new \DateTime());
  692. //    }
  693.     /**
  694.      * @return mixed
  695.      */
  696.     public function getKeycloakId()
  697.     {
  698.         return $this->keycloakId;
  699.     }
  700.     /**
  701.      * @param mixed $keycloakId
  702.      */
  703.     public function setKeycloakId($keycloakId): void
  704.     {
  705.         $this->keycloakId $keycloakId;
  706.     }
  707.     /**
  708.      * @return mixed
  709.      */
  710.     public function getAgreeTermsAt()
  711.     {
  712.         return $this->agreeTermsAt;
  713.     }
  714.     /**
  715.      * @param mixed $agreeTermsAt
  716.      */
  717.     public function setAgreeTermsAt($agreeTermsAt): void
  718.     {
  719.         $this->agreeTermsAt $agreeTermsAt;
  720.     }
  721.     /**
  722.      * @return mixed
  723.      */
  724.     public function getAgreePrivateDataAt()
  725.     {
  726.         return $this->agreePrivateDataAt;
  727.     }
  728.     /**
  729.      * @param mixed $agreePrivateDataAt
  730.      */
  731.     public function setAgreePrivateDataAt($agreePrivateDataAt): void
  732.     {
  733.         $this->agreePrivateDataAt $agreePrivateDataAt;
  734.     }
  735. }