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;
  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;
  51.         $roles[] = 'ROLE_USER'// immer mindestens ROLE_USER
  52.         return array_unique($roles);
  53.     }
  54.     public function setRoles(array $roles): self
  55.     {
  56.         $this->roles $roles;
  57.         return $this;
  58.     }     public function isEnabled(): bool     {         return $this->enabled;     }     public function setEnabled(bool $enabled): self     {         $this->enabled $enabled;         return $this;     }
  59.     public function getUserIdentifier(): string
  60.     {
  61.         return $this->email;
  62.     }
  63.     /**
  64.      * Get id
  65.      *
  66.      * @return integer
  67.      */
  68.     public function getId()
  69.     {
  70.         return $this->id;
  71.     }
  72.     /**
  73.      * Set kunde [INVERSE SIDE]
  74.      *
  75.      * @param \JF\JuridicusBundle\Entity\Kunde $kunde
  76.      * @return User
  77.      */
  78.     public function setKunde(Kunde $kunde null)
  79.     {
  80.         $this->kunde $kunde;
  81.         return $this;
  82.     }
  83.     /**
  84.      * Get kunde
  85.      *
  86.      * @return \JF\JuridicusBundle\Entity\Kunde
  87.      */
  88.     public function getKunde()
  89.     {
  90.         return $this->kunde;
  91.     }
  92.     /**
  93.      * Hook on pre-persist operations
  94.      */
  95.     public function prePersist() : void
  96.     {
  97.         if (!isset($this->createdAt)) {
  98.             $this->createdAt = new \DateTime();
  99.         }
  100.         if (!isset($this->updatedAt)) {
  101.             $this->updatedAt = new \DateTime();
  102.         }         if ($this->confirmationToken === '') {             $this->confirmationToken null;         }
  103.     }
  104.     /**
  105.      * Hook on pre-update operations
  106.      */
  107.     public function preUpdate()  : void
  108.     {
  109.         if (!isset($this->updatedAt)) {
  110.             $this->updatedAt = new \DateTime();
  111.         }
  112.     }
  113.     /**
  114.      * Get the truncated email
  115.      *
  116.      * @return string
  117.      */
  118.     public function getObfuscatedEmail()
  119.     {
  120.            $email $this->email;
  121.         if (false !== $pos strpos($email'@')) {
  122.             $email '...' substr($email$pos);
  123.         }
  124.         return $email;
  125.     }
  126.     /**
  127.      * Set partner [INVERSE SIDE]
  128.      *
  129.      * @param \JF\JuridicusBundle\Entity\Partner $partner
  130.      * @return User
  131.      */
  132.     public function setPartner(Partner $partner null)
  133.     {
  134.         $this->partner $partner;
  135.         return $this;
  136.     }
  137.     /**
  138.      * Get partner
  139.      *
  140.      * @return \JF\JuridicusBundle\Entity\Partner
  141.      */
  142.     public function getPartner()
  143.     {
  144.         return $this->partner;
  145.     }
  146.     /**
  147.      * Add pruefer
  148.      *
  149.      * @param \JF\JuridicusBundle\Entity\Pruefer $pruefer
  150.      * @return User
  151.      */
  152.     public function addPruefer(Pruefer $pruefer)
  153.     {
  154.         $this->pruefer[] = $pruefer;
  155.         return $this;
  156.     }
  157.     /**
  158.      * Remove pruefer
  159.      *
  160.      * @param \JF\JuridicusBundle\Entity\Pruefer $pruefer
  161.      */
  162.     public function removePruefer(Pruefer $pruefer)
  163.     {
  164.         $this->pruefer->removeElement($pruefer);
  165.     }
  166.     /**
  167.      * Get pruefer
  168.      *
  169.      * @return \Doctrine\Common\Collections\Collection
  170.      */
  171.     public function getPruefer()
  172.     {
  173.         return $this->pruefer;
  174.     }
  175.     /**
  176.      * Add pruefungen
  177.      *
  178.      * @param \JF\JuridicusBundle\Entity\Pruefung $pruefungen
  179.      * @return User
  180.      */
  181.     public function addPruefungen(Pruefung $pruefungen)
  182.     {
  183.         $this->pruefungen[] = $pruefungen;
  184.         return $this;
  185.     }
  186.     /**
  187.      * Remove pruefungen
  188.      *
  189.      * @param \JF\JuridicusBundle\Entity\Pruefung $pruefungen
  190.      */
  191.     public function removePruefungen(Pruefung $pruefungen)
  192.     {
  193.         $this->pruefungen->removeElement($pruefungen);
  194.     }
  195.     /**
  196.      * Get pruefungen
  197.      *
  198.      * @return \Doctrine\Common\Collections\Collection
  199.      */
  200.     public function getPruefungen()
  201.     {
  202.         return $this->pruefungen;
  203.     }          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 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 ;     }
  204. }