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\ManyToOne(targetEntity="App\Entity\Department")
  100.      */
  101.     private $department;
  102.     /**
  103.      * @ORM\OneToMany(targetEntity=FormationRegistration::class, mappedBy="User",cascade={"remove"})
  104.      */
  105.     private $formations;
  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\ManyToOne(targetEntity=Job::class, inversedBy="user")
  128.      */
  129.     private $job;
  130.     /**
  131.      * @ORM\Column(type="boolean", nullable=true)
  132.      */
  133.     private $isContact;
  134.     /**
  135.      * @ORM\Column(type="datetime", nullable=true, options={"default": null})
  136.      */
  137.     private $lastLoginAt;
  138.     /**
  139.      * @ORM\Column(type="string", length=255, nullable=true)
  140.      */
  141.     private $keycloakId;
  142.     /**
  143.      * @ORM\ManyToOne(targetEntity=Site::class, inversedBy="user")
  144.      */
  145.     private $site;
  146.     /**
  147.      * @ORM\Column(type="datetime", nullable=true)
  148.      */
  149.     private $agreeTermsAt;
  150.     /**
  151.      * @ORM\Column(type="datetime", nullable=true)
  152.      */
  153.     private $agreePrivateDataAt;
  154.     public function __construct()
  155.     {
  156.         $this->userActivities = new ArrayCollection();
  157.         $this->formations = new ArrayCollection();
  158.         $this->notifications = new ArrayCollection();
  159.         $this->logs = new ArrayCollection();
  160.     }
  161.     /**
  162.      * @return mixed
  163.      */
  164.     public function getId()
  165.     {
  166.         return $this->id;
  167.     }
  168.     /**
  169.      * @return mixed
  170.      */
  171.     public function getFirstname()
  172.     {
  173.         return $this->firstname;
  174.     }
  175.     /**
  176.      * @param mixed $firstname
  177.      */
  178.     public function setFirstname($firstname)
  179.     {
  180.         $this->firstname $firstname;
  181.     }
  182.     /**
  183.      * @return mixed
  184.      */
  185.     public function getLastname()
  186.     {
  187.         return $this->lastname;
  188.     }
  189.     /**
  190.      * @param mixed $lastname
  191.      */
  192.     public function setLastname($lastname)
  193.     {
  194.         $this->lastname $lastname;
  195.     }
  196.     /**
  197.      * @return mixed
  198.      */
  199.     public function getBirth()
  200.     {
  201.         return $this->birth;
  202.     }
  203.     /**
  204.      * @param mixed $birth
  205.      */
  206.     public function setBirth($birth)
  207.     {
  208.         $this->birth $birth;
  209.     }
  210.     /**
  211.      * @return mixed
  212.      */
  213.     public function getGender()
  214.     {
  215.         return $this->gender;
  216.     }
  217.     /**
  218.      * @param mixed $gender
  219.      */
  220.     public function setGender($gender)
  221.     {
  222.         $this->gender $gender;
  223.     }
  224.     /**
  225.      * @return mixed
  226.      */
  227.     public function getWeight()
  228.     {
  229.         return $this->weight;
  230.     }
  231.     /**
  232.      * @param mixed $weight
  233.      */
  234.     public function setWeight($weight)
  235.     {
  236.         $this->weight $weight;
  237.     }
  238.     /**
  239.      * @return mixed
  240.      */
  241.     public function getHeight()
  242.     {
  243.         return $this->height;
  244.     }
  245.     /**
  246.      * @param mixed $height
  247.      */
  248.     public function setHeight($height)
  249.     {
  250.         $this->height $height;
  251.     }
  252.     /**
  253.      * @return mixed
  254.      */
  255.     public function getCompany()
  256.     {
  257.         return $this->company;
  258.     }
  259.     /**
  260.      * @param mixed $company
  261.      */
  262.     public function setCompany($company)
  263.     {
  264.         $this->company $company;
  265.     }
  266.     /**
  267.      * @return mixed
  268.      */
  269.     public function getEmail()
  270.     {
  271.         return $this->email;
  272.     }
  273.     /**
  274.      * Returns the roles granted to the user.
  275.      *
  276.      * <code>
  277.      * public function getRoles()
  278.      * {
  279.      *     return array('ROLE_USER_ACTIF');
  280.      * }
  281.      * </code>
  282.      *
  283.      * Alternatively, the roles might be stored on a ``roles`` property,
  284.      * and populated in any number of different ways when the user object
  285.      * is created.
  286.      *
  287.      * @return (Role|string)[] The user roles
  288.      */
  289.     public function getRoles()
  290.     {
  291.         return array($this->roles->getName());
  292.     }
  293.     public static function getStandardRoleNames(): array
  294.     {
  295.         return [
  296.             self::ROLE_USER_ACTIF,
  297.             self::ROLE_USER_INACTIF,
  298.         ];
  299.     }
  300.     public static function getAssignableRoleNames(): array
  301.     {
  302.         return array_merge(self::getStandardRoleNames(), [self::ROLE_RH]);
  303.     }
  304.     public static function getStandardAndManagerRoleNames(): array
  305.     {
  306.         return array_merge(self::getStandardRoleNames(), [self::ROLE_RH]);
  307.     }
  308.     public function isStandardUser(): bool
  309.     {
  310.         return in_array($this->getRoles()[0], self::getStandardRoleNames(), true);
  311.     }
  312.     public function getRoleLabel(): string
  313.     {
  314.         switch ($this->getRoles()[0]) {
  315.             case self::ROLE_USER_ACTIF:
  316.                 return 'Utilisateur actif';
  317.             case self::ROLE_USER_INACTIF:
  318.                 return 'Utilisateur non actif';
  319.             case self::ROLE_RH:
  320.                 return 'Gestionnaire';
  321.             case self::ROLE_ADMIN:
  322.                 return 'Administrateur';
  323.             default:
  324.                 return $this->getRoles()[0];
  325.         }
  326.     }
  327.     /**
  328.      * @param string|Role $role
  329.      * @return bool
  330.      */
  331.     public function hasRole($role)
  332.     {
  333.         $roles $this->getRoles();
  334.         foreach ($roles as $_role) {
  335.             if($_role == (is_string($role) ? $role $role->getName()))
  336.                 return true;
  337.         }
  338.         return false;
  339.     }
  340.     /**
  341.      * @return Collection|UserActivity[]
  342.      */
  343.     public function getUserActivities(): Collection
  344.     {
  345.         return $this->userActivities;
  346.     }
  347.     public function addUserActivity(UserActivity $userActivity): self
  348.     {
  349.         if (!$this->userActivities->contains($userActivity)) {
  350.             $this->userActivities[] = $userActivity;
  351.             $userActivity->setUser($this);
  352.         }
  353.         return $this;
  354.     }
  355.     public function removeUserActivity(UserActivity $userActivity): self
  356.     {
  357.         if ($this->userActivities->contains($userActivity)) {
  358.             $this->userActivities->removeElement($userActivity);
  359.             // set the owning side to null (unless already changed)
  360.             if ($userActivity->getUser() === $this) {
  361.                 $userActivity->setUser(null);
  362.             }
  363.         }
  364.         return $this;
  365.     }
  366.     /**
  367.      * @param mixed $roles
  368.      */
  369.     public function setRoles(Role $roles)
  370.     {
  371.         $this->roles $roles;
  372.     }
  373.     /**
  374.      * Returns the password used to authenticate the user.
  375.      *
  376.      * This should be the encoded password. On authentication, a plain-text
  377.      * password will be salted, encoded, and then compared to this value.
  378.      *
  379.      * @return string The password
  380.      */
  381.     public function getPassword()
  382.     {
  383.         return $this->password;
  384.     }
  385.     /**
  386.      * Returns the salt that was originally used to encode the password.
  387.      *
  388.      * This can return null if the password was not encoded using a salt.
  389.      *
  390.      * @return string|null The salt
  391.      */
  392.     public function getSalt()
  393.     {
  394.         return null;
  395.     }
  396.     /**
  397.      * Returns the username used to authenticate the user.
  398.      *
  399.      * @return string The username
  400.      */
  401.     public function getUsername()
  402.     {
  403.         return $this->getEmail();
  404.     }
  405.     /**
  406.      * @param mixed $password
  407.      */
  408.     public function setPassword($password)
  409.     {
  410.         $this->password $password;
  411.     }
  412.     /**
  413.      * @param mixed $email
  414.      */
  415.     public function setEmail($email)
  416.     {
  417.         $this->email $email;
  418.     }
  419.     /**
  420.      * @return mixed
  421.      */
  422.     public function getCreatedAt()
  423.     {
  424.         return $this->createdAt;
  425.     }
  426.     /**
  427.      * @param mixed $createdAt
  428.      */
  429.     public function setCreatedAt($createdAt): void
  430.     {
  431.         $this->createdAt $createdAt;
  432.     }
  433.     /**
  434.      * @return mixed
  435.      */
  436.     public function getUpdatedAt()
  437.     {
  438.         return $this->updatedAt;
  439.     }
  440.     /**
  441.      * @param mixed $updatedAt
  442.      */
  443.     public function setUpdatedAt($updatedAt): void
  444.     {
  445.         $this->updatedAt $updatedAt;
  446.     }
  447.     /**
  448.      * Removes sensitive data from the user.
  449.      *
  450.      * This is important if, at any given point, sensitive information like
  451.      * the plain-text password is stored on this object.
  452.      */
  453.     public function eraseCredentials()
  454.     {
  455.         // TODO: Implement eraseCredentials() method.
  456.     }
  457.     /**
  458.      * String representation of object
  459.      * @link http://php.net/manual/en/serializable.serialize.php
  460.      * @return string the string representation of the object or null
  461.      * @since 5.1.0
  462.      */
  463.     public function serialize()
  464.     {
  465.         return serialize(array(
  466.             $this->id,
  467.             $this->email,
  468.             $this->password,
  469.             $this->roles,
  470.             // see section on salt below
  471.             // $this->salt,
  472.         ));
  473.     }
  474.     /**
  475.      * Constructs the object
  476.      * @link http://php.net/manual/en/serializable.unserialize.php
  477.      * @param string $serialized <p>
  478.      * The string representation of the object.
  479.      * </p>
  480.      * @return void
  481.      * @since 5.1.0
  482.      */
  483.     public function unserialize($serialized)
  484.     {
  485.         list(
  486.             $this->id,
  487.             $this->email,
  488.             $this->password,
  489.             $this->roles,
  490.             // see section on salt below
  491.             // $this->salt
  492.         ) = unserialize($serialized);
  493.     }
  494.     /** @ORM\PrePersist */
  495.     public function onPrePersist()
  496.     {
  497.         $this->createdAt = new \DateTime("now", new \DateTimeZone("Europe/Paris"));
  498.         $this->updatedAt = new \DateTime("now", new \DateTimeZone("Europe/Paris"));
  499.     }
  500.     /** @ORM\PreUpdate */
  501.     public function onPreUpdate()
  502.     {
  503.         $this->updatedAt = new \DateTime("now", new \DateTimeZone("Europe/Paris"));
  504.     }
  505.     public function getDepartment(): ?Department
  506.     {
  507.         return $this->department;
  508.     }
  509.     public function setDepartment(?Department $department): self
  510.     {
  511.         $this->department $department;
  512.         return $this;
  513.     }
  514.     /**
  515.      * @return mixed
  516.      */
  517.     public function getPlainPassword()
  518.     {
  519.         return $this->plainPassword;
  520.     }
  521.     /**
  522.      * @param mixed $plainPassword
  523.      */
  524.     public function setPlainPassword($plainPassword): void
  525.     {
  526.         $this->plainPassword $plainPassword;
  527.     }
  528.     /**
  529.      * @return Collection|FormationRegistration[]
  530.      */
  531.     public function getFormations(): Collection
  532.     {
  533.         return $this->formations;
  534.     }
  535.     public function addFormation(FormationRegistration $formation): self
  536.     {
  537.         if (!$this->formations->contains($formation)) {
  538.             $this->formations[] = $formation;
  539.             $formation->setUser($this);
  540.         }
  541.         return $this;
  542.     }
  543.     public function removeFormation(FormationRegistration $formation): self
  544.     {
  545.         if ($this->formations->removeElement($formation)) {
  546.             // set the owning side to null (unless already changed)
  547.             if ($formation->getUser() === $this) {
  548.                 $formation->setUser(null);
  549.             }
  550.         }
  551.         return $this;
  552.     }
  553.     /**
  554.      * @return Collection|Notification[]
  555.      */
  556.     public function getNotifications(): Collection
  557.     {
  558.         return $this->notifications;
  559.     }
  560.     public function addNotification(Notification $notification): self
  561.     {
  562.         if (!$this->notifications->contains($notification)) {
  563.             $this->notifications[] = $notification;
  564.             $notification->setUserTo($this);
  565.         }
  566.         return $this;
  567.     }
  568.     public function removeNotification(Notification $notification): self
  569.     {
  570.         if ($this->notifications->removeElement($notification)) {
  571.             // set the owning side to null (unless already changed)
  572.             if ($notification->getUserTo() === $this) {
  573.                 $notification->setUserTo(null);
  574.             }
  575.         }
  576.         return $this;
  577.     }
  578.     /**
  579.      * @return bool
  580.      */
  581.     public function isIntro(): bool
  582.     {
  583.         return $this->intro;
  584.     }
  585.     /**
  586.      * @param bool $intro
  587.      */
  588.     public function setIntro(bool $intro): void
  589.     {
  590.         $this->intro $intro;
  591.     }
  592.     /**
  593.      * @return bool
  594.      */
  595.     public function getCgu(): bool
  596.     {
  597.         return $this->cgu;
  598.     }
  599.     /**
  600.      * @param bool $cgu
  601.      */
  602.     public function setCgu(bool $cgu): void
  603.     {
  604.         $this->cgu $cgu;
  605.     }
  606.     /**
  607.      * @return null
  608.      */
  609.     public function getWorkHandicapped()
  610.     {
  611.         return $this->work_handicapped;
  612.     }
  613.     /**
  614.      * @param null $work_handicapped
  615.      */
  616.     public function setWorkHandicapped($work_handicapped): void
  617.     {
  618.         $this->work_handicapped $work_handicapped;
  619.     }
  620.     /**
  621.      * @return
  622.      */
  623.     public function getPunctualSport()
  624.     {
  625.         return $this->punctual_sport;
  626.     }
  627.     /**
  628.      * @param $punctual_sport
  629.      */
  630.     public function setPunctualSport($punctual_sport): void
  631.     {
  632.         $this->punctual_sport $punctual_sport;
  633.     }
  634.     /**
  635.      * @return mixed
  636.      */
  637.     public function getUpdatedDataConfirmedAt()
  638.     {
  639.         return $this->updatedDataConfirmedAt;
  640.     }
  641.     /**
  642.      * @param mixed $updatedDataConfirmedAt
  643.      */
  644.     public function setUpdatedDataConfirmedAt($updatedDataConfirmedAt): void
  645.     {
  646.         $this->updatedDataConfirmedAt $updatedDataConfirmedAt;
  647.     }
  648.     public function getJob(): ?Job
  649.     {
  650.         return $this->job;
  651.     }
  652.     public function setJob(?Job $job): self
  653.     {
  654.         $this->job $job;
  655.         return $this;
  656.     }
  657.     public function getIsContact(): ?bool
  658.     {
  659.         return $this->isContact;
  660.     }
  661.     public function setIsContact(?bool $isContact): self
  662.     {
  663.         $this->isContact $isContact;
  664.         return $this;
  665.     }
  666.     /**
  667.      * @return mixed
  668.      */
  669.     public function getLastLoginAt()
  670.     {
  671.         return $this->lastLoginAt;
  672.     }
  673.     /**
  674.      * @param mixed $lastLoginAt
  675.      */
  676.     public function setLastLoginAt($lastLoginAt): void
  677.     {
  678.         $this->lastLoginAt $lastLoginAt;
  679.     }
  680.     //    /**
  681. //     * @ORM\PrePersist
  682. //     * @ORM\PreUpdate
  683. //     */
  684. //    public function updatedTimestamps(): void
  685. //    {
  686. //        $this->setUpdatedDataConfirmedAt(new \DateTime());
  687. //    }
  688.     /**
  689.      * @return mixed
  690.      */
  691.     public function getKeycloakId()
  692.     {
  693.         return $this->keycloakId;
  694.     }
  695.     /**
  696.      * @param mixed $keycloakId
  697.      */
  698.     public function setKeycloakId($keycloakId): void
  699.     {
  700.         $this->keycloakId $keycloakId;
  701.     }
  702.     public function getSite(): ?Site
  703.     {
  704.         return $this->site;
  705.     }
  706.     public function setSite(?Site $site): self
  707.     {
  708.         $this->site $site;
  709.         return $this;
  710.     }
  711.     /**
  712.      * @return mixed
  713.      */
  714.     public function getAgreeTermsAt()
  715.     {
  716.         return $this->agreeTermsAt;
  717.     }
  718.     /**
  719.      * @param mixed $agreeTermsAt
  720.      */
  721.     public function setAgreeTermsAt($agreeTermsAt): void
  722.     {
  723.         $this->agreeTermsAt $agreeTermsAt;
  724.     }
  725.     /**
  726.      * @return mixed
  727.      */
  728.     public function getAgreePrivateDataAt()
  729.     {
  730.         return $this->agreePrivateDataAt;
  731.     }
  732.     /**
  733.      * @param mixed $agreePrivateDataAt
  734.      */
  735.     public function setAgreePrivateDataAt($agreePrivateDataAt): void
  736.     {
  737.         $this->agreePrivateDataAt $agreePrivateDataAt;
  738.     }
  739. }