src/JuridicusBundle/Entity/User.php line 27

Open in your IDE?
  1. <?php
  2. namespace JF\JuridicusBundle\Entity;
  3. use Doctrine\ORM\Mapping as ORM;
  4. use Doctrine\Common\Collections\ArrayCollection;
  5. use DateTimeInterface;
  6. use Symfony\Component\Security\Core\User\PasswordAuthenticatedUserInterface;
  7. use Symfony\Component\Security\Core\User\UserInterface;
  8. /**
  9.  * User
  10.  */
  11. class User implements UserInterfacePasswordAuthenticatedUserInterface
  12. {
  13.       const CLASSNAME __CLASS__;
  14.     /**
  15.      * @var integer
  16.      */
  17.     protected $id;
  18.     /**
  19.      * @var \JF\JuridicusBundle\Entity\Kunde
  20.      */
  21.     private $kunde;
  22.     /**
  23.      * @var \JF\JuridicusBundle\Entity\Partner
  24.      */
  25.     private $partner;
  26.     /**
  27.      * @var \Doctrine\Common\Collections\Collection
  28.      */
  29.     private $pruefer;
  30.     private $username;     private $usernameCanonical;     private $email;     private $emailCanonical;     private $password;     private $salt;     private $roles = [];     private $enabled;     private $lastLogin;     private ?DateTimeInterface $updatedAt null;     private ?DateTimeInterface $createdAt null;     private ?DateTimeInterface $passwordRequestedAt null;     private ?string $confirmationToken null;     private $plainPassword;     private ?bool $locked false;
  31.     /**
  32.      * @var \Doctrine\Common\Collections\Collection
  33.      */
  34.     private $pruefungen;
  35.     /**
  36.      * Constructor.
  37.      */
  38.     public function __construct()
  39.     {
  40.         $this->pruefer = new ArrayCollection();
  41.         $this->pruefungen = new ArrayCollection();         $this->createdAt = new \DateTimeImmutable();
  42.     }
  43.     // NEW 5.4 update     public function hasRole($role) {         return in_array($role$this->getRoles());     }          public function addRole($role) {         if (!$this->hasRole($role)) {             $roles $this->getRoles();             $roles[] = $role;             $this->setRoles($roles);         }     }     
  44.     public function eraseCredentials() {}
  45.     public function getPassword(): string     {         return $this->password;     }     public function getSalt(): ?string     {         return $this->salt;     }     public function setPassword(string $password): self     {         $this->password $password;         return $this;     }          public function getPlainPassword(): string     {         return $this->plainPassword;     }          public function setPlainPassword(string $plainPassword): self     {         $this->plainPassword $plainPassword;         return $this;     }          public function getUsername(): ?string     {         return $this->username;     }          public function setUsername(string $username): self     {         $this->username $username;         return $this;     }     public function getEmail(): ?string     {         return $this->email;     }          public function setEmail(string $email): self     {         $this->email $email;         return $this;     }     public function setSalt(?string $salt): self     {         $this->salt $salt;         return $this;     }     public function setConfirmationToken(?string $confirmationToken): self     {         $this->confirmationToken $confirmationToken ?: null;         return $this;     }     
  46.     public function getConfirmationToken(): ?string     {         return $this->confirmationToken;     }
  47.     // UserInterface Methoden
  48.     public function getRoles(): array
  49.     {
  50.                  $roles $this->roles;         if (is_string($roles)) {             $roles = @unserialize($roles) ?: [];         }         if (!is_array($roles)) {             $roles = [];         }         $roles[] = 'ROLE_USER';         return array_values(array_unique($roles));
  51.     }
  52.     public function setRoles(array $roles): self
  53.     {
  54.         $this->roles $roles;
  55.         return $this;
  56.     }     public function isEnabled(): bool     {         return $this->enabled;     }     public function setEnabled(bool $enabled): self     {         $this->enabled $enabled;         return $this;     }
  57.     public function getUserIdentifier(): string
  58.     {
  59.         return $this->email;
  60.     }
  61.     /**
  62.      * Get id
  63.      *
  64.      * @return integer
  65.      */
  66.     public function getId()
  67.     {
  68.         return $this->id;
  69.     }
  70.     /**
  71.      * Set kunde [INVERSE SIDE]
  72.      *
  73.      * @param \JF\JuridicusBundle\Entity\Kunde $kunde
  74.      * @return User
  75.      */
  76.     public function setKunde(Kunde $kunde null)
  77.     {
  78.         $this->kunde $kunde;
  79.         return $this;
  80.     }
  81.     /**
  82.      * Get kunde
  83.      *
  84.      * @return \JF\JuridicusBundle\Entity\Kunde
  85.      */
  86.     public function getKunde()
  87.     {
  88.         return $this->kunde;
  89.     }
  90.     /**
  91.      * Hook on pre-persist operations
  92.      */
  93.     public function prePersist() : void
  94.     {
  95.         if (!isset($this->createdAt)) {
  96.             $this->createdAt = new \DateTime();
  97.         }
  98.         if (!isset($this->updatedAt)) {
  99.             $this->updatedAt = new \DateTime();
  100.         }         if ($this->confirmationToken === '') {             $this->confirmationToken null;         }
  101.     }
  102.     /**
  103.      * Hook on pre-update operations
  104.      */
  105.     public function preUpdate()  : void
  106.     {
  107.         if (!isset($this->updatedAt)) {
  108.             $this->updatedAt = new \DateTime();
  109.         }
  110.     }
  111.     /**
  112.      * Get the truncated email
  113.      *
  114.      * @return string
  115.      */
  116.     public function getObfuscatedEmail()
  117.     {
  118.            $email $this->email;
  119.         if (false !== $pos strpos($email'@')) {
  120.             $email '...' substr($email$pos);
  121.         }
  122.         return $email;
  123.     }
  124.     /**
  125.      * Set partner [INVERSE SIDE]
  126.      *
  127.      * @param \JF\JuridicusBundle\Entity\Partner $partner
  128.      * @return User
  129.      */
  130.     public function setPartner(Partner $partner null)
  131.     {
  132.         $this->partner $partner;
  133.         return $this;
  134.     }
  135.     /**
  136.      * Get partner
  137.      *
  138.      * @return \JF\JuridicusBundle\Entity\Partner
  139.      */
  140.     public function getPartner()
  141.     {
  142.         return $this->partner;
  143.     }
  144.     /**
  145.      * Add pruefer
  146.      *
  147.      * @param \JF\JuridicusBundle\Entity\Pruefer $pruefer
  148.      * @return User
  149.      */
  150.     public function addPruefer(Pruefer $pruefer)
  151.     {
  152.         $this->pruefer[] = $pruefer;
  153.         return $this;
  154.     }
  155.     /**
  156.      * Remove pruefer
  157.      *
  158.      * @param \JF\JuridicusBundle\Entity\Pruefer $pruefer
  159.      */
  160.     public function removePruefer(Pruefer $pruefer)
  161.     {
  162.         $this->pruefer->removeElement($pruefer);
  163.     }
  164.     /**
  165.      * Get pruefer
  166.      *
  167.      * @return \Doctrine\Common\Collections\Collection
  168.      */
  169.     public function getPruefer()
  170.     {
  171.         return $this->pruefer;
  172.     }
  173.     /**
  174.      * Add pruefungen
  175.      *
  176.      * @param \JF\JuridicusBundle\Entity\Pruefung $pruefungen
  177.      * @return User
  178.      */
  179.     public function addPruefungen(Pruefung $pruefungen)
  180.     {
  181.         $this->pruefungen[] = $pruefungen;
  182.         return $this;
  183.     }
  184.     /**
  185.      * Remove pruefungen
  186.      *
  187.      * @param \JF\JuridicusBundle\Entity\Pruefung $pruefungen
  188.      */
  189.     public function removePruefungen(Pruefung $pruefungen)
  190.     {
  191.         $this->pruefungen->removeElement($pruefungen);
  192.     }
  193.     /**
  194.      * Get pruefungen
  195.      *
  196.      * @return \Doctrine\Common\Collections\Collection
  197.      */
  198.     public function getPruefungen()
  199.     {
  200.         return $this->pruefungen;
  201.     }          public function isPasswordRequestNonExpired(int $ttl): bool     {         if (null === $this->passwordRequestedAt) {             return false;         }         return $this->passwordRequestedAt->getTimestamp() + $ttl time();     }          public function setUpdatedAt(?DateTimeInterface $updatedAt): self     {         $this->updatedAt $updatedAt;         return $this;     }     public function getUpdatedAt(): DateTimeInterface     {         return $this->updatedAt ;     }          public function isLocked(): bool     {         return (bool) $this->locked;     }     public function getLocked(): bool     {         return (bool) $this->locked;     }     public function setLocked(?bool $locked): self     {         $this->locked = (bool) $locked;         return $this;     }          public function setCreatedAt(?\DateTimeInterface $updatedAt): self     {         $this->createdAt $createdAt;         return $this;     }     public function getCreatedAtt(): DateTimeInterface     {         return $this->createdAt ;     }          public function setPasswordRequestedAt(?\DateTimeInterface $passwordRequestedAt): self     {         $this->passwordRequestedAt $passwordRequestedAt;         return $this;     }     public function getPasswordRequestedAt(): DateTimeInterface     {         return $this->passwordRequestedAt ;     }
  202. }