src/Entity/Users.php line 26

  1. <?php
  2. namespace App\Entity;
  3. use DateTime;
  4. use Doctrine\Common\Collections\ArrayCollection;
  5. use Doctrine\Common\Collections\Collection;
  6. use Doctrine\ORM\Mapping as ORM;
  7. use Symfony\Component\Security\Core\User\LegacyPasswordAuthenticatedUserInterface;
  8. use Symfony\Component\Security\Core\User\PasswordAuthenticatedUserInterface;
  9. use Symfony\Component\Validator\Constraints as Assert;
  10. use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
  11. use Symfony\Component\Security\Core\User\UserInterface;
  12. use Symfony\Component\Security\Core\User\EquatableInterface;
  13. /**
  14.  * Users
  15.  */
  16. #[UniqueEntity('username'message'Uživatel s tímto uživatelským jménem už existuje.')]
  17. #[UniqueEntity(fields: ['email''isDeleted'], message'Uživatel s tímto emailem už existuje.')]
  18. #[ORM\Table(name'users')]
  19. #[ORM\Index(name'IDX_D69CF8AF460D9222'columns: ['google_id'])]
  20. #[ORM\Index(name'IDX_D69CF8AF460D9333'columns: ['google_access_token'])]
  21. #[ORM\Index(name'IDX_D69CF8AF460D8989'columns: ['linkedin_id'])]
  22. #[ORM\Entity]
  23. class Users implements  UserInterface\SerializableEquatableInterfacePasswordAuthenticatedUserInterfaceLegacyPasswordAuthenticatedUserInterface
  24. {
  25.     #[ORM\Column(name'id'type'integer'options: ['comment' => 'ID'])]
  26.     #[ORM\Id]
  27.     #[ORM\GeneratedValue(strategy'SEQUENCE')]
  28.     #[ORM\SequenceGenerator(sequenceName'seq_users_id'allocationSize1initialValue1)]
  29.     private int $id;
  30.     #[ORM\Column(name'username'type'string'length96nullablefalseoptions: ['comment' => 'Username'])]
  31.     private string $username;
  32.     #[ORM\Column(name'password'type'string'length128nullablefalseoptions: ['comment' => 'Password'])]
  33.     private string $password;
  34.     #[ORM\Column(name'salt'type'string'length96nullablefalseoptions: ['default' => 'tmpSolution'])]
  35.     private string $salt;
  36.     #[ORM\Column(name'first_name'type'string'length64nullablefalseoptions: ['comment' => 'First name'])]
  37.     private ?string $firstName;
  38.     #[ORM\Column(name'last_name'type'string'length64nullablefalseoptions: ['comment' => 'Last name'])]
  39.     private ?string $lastName;
  40.     #[ORM\Column(name'email'type'string'length128nullablefalseoptions: ['comment' => 'Email'])]
  41.     private ?string $email;
  42.     #[ORM\Column(name'phone'type'string'length64nullabletrueoptions: ['comment' => 'Phone'])]
  43.     private ?string $phone;
  44.     #[ORM\Column(name'institution'type'string'length128nullabletrueoptions: ['comment' => 'Institution'])]
  45.     private ?string $institution;
  46.     #[ORM\Column(name'address'type'string'length255nullabletrueoptions: ['comment' => 'Address'])]
  47.     private ?string $address;
  48.     #[ORM\Column(name'city'type'string'length128nullabletrueoptions: ['comment' => 'City'])]
  49.     private ?string $city;
  50.     #[ORM\Column(name'postalcode'type'string'length15nullabletrueoptions: ['comment' => 'Postal code'])]
  51.     private ?string $postalcode;
  52.     #[ORM\Column(name'auth_role'type'string'length20nullablefalseoptions: ['comment' => 'Role'])]
  53.     private string $authRole;
  54.     #[ORM\Column(name'lastvisit_at'type'datetime'nullabletrue)]
  55.     private ?DateTime $lastvisitAt;
  56.     #[ORM\Column(name'created_at'type'datetime'nullablefalseoptions: ['comment' => 'Created at''default' => 'now()'])]
  57.     private DateTime $createdAt;
  58.     #[ORM\Column(name'lastmod_at'type'datetime'nullabletrue)]
  59.     private ?DateTime $lastmodAt;
  60.     #[ORM\ManyToOne(targetEntity'App\Entity\Users')]
  61.     #[ORM\JoinColumn(name'users_id'referencedColumnName'id')]
  62.     private ?Users $users;
  63.     #[ORM\Column(name'users_id'type'integer'nullablefalseoptions: ['comment' => 'Creating/editing user'])]
  64.     protected int $usersId;
  65.     #[ORM\Column(name'is_deleted'type'boolean'nullablefalseoptions: ['default' => false])]
  66.     private bool $isDeleted false;
  67.     #[Assert\Length(min7minMessage"Heslo musí obsahovat minimálně 7 znaků.")]
  68.     #[Assert\Length(max4096maxMessage"Heslo může obsahovat maximálně 4096 znaků.")]
  69.     #[Assert\Regex(pattern"/\d/", match: truemessage"Heslo musí obsahovat číslo.")]
  70.     #[Assert\Regex(pattern"/[A-Z]/", match: truemessage"Heslo musí obsahovat velké písmeno.")]
  71.     #[Assert\Regex(pattern"/[a-z]/", match: truemessage"Heslo musí obsahovat malé písmeno.")]
  72.     private ?string $plainPassword null;
  73.     /**
  74.      * Null or expire date
  75.      */
  76.     #[ORM\Column(name'PASSWORD_EXPIRE'type'datetime'nullabletrueoptions: ['comment' => 'Password expire date'])]
  77.     public $passwordExpire null;
  78.     #[ORM\Column(name'PASSWORD_RESET_HASH'type'string'nullabletrueoptions: ['comment' => 'Hash needed to reset password'])]
  79.     protected ?string $passwordResetHash;
  80.     #[ORM\Column(name'PASSWORD_RESET_HASH_VALIDITY'type'datetime'nullabletrueoptions: ['comment' => 'Date until the password reset hash is valid'])]
  81.     protected ?DateTime $hashValidUntil;
  82.     #[ORM\Column(name'CREDENTIALS_SENT_LAST_ON'type'datetime'nullabletrueoptions: ['comment' => 'Last time sent user credentials'])]
  83.     protected ?DateTime $credentialsSentLastOn;
  84.     #[ORM\Column(name'SEND_CREDENTIALS_IMMEDIATELY'type'boolean'nullabletrueoptions: ['default' => true])]
  85.     protected ?bool $sendCredentialsImmediately false;
  86.     #[ORM\Column(name'google_id'type'string'length2500nullabletrue)]
  87.     private ?string $googleId;
  88.     #[ORM\Column(name'google_access_token'type'string'length2500nullabletrue)]
  89.     private ?string $googleAccessToken;
  90.     #[ORM\Column(name'linkedin_id'type'string'length2500nullabletrue)]
  91.     private ?string $linkedinId;
  92.     #[ORM\Column(name'linkedin_access_token'type'string'length2500nullabletrue)]
  93.     private ?string $linkedinAccessToken;
  94.     #[ORM\Column(name'personal_number'type'string'length64nullabletrueoptions: ['comment' => 'Personal number'])]
  95.     private ?string $personalNumber;
  96.     /**
  97.      * Stats where users used
  98.      */
  99.     #[ORM\JoinTable(name'STAT_USERS')]
  100.     #[ORM\JoinColumn(name'USERS_ID'referencedColumnName'id'nullablefalse)]
  101.     #[ORM\InverseJoinColumn(name'STAT_ID'referencedColumnName'id'nullablefalse)]
  102.     #[ORM\ManyToMany(targetEntity'Stat'inversedBy'users')]
  103.     protected $stats;
  104.     public function __construct()
  105.     {
  106.         $this->stats = new ArrayCollection();
  107.     }
  108.     /**
  109.      * Set username
  110.      *
  111.      * @param string $username
  112.      *
  113.      * @return Users
  114.      */
  115.     public function setUsername(string $username): Users
  116.     {
  117.         $this->username $username;
  118.         return $this;
  119.     }
  120.     /**
  121.      * Set username
  122.      *
  123.      * @param string $username
  124.      *
  125.      * @return Users
  126.      */
  127.     public function setUserIdentifier(string $username): Users
  128.     {
  129.         $this->username $username;
  130.         return $this;
  131.     }
  132.     /**
  133.      * Get username
  134.      *
  135.      * @return string
  136.      */
  137.     public function getUsername(): string
  138.     {
  139.         return $this->username;
  140.     }
  141.     /**
  142.      * Get username
  143.      *
  144.      * @return string
  145.      */
  146.     public function getUserIdentifier(): string
  147.     {
  148.         return $this->username;
  149.     }
  150.     /**
  151.      * Set password
  152.      *
  153.      * @param string $password
  154.      *
  155.      * @return Users
  156.      */
  157.     public function setPassword(string $password): Users
  158.     {
  159.         $this->password $password;
  160.         return $this;
  161.     }
  162.     /**
  163.      * Get password
  164.      *
  165.      * @return string
  166.      */
  167.     public function getPassword(): string
  168.     {
  169.         return $this->password;
  170.     }
  171.     /**
  172.      * Set salt
  173.      *
  174.      * @param string $salt
  175.      *
  176.      * @return Users
  177.      */
  178.     public function setSalt(string $salt): Users
  179.     {
  180.         $this->salt $salt;
  181.         return $this;
  182.     }
  183.     /**
  184.      * Get salt
  185.      *
  186.      * @return string
  187.      */
  188.     public function getSalt(): string
  189.     {
  190.         return $this->salt;
  191.     }
  192.     /**
  193.      * Set firstName
  194.      *
  195.      * @param string $firstName
  196.      *
  197.      * @return Users
  198.      */
  199.     public function setFirstName(string $firstName): Users
  200.     {
  201.         $this->firstName $firstName;
  202.         return $this;
  203.     }
  204.     /**
  205.      * Get firstName
  206.      *
  207.      * @return string
  208.      */
  209.     public function getFirstName(): string
  210.     {
  211.         return (string)$this->firstName;
  212.     }
  213.     /**
  214.      * Set lastName
  215.      *
  216.      * @param string $lastName
  217.      *
  218.      * @return Users
  219.      */
  220.     public function setLastName(string $lastName): Users
  221.     {
  222.         $this->lastName $lastName;
  223.         return $this;
  224.     }
  225.     /**
  226.      * Get lastName
  227.      *
  228.      * @return string
  229.      */
  230.     public function getLastName(): string
  231.     {
  232.         return (string)$this->lastName;
  233.     }
  234.     /**
  235.      * Set email
  236.      *
  237.      * @param string $email
  238.      *
  239.      * @return Users
  240.      */
  241.     public function setEmail(string $email): Users
  242.     {
  243.         $this->email $email;
  244.         return $this;
  245.     }
  246.     /**
  247.      * Get email
  248.      *
  249.      * @return string
  250.      */
  251.     public function getEmail(): string
  252.     {
  253.         return (string)$this->email;
  254.     }
  255.     /**
  256.      * Set phone
  257.      *
  258.      * @param string|null $phone
  259.      *
  260.      * @return Users
  261.      */
  262.     public function setPhone(?string $phone): Users
  263.     {
  264.         $this->phone $phone;
  265.         return $this;
  266.     }
  267.     /**
  268.      * Get phone
  269.      *
  270.      * @return string|null
  271.      */
  272.     public function getPhone(): ?string
  273.     {
  274.         return $this->phone;
  275.     }
  276.     /**
  277.      * Set institution
  278.      *
  279.      * @param string|null $institution
  280.      *
  281.      * @return Users
  282.      */
  283.     public function setInstitution(?string $institution): Users
  284.     {
  285.         $this->institution $institution;
  286.         return $this;
  287.     }
  288.     /**
  289.      * Get institution
  290.      *
  291.      * @return string|null
  292.      */
  293.     public function getInstitution(): ?string
  294.     {
  295.         return $this->institution;
  296.     }
  297.     /**
  298.      * Set address
  299.      *
  300.      * @param string|null $address
  301.      *
  302.      * @return Users
  303.      */
  304.     public function setAddress(?string $address): Users
  305.     {
  306.         $this->address $address;
  307.         return $this;
  308.     }
  309.     /**
  310.      * Get address
  311.      *
  312.      * @return string|null
  313.      */
  314.     public function getAddress(): ?string
  315.     {
  316.         return $this->address;
  317.     }
  318.     /**
  319.      * Set city
  320.      *
  321.      * @param string|null $city
  322.      *
  323.      * @return Users
  324.      */
  325.     public function setCity(?string $city): Users
  326.     {
  327.         $this->city $city;
  328.         return $this;
  329.     }
  330.     /**
  331.      * Get city
  332.      *
  333.      * @return string|null
  334.      */
  335.     public function getCity(): ?string
  336.     {
  337.         return $this->city;
  338.     }
  339.     /**
  340.      * Set postalcode
  341.      *
  342.      * @param string|null $postalcode
  343.      *
  344.      * @return Users
  345.      */
  346.     public function setPostalcode(?string $postalcode): Users
  347.     {
  348.         $this->postalcode $postalcode;
  349.         return $this;
  350.     }
  351.     /**
  352.      * Get postalcode
  353.      *
  354.      * @return string|null
  355.      */
  356.     public function getPostalcode(): ?string
  357.     {
  358.         return $this->postalcode;
  359.     }
  360.     /**
  361.      * Set authRole
  362.      *
  363.      * @param string $authRole
  364.      *
  365.      * @return Users
  366.      */
  367.     public function setAuthRole(string $authRole): Users
  368.     {
  369.         $this->authRole $authRole;
  370.         return $this;
  371.     }
  372.     /**
  373.      * Get authRole
  374.      *
  375.      * @return string
  376.      */
  377.     public function getAuthRole(): string
  378.     {
  379.         return $this->authRole;
  380.     }
  381.     /**
  382.      * Set lastvisitAt
  383.      *
  384.      * @param DateTime $lastvisitAt
  385.      *
  386.      * @return Users
  387.      */
  388.     public function setLastvisitAt(DateTime $lastvisitAt): Users
  389.     {
  390.         $this->lastvisitAt $lastvisitAt;
  391.         return $this;
  392.     }
  393.     /**
  394.      * Get lastvisitAt
  395.      *
  396.      * @return DateTime|null
  397.      */
  398.     public function getLastvisitAt(): ?DateTime
  399.     {
  400.         return $this->lastvisitAt;
  401.     }
  402.     /**
  403.      * Set createdAt
  404.      *
  405.      * @param DateTime $createdAt
  406.      *
  407.      * @return Users
  408.      */
  409.     public function setCreatedAt(DateTime $createdAt): Users
  410.     {
  411.         $this->createdAt $createdAt;
  412.         return $this;
  413.     }
  414.     /**
  415.      * Get createdAt
  416.      *
  417.      * @return DateTime|null
  418.      */
  419.     public function getCreatedAt(): ?DateTime
  420.     {
  421.         return $this->createdAt;
  422.     }
  423.     /**
  424.      * Set lastmodAt
  425.      *
  426.      * @param DateTime $lastmodAt
  427.      *
  428.      * @return Users
  429.      */
  430.     public function setLastmodAt(DateTime $lastmodAt): Users
  431.     {
  432.         $this->lastmodAt $lastmodAt;
  433.         return $this;
  434.     }
  435.     /**
  436.      * Get lastmodAt
  437.      *
  438.      * @return DateTime|null
  439.      */
  440.     public function getLastmodAt(): ?DateTime
  441.     {
  442.         return $this->lastmodAt;
  443.     }
  444.     /**
  445.      * @return boolean
  446.      */
  447.     public function isIsDeleted(): bool
  448.     {
  449.         return $this->isDeleted;
  450.     }
  451.     /**
  452.      * @param boolean $isDeleted
  453.      */
  454.     public function setIsDeleted(bool $isDeleted)
  455.     {
  456.         $this->isDeleted $isDeleted;
  457.     }
  458.     public function getPlainPassword()
  459.     {
  460.         return $this->plainPassword;
  461.     }
  462.     public function setPlainPassword($password)
  463.     {
  464.         $this->plainPassword $password;
  465.     }
  466.     /**
  467.      * Get id
  468.      *
  469.      * @return integer
  470.      */
  471.     public function getId(): int
  472.     {
  473.         return $this->id;
  474.     }
  475.     public function isAccountNonExpired(): bool
  476.     {
  477.         return true;
  478.     }
  479.     public function isAccountNonLocked(): bool
  480.     {
  481.         return true;
  482.     }
  483.     public function isCredentialsNonExpired(): bool
  484.     {
  485.         return true;
  486.     }
  487.     public function isEnabled(): bool
  488.     {
  489.         return !$this->getIsDeleted();
  490.     }
  491.     public function getRoles(): array
  492.     {
  493.         return array($this->getAuthRole());
  494.     }
  495.     public function eraseCredentials()
  496.     {
  497.     }
  498.     /** @see \Serializable::serialize() */
  499.     public function serialize(): ?string
  500.     {
  501.         return serialize(array(
  502.             $this->id,
  503.             $this->username,
  504.             $this->password,
  505.             // see section on salt below
  506.             // $this->salt,
  507.         ));
  508.     }
  509.     /** @see \Serializable::unserialize() */
  510.     public function unserialize($serialized)
  511.     {
  512.         list (
  513.             $this->id,
  514.             $this->username,
  515.             $this->password,
  516.             // see section on salt below
  517.             // $this->salt
  518.             ) = unserialize($serialized);
  519.     }
  520.     /**
  521.      * Get isDeleted
  522.      *
  523.      * @return boolean
  524.      */
  525.     public function getIsDeleted(): bool
  526.     {
  527.         return $this->isDeleted;
  528.     }
  529.     /**
  530.      * @return Users|null
  531.      */
  532.     public function getUsers(): ?Users
  533.     {
  534.         return $this->users;
  535.     }
  536.     /**
  537.      * @param Users $users
  538.      */
  539.     public function setUsers(Users $users)
  540.     {
  541.         $this->users $users;
  542.     }
  543.     /**
  544.      * @return int
  545.      */
  546.     public function getUsersId(): int
  547.     {
  548.         return $this->usersId;
  549.     }
  550.     /**
  551.      * @param int $usersId
  552.      */
  553.     public function setUsersId(int $usersId)
  554.     {
  555.         $this->usersId $usersId;
  556.     }
  557.     /**
  558.      * @return null
  559.      */
  560.     public function getPasswordExpire()
  561.     {
  562.         return $this->passwordExpire;
  563.     }
  564.     /**
  565.      * @param null $passwordExpire
  566.      */
  567.     public function setPasswordExpire($passwordExpire)
  568.     {
  569.         $this->passwordExpire $passwordExpire;
  570.     }
  571.     /**
  572.      * @return mixed
  573.      */
  574.     public function getPasswordResetHash()
  575.     {
  576.         return $this->passwordResetHash;
  577.     }
  578.     /**
  579.      * @param mixed $passwordResetHash
  580.      */
  581.     public function setPasswordResetHash($passwordResetHash)
  582.     {
  583.         $this->passwordResetHash $passwordResetHash;
  584.     }
  585.     /**
  586.      * @return DateTime|null
  587.      */
  588.     public function getHashValidUntil(): ?DateTime
  589.     {
  590.         return $this->hashValidUntil;
  591.     }
  592.     /**
  593.      * @param DateTime|null $hashValidUntil
  594.      */
  595.     public function setHashValidUntil(?DateTime $hashValidUntil)
  596.     {
  597.         $this->hashValidUntil $hashValidUntil;
  598.     }
  599.     /**
  600.      * @return DateTime|null
  601.      */
  602.     public function getCredentialsSentLastOn(): ?DateTime
  603.     {
  604.         return $this->credentialsSentLastOn;
  605.     }
  606.     /**
  607.      * @param DateTime|null $credentialsSentLastOn
  608.      */
  609.     public function setCredentialsSentLastOn(?DateTime $credentialsSentLastOn)
  610.     {
  611.         $this->credentialsSentLastOn $credentialsSentLastOn;
  612.     }
  613.     /**
  614.      * @return bool
  615.      */
  616.     public function isSendCredentialsImmediately(): bool
  617.     {
  618.         return $this->sendCredentialsImmediately;
  619.     }
  620.     /**
  621.      * @param bool $sendCredentialsImmediately
  622.      */
  623.     public function setSendCredentialsImmediately(bool $sendCredentialsImmediately)
  624.     {
  625.         $this->sendCredentialsImmediately $sendCredentialsImmediately;
  626.     }
  627.     public function isEqualTo(UserInterface $user): bool
  628.     {
  629.         if ($this->password !== $user->getPassword()) {
  630.             return false;
  631.         }
  632.         if ($this->username !== $user->getUserIdentifier()) {
  633.             return false;
  634.         }
  635.         return true;
  636.     }
  637.     /**
  638.      * @return string
  639.      */
  640.     public function getGoogleId()
  641.     {
  642.         return $this->googleId;
  643.     }
  644.     /**
  645.      * @param string $googleId
  646.      */
  647.     public function setGoogleId($googleId)
  648.     {
  649.         $this->googleId $googleId;
  650.     }
  651.     /**
  652.      * @return string
  653.      */
  654.     public function getGoogleAccessToken()
  655.     {
  656.         return $this->googleAccessToken;
  657.     }
  658.     /**
  659.      * @param string $googleAccessToken
  660.      */
  661.     public function setGoogleAccessToken($googleAccessToken)
  662.     {
  663.         $this->googleAccessToken $googleAccessToken;
  664.     }
  665.     /**
  666.      * @return string
  667.      */
  668.     public function getLinkedinId()
  669.     {
  670.         return $this->linkedinId;
  671.     }
  672.     /**
  673.      * @param string $linkedinId
  674.      */
  675.     public function setLinkedinId($linkedinId)
  676.     {
  677.         $this->linkedinId $linkedinId;
  678.     }
  679.     /**
  680.      * @return string
  681.      */
  682.     public function getLinkedinAccessToken()
  683.     {
  684.         return $this->linkedinAccessToken;
  685.     }
  686.     /**
  687.      * @param string $linkedinAccessToken
  688.      */
  689.     public function setLinkedinAccessToken($linkedinAccessToken)
  690.     {
  691.         $this->linkedinAccessToken $linkedinAccessToken;
  692.     }
  693.     /**
  694.      * @return string|null
  695.      */
  696.     public function getPersonalNumber(): ?string
  697.     {
  698.         return $this->personalNumber;
  699.     }
  700.     /**
  701.      * @param string|null $personalNumber
  702.      */
  703.     public function setPersonalNumber(?string $personalNumber): void
  704.     {
  705.         $this->personalNumber $personalNumber;
  706.     }
  707.     public function getStats(): Collection
  708.     {
  709.         return $this->stats;
  710.     }
  711.     public function setStats(Collection $stats): Stat
  712.     {
  713.         $this->stat $stats;
  714.         return $this;
  715.     }
  716.     public function customFormTitle() {
  717.         return trim($this->getLastName().' '.$this->getFirstName().' ('.$this->getId().')');
  718.     }
  719. }