src/Entity/User/User.php line 26

Open in your IDE?
  1. <?php
  2. namespace App\Entity\User;
  3. use App\Entity\Federation\Race;
  4. use Doctrine\ORM\Mapping as ORM;
  5. use Gedmo\Mapping\Annotation as Gedmo;
  6. use Symfony\Component\Security\Core\User\PasswordAuthenticatedUserInterface;
  7. use Symfony\Component\Security\Core\User\UserInterface;
  8. use Symfony\Component\Validator\Constraints as Assert;
  9. use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
  10. use Doctrine\Common\Collections\ArrayCollection;
  11. use Doctrine\Common\Collections\Collection;
  12. use App\Entity\Federation\Participation;
  13. use function Symfony\Component\Translation\t;
  14. /**
  15.  * User
  16.  *
  17.  * @ORM\Table(name="users")
  18.  * @ORM\Entity(repositoryClass="App\Repository\User\UserRepository")
  19.  * @ORM\HasLifecycleCallbacks()
  20.  * @Gedmo\Loggable(logEntryClass="App\Entity\History\History")
  21.  * @UniqueEntity(fields="email", message="inodia_user.email.unique", groups={"RegistrationUserInodia", "UpdateUserInodia"})
  22.  */
  23. class User implements UserInterfacePasswordAuthenticatedUserInterface
  24. {
  25.     /**
  26.      *
  27.      * @ORM\Column(name="id", type="integer")
  28.      * @ORM\Id
  29.      * @ORM\GeneratedValue(strategy="AUTO")
  30.      */
  31.     protected $id;
  32.     
  33.     /**
  34.      *  @var string
  35.      */
  36.     protected $plainPassword;
  37.     
  38.     /**
  39.      * @var string
  40.      *
  41.      * @Gedmo\Versioned
  42.      * @ORM\Column(name="password", type="string")
  43.      * @Assert\NotBlank(groups={"RegistrationUserInodia"}, message="inodia_user.password.not_blank")
  44.      * @Assert\Regex(
  45.      *     groups={"RegistrationUserInodia", "ChangePassword"},
  46.      *     pattern="/^(?=.*?[A-Z])(?=.*?[a-z])(?=.*?[0-9])(?=.*?[^\w\s]).{8,}$/",
  47.      *     match=true,
  48.      *     message="inodia_user.password.validation"
  49.      *  )
  50.      */
  51.     private $password;
  52.     /**
  53.      * @ORM\Column(type="json")
  54.      */
  55.     protected $roles = array();
  56.     
  57.     /**
  58.      * @var string
  59.      *
  60.      * @Gedmo\Versioned
  61.      * @ORM\Column(name="firstname", type="string", length=255, nullable=false)
  62.      * @Assert\NotBlank(groups={"RegistrationUserInodia", "UpdateUserInodia"})
  63.      */
  64.     private $firstname;
  65.     
  66.     /**
  67.      * @var string
  68.      *
  69.      * @Gedmo\Versioned
  70.      * @ORM\Column(name="lastname", type="string", length=255, nullable=false)
  71.      * @Assert\NotBlank(groups={"RegistrationUserInodia", "UpdateUserInodia"})
  72.      */
  73.     private $lastname;
  74.     
  75.     /**
  76.      * @Gedmo\Versioned
  77.      * @ORM\ManyToOne(targetEntity="App\Entity\User\Prefix")
  78.      */
  79.     private $prefix;
  80.     
  81.     /**
  82.      * @var string
  83.      *
  84.      * @Gedmo\Versioned
  85.      * @ORM\Column(name="job", type="string", length=255, nullable=true)
  86.      */
  87.     private $job;
  88.     
  89.     /**
  90.      * @var string
  91.      *
  92.      * @Gedmo\Versioned
  93.      * @ORM\Column(name="language", type="string", length=255, nullable=false)
  94.      * @Assert\NotBlank(groups={"RegistrationUserInodia", "UpdateUserInodia"})
  95.      */
  96.     private $language;
  97.     
  98.     /**
  99.      * @Gedmo\Versioned
  100.      * @ORM\Column(type="string", length=255, unique=true)
  101.      * @Assert\Email(groups={"RegistrationUserInodia", "UpdateUserInodia"}, message="inodia_user.email.validation")
  102.      * @Assert\NotBlank(groups={"RegistrationUserInodia", "UpdateUserInodia"}, message="inodia_user.email.not_blank")
  103.      */
  104.     protected $email;
  105.     
  106.     /**
  107.      * @Gedmo\Versioned
  108.      * @ORM\Column(name="mobile_phone", type="string", nullable=true)
  109.      * @Assert\Expression(
  110.      *     "this.getMobilePhone() != '' or this.getPhone() != ''",
  111.      *     message="inodia_user.phone.one_required",
  112.      *     groups={"RegistrationUserInodia", "UpdateUserInodia"} 
  113.      * )
  114.      */
  115.     private $mobilePhone;
  116.     
  117.     /**
  118.      * @Gedmo\Versioned
  119.      * @ORM\Column(name="phone", type="string", nullable=true)
  120.      */
  121.     private $phone;
  122.      
  123.     /**
  124.      * @var \DateTime
  125.      *
  126.      * @Gedmo\Timestampable(on="change", field={"password"})
  127.      * @ORM\Column(name="password_change_date", type="datetime", nullable=true)
  128.      */
  129.     private $passwordChangeDate;
  130.     
  131.     /**
  132.      * @ORM\ManyToMany(targetEntity="App\Entity\User\Group")
  133.      * @ORM\JoinTable(name="users_groups",
  134.      *      joinColumns={@ORM\JoinColumn(name="user_id", referencedColumnName="id")},
  135.      *      inverseJoinColumns={@ORM\JoinColumn(name="group_id", referencedColumnName="id")}
  136.      * )
  137.      */
  138.     protected $groups;
  139.     
  140.     /**
  141.      *
  142.      * @var \App\Entity\ThirdParty\ThirdParty
  143.      *
  144.      * @ORM\ManyToOne(targetEntity="App\Entity\ThirdParty\ThirdParty", inversedBy="users")
  145.      */
  146.     protected $thirdParty;
  147.     
  148.     protected $confirmation_token;
  149.     
  150.     /**
  151.      * @var \DateTime
  152.      *
  153.      * @ORM\Column(name="last_login", type="datetime", nullable=true)
  154.      */
  155.     private $lastLogin;
  156.     
  157.     /**
  158.      * @var \DateTime
  159.      *
  160.      * @Gedmo\Timestampable(on="create")
  161.      * @ORM\Column(name="created_date", type="datetime", nullable=false)
  162.      */
  163.     private $createdDate;
  164.     
  165.     /**
  166.      * @var \DateTime
  167.      *
  168.      * @Gedmo\Timestampable(on="update")
  169.      * @ORM\Column(name="updated_date", type="datetime", nullable=true)
  170.      */
  171.     private $updatedDate;
  172.     
  173.     /**
  174.      * @var integer
  175.      *
  176.      * @ORM\Column(name="enabled", type="integer", nullable=false)
  177.      */
  178.     private $enabled 1;
  179.     
  180.     /**
  181.      * @var integer
  182.      *
  183.      * @ORM\Column(name="status", type="integer", nullable=false)
  184.      */
  185.     private $status 1;
  186.     
  187.     private $superAdmin false;
  188.     
  189.     /**
  190.      * @ORM\Column(type="boolean")
  191.      * @Assert\IsTrue(message="inodia_user.dataPrivacyPolicyAcceptation", groups={"RegistrationUserInodia"})
  192.      */
  193.     private $dataPrivacyPolicyAcceptation 0;
  194.     
  195.     /**
  196.      * @ORM\ManyToMany(targetEntity="App\Entity\Federation\Participation", mappedBy="referents", cascade={"remove"})
  197.      */
  198.     private $participations;
  199.     /**
  200.      * @ORM\OneToMany(targetEntity="App\Entity\Site\AccessSite", mappedBy="user", cascade={"remove"})
  201.      */
  202.     private $accessSites;
  203.     /**
  204.      * @ORM\OneToMany(targetEntity="App\Entity\Media\Document", mappedBy="proofValidationUser")
  205.      */
  206.     private $proofValidations;
  207.     /**
  208.      * @ORM\OneToMany(targetEntity="App\Entity\History\History", mappedBy="user", cascade={"remove"})
  209.      */
  210.     private $histories;
  211.         
  212.     public function __construct()
  213.     {
  214.         $this->groups = new ArrayCollection();
  215.         $this->participations = new ArrayCollection();
  216.         $this->proofValidations = new ArrayCollection();
  217.         $this->histories = new ArrayCollection();
  218.     }
  219.     
  220.     public function getEmail(): ?string
  221.     {
  222.         return $this->email;
  223.     }
  224.     public function setEmail(string $email): self
  225.     {
  226.         $this->email $email;
  227.         return $this;
  228.     }
  229.     
  230.     /**
  231.      * The public representation of the user (e.g. a username, an email address, etc.)
  232.      *
  233.      * @see UserInterface
  234.      */
  235.     public function getUserIdentifier(): string
  236.     {
  237.         return (string) $this->email;
  238.     }
  239.     /**
  240.      * @see UserInterface
  241.      */
  242.     public function getRoles(): array
  243.     {
  244.         $roles $this->roles;
  245.         if(!empty($this->getGroups()))
  246.             foreach($this->getGroups() as $group)
  247.                 foreach($group->getRoles() as $role)
  248.                     $roles[] = $role;
  249.         
  250.         //$roles = $this->roles;
  251.         // guarantee every user at least has ROLE_USER
  252.         //$roles[] = 'ROLE_USER';
  253.         
  254.         return array_unique($roles);
  255.     }
  256.     public function setRoles(array $roles): self
  257.     {
  258.         $this->roles $roles;
  259.         return $this;
  260.     }
  261.     /**
  262.      * @see PasswordAuthenticatedUserInterface
  263.      */
  264.     public function getPassword(): ?string
  265.     {
  266.         return $this->password;
  267.     }
  268.     public function setPassword(?string $password): self
  269.     {
  270.         $this->password $password;
  271.         return $this;
  272.     }
  273.     /**
  274.      * Returning a salt is only needed, if you are not using a modern
  275.      * hashing algorithm (e.g. bcrypt or sodium) in your security.yaml.
  276.      *
  277.      * @see UserInterface
  278.      */
  279.     public function getSalt(): ?string
  280.     {
  281.         return null;
  282.     }
  283.     /**
  284.      * @see UserInterface
  285.      */
  286.     public function eraseCredentials()
  287.     {
  288.         // If you store any temporary, sensitive data on the user, clear it here
  289.         // $this->plainPassword = null;
  290.     }
  291.     
  292.     /**
  293.      * Get id
  294.      *
  295.      * @return int
  296.      */
  297.     public function getId()
  298.     {
  299.         return $this->id;
  300.     }
  301.     
  302.     /**
  303.      * Get firstname
  304.      *
  305.      * @return string
  306.      */
  307.     public function getUsername()
  308.     {
  309.         return $this->email;
  310.     }
  311.     
  312.     /**
  313.      * Set firstname
  314.      *
  315.      * @param string $firstname
  316.      *
  317.      * @return User
  318.      */
  319.     public function setFirstname($firstname)
  320.     {
  321.         $this->firstname $firstname;
  322.         
  323.         return $this;
  324.     }
  325.     
  326.     /**
  327.      * Get firstname
  328.      *
  329.      * @return string
  330.      */
  331.     public function getFirstname()
  332.     {
  333.         return $this->firstname;
  334.     }
  335.     
  336.     /**
  337.      * Set lastname
  338.      *
  339.      * @param string $lastname
  340.      *
  341.      * @return User
  342.      */
  343.     public function setLastname($lastname)
  344.     {
  345.         $this->lastname $lastname;
  346.         
  347.         return $this;
  348.     }
  349.     
  350.     /**
  351.      * Get lastname
  352.      *
  353.      * @return string
  354.      */
  355.     public function getLastname()
  356.     {
  357.         return $this->lastname;
  358.     }
  359.     
  360.     /**
  361.      * Set prefix
  362.      *
  363.      * @param \App\Entity\User\Prefix $prefix
  364.      *
  365.      * @return User
  366.      */
  367.     public function setPrefix($prefix)
  368.     {
  369.         $this->prefix $prefix;
  370.         
  371.         return $this;
  372.     }
  373.     
  374.     /**
  375.      * Get prefix
  376.      *
  377.      * @return \App\Entity\User\Prefix $prefix
  378.      */
  379.     public function getPrefix()
  380.     {
  381.         return $this->prefix;
  382.     }
  383.     
  384.     
  385.     /**
  386.      * Set job
  387.      *
  388.      * @param string $job
  389.      *
  390.      * @return User
  391.      */
  392.     public function setJob($job)
  393.     {
  394.         $this->job $job;
  395.         
  396.         return $this;
  397.     }
  398.     
  399.     /**
  400.      * Get job
  401.      *
  402.      * @return string
  403.      */
  404.     public function getJob()
  405.     {
  406.         return $this->job;
  407.     }
  408.     
  409.     /**
  410.      * Set language
  411.      *
  412.      * @param string $language
  413.      *
  414.      * @return User
  415.      */
  416.     public function setLanguage($language)
  417.     {
  418.         $this->language $language;
  419.         
  420.         return $this;
  421.     }
  422.     
  423.     /**
  424.      * Get language
  425.      *
  426.      * @return string
  427.      */
  428.     public function getLanguage()
  429.     {
  430.         return $this->language;
  431.     }
  432.     
  433.     /**
  434.      * Set mobilePhone
  435.      *
  436.      * @param string $mobilephone
  437.      *
  438.      * @return User
  439.      */
  440.     public function setMobilePhone($mobilephone)
  441.     {
  442.         $this->mobilePhone $mobilephone;
  443.         
  444.         return $this;
  445.     }
  446.     
  447.     /**
  448.      * Get phone
  449.      *
  450.      * @return string
  451.      */
  452.     public function getPhone()
  453.     {
  454.         return $this->phone;
  455.     }
  456.     
  457.     /**
  458.      * Set phone
  459.      *
  460.      * @param string $phone
  461.      *
  462.      * @return User
  463.      */
  464.     public function setPhone($phone)
  465.     {
  466.         $this->phone $phone;
  467.         
  468.         return $this;
  469.     }
  470.     
  471.     /**
  472.      * Get mobilePhone
  473.      *
  474.      * @return string
  475.      */
  476.     public function getMobilePhone()
  477.     {
  478.         return $this->mobilePhone;
  479.     }
  480.     
  481.     /**
  482.      * Get lastLogin
  483.      *
  484.      * @return \DateTime
  485.      */
  486.     public function getLastLogin()
  487.     {
  488.         return $this->lastLogin;
  489.     }
  490.     
  491.     /**
  492.      * Set phone
  493.      *
  494.      * @param \DateTime $lastLogin
  495.      *
  496.      * @return User
  497.      */
  498.     public function setLastLogin($lastLogin)
  499.     {
  500.         $this->lastLogin $lastLogin;
  501.         
  502.         return $this;
  503.     }
  504.     
  505.     /**
  506.      * Get createdDate
  507.      *
  508.      * @return \DateTime
  509.      */
  510.     public function getCreatedDate()
  511.     {
  512.         return $this->createdDate;
  513.     }
  514.     
  515.     /**
  516.      * Get updatedDate
  517.      *
  518.      * @return \DateTime
  519.      */
  520.     public function getUpdatedDate()
  521.     {
  522.         return $this->updatedDate;
  523.     }
  524.     
  525.     /**
  526.      * Set enabled
  527.      *
  528.      * @param integer $enabled
  529.      *
  530.      * @return User
  531.      */
  532.     public function setEnabled($enabled)
  533.     {
  534.         $this->enabled $enabled;
  535.         
  536.         return $this;
  537.     }
  538.     
  539.     /**
  540.      * Get enabled
  541.      *
  542.      * @return integer
  543.      */
  544.     public function isEnabled()
  545.     {
  546.         return $this->enabled;
  547.     }
  548.     
  549.     /**
  550.      * Set status
  551.      *
  552.      * @param integer $status
  553.      *
  554.      * @return User
  555.      */
  556.     public function setStatus($status)
  557.     {
  558.         $this->status $status;
  559.         
  560.         return $this;
  561.     }
  562.     
  563.     /**
  564.      * Get status
  565.      *
  566.      * @return integer
  567.      */
  568.     public function getStatus()
  569.     {
  570.         return $this->status;
  571.     }
  572.           
  573.     /**
  574.      * Set passwordChangeDate
  575.      *
  576.      * @param \DateTime $passwordChangeDate
  577.      *
  578.      * @return User
  579.      */
  580.     public function setPasswordChangeDate($passwordChangeDate)
  581.     {
  582.         $this->passwordChangeDate $passwordChangeDate;
  583.         
  584.         return $this;
  585.     }
  586.     
  587.     /**
  588.      * Get passwordChangeDate
  589.      *
  590.      * @return \DateTime
  591.      */
  592.     public function getPasswordChangeDate()
  593.     {
  594.         return $this->passwordChangeDate;
  595.     }
  596.     
  597.     /**
  598.      * Set thirdparty
  599.      *
  600.      * @param \App\Entity\ThirdParty\ThirdParty $thirdparty
  601.      *
  602.      * @return \App\Entity\ThirdParty\ThirdParty
  603.      */
  604.     public function setThirdParty(\App\Entity\ThirdParty\ThirdParty $thirdParty null)
  605.     {
  606.         $this->thirdParty $thirdParty;
  607.         
  608.         return $this;
  609.     }
  610.     
  611.     /**
  612.      * Get thirdparty
  613.      *
  614.      * @return \App\Entity\ThirdParty\ThirdParty
  615.      */
  616.     public function getThirdParty()
  617.     {
  618.         return $this->thirdParty;
  619.     }
  620.     
  621.     public function getGroups()
  622.     {
  623.         return $this->groups;
  624.     }
  625.     
  626.     public function addGroup(Group $group)
  627.     {
  628.         if(!$this->groups->contains($group))
  629.             $this->groups->add($group); 
  630.     }
  631.     
  632.     public function belongsToGroup($role)
  633.     {
  634.         $groups=$this->getGroups();
  635.         foreach ($groups as $group)
  636.         {
  637.             if($group->hasRole($role))
  638.                 return true;
  639.         }
  640.         return false;
  641.     }
  642.     
  643.     public function getDataPrivacyPolicyAcceptation(): ?bool
  644.     {
  645.         return $this->dataPrivacyPolicyAcceptation;
  646.     }
  647.     
  648.     public function setDataPrivacyPolicyAcceptation(bool $dataPrivacyPolicyAcceptation): self
  649.     {
  650.         $this->dataPrivacyPolicyAcceptation $dataPrivacyPolicyAcceptation;
  651.         
  652.         return $this;
  653.     }
  654.     
  655.     public function getPlainPassword()
  656.     {
  657.         return $this->plainPassword;
  658.     }
  659.     
  660.     /**
  661.      * @return Collection|Participation[]
  662.      */
  663.     public function getParticipations(): ?Collection
  664.     {
  665.         return $this->participations;
  666.     }
  667.     public function addParticipation(Participation $participation): self
  668.     {
  669.         if (!$this->participations->contains($participation)) {
  670.             $this->participations[] = $participation;
  671.             $participation->addTeam($this);
  672.         }
  673.         return $this;
  674.     }
  675.     public function removeParticipation(Participation $participation): self
  676.     {
  677.         if ($this->participations->contains($participation)) {
  678.             $this->participations->removeElement($participation);
  679.             $participation->removeTeam($this);
  680.         }
  681.         return $this;
  682.     }
  683.     public function getAccessSites()
  684.     {
  685.         return $this->accessSites;
  686.     }
  687.     public function checkAccessRace(Race $race): bool
  688.     {
  689.         foreach($this->getAccessSites() as $accessSite)
  690.             if($accessSite->getSite()->getRace()->getId() == $race->getId())
  691.                 return true;
  692.         return false;
  693.     }
  694.     public function getAllowedRace()
  695.     {
  696.         $races = [];
  697.         foreach($this->getAllowedSite() as $site)
  698.             $races[] = $site->getRace();
  699.         return $races;
  700.     }
  701.     public function getAllowedSite()
  702.     {
  703.         $sites = [];
  704.         foreach($this->getAccessSites() as $accessSite)
  705.             if($accessSite->getStatus() == 2)
  706.                 $sites[] = $accessSite->getSite();
  707.         return $sites;
  708.     }
  709.     public function getProofValidations()
  710.     {
  711.         return $this->proofValidations;
  712.     }
  713. }