<?php
namespace JF\JuridicusBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
use Doctrine\Common\Collections\ArrayCollection;
use DateTimeInterface;
use Symfony\Component\Security\Core\User\PasswordAuthenticatedUserInterface;
use Symfony\Component\Security\Core\User\UserInterface;
/**
* User
*/
class User implements UserInterface, PasswordAuthenticatedUserInterface
{
const CLASSNAME = __CLASS__;
/**
* @var integer
*/
protected $id;
/**
* @var \JF\JuridicusBundle\Entity\Kunde
*/
private $kunde;
/**
* @var \JF\JuridicusBundle\Entity\Partner
*/
private $partner;
/**
* @var \Doctrine\Common\Collections\Collection
*/
private $pruefer;
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;
/**
* @var \Doctrine\Common\Collections\Collection
*/
private $pruefungen;
/**
* Constructor.
*/
public function __construct()
{
$this->pruefer = new ArrayCollection();
$this->pruefungen = new ArrayCollection();
$this->createdAt = new \DateTimeImmutable();
}
// 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);
}
}
public function eraseCredentials() {}
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;
}
public function getConfirmationToken(): ?string
{
return $this->confirmationToken;
}
// UserInterface Methoden
public function getRoles(): array
{
$roles = $this->roles;
$roles[] = 'ROLE_USER'; // immer mindestens ROLE_USER
return array_unique($roles);
}
public function setRoles(array $roles): self
{
$this->roles = $roles;
return $this;
}
public function isEnabled(): bool
{
return $this->enabled;
}
public function setEnabled(bool $enabled): self
{
$this->enabled = $enabled;
return $this;
}
public function getUserIdentifier(): string
{
return $this->email;
}
/**
* Get id
*
* @return integer
*/
public function getId()
{
return $this->id;
}
/**
* Set kunde [INVERSE SIDE]
*
* @param \JF\JuridicusBundle\Entity\Kunde $kunde
* @return User
*/
public function setKunde(Kunde $kunde = null)
{
$this->kunde = $kunde;
return $this;
}
/**
* Get kunde
*
* @return \JF\JuridicusBundle\Entity\Kunde
*/
public function getKunde()
{
return $this->kunde;
}
/**
* Hook on pre-persist operations
*/
public function prePersist() : void
{
if (!isset($this->createdAt)) {
$this->createdAt = new \DateTime();
}
if (!isset($this->updatedAt)) {
$this->updatedAt = new \DateTime();
}
if ($this->confirmationToken === '') {
$this->confirmationToken = null;
}
}
/**
* Hook on pre-update operations
*/
public function preUpdate() : void
{
if (!isset($this->updatedAt)) {
$this->updatedAt = new \DateTime();
}
}
/**
* Get the truncated email
*
* @return string
*/
public function getObfuscatedEmail()
{
$email = $this->email;
if (false !== $pos = strpos($email, '@')) {
$email = '...' . substr($email, $pos);
}
return $email;
}
/**
* Set partner [INVERSE SIDE]
*
* @param \JF\JuridicusBundle\Entity\Partner $partner
* @return User
*/
public function setPartner(Partner $partner = null)
{
$this->partner = $partner;
return $this;
}
/**
* Get partner
*
* @return \JF\JuridicusBundle\Entity\Partner
*/
public function getPartner()
{
return $this->partner;
}
/**
* Add pruefer
*
* @param \JF\JuridicusBundle\Entity\Pruefer $pruefer
* @return User
*/
public function addPruefer(Pruefer $pruefer)
{
$this->pruefer[] = $pruefer;
return $this;
}
/**
* Remove pruefer
*
* @param \JF\JuridicusBundle\Entity\Pruefer $pruefer
*/
public function removePruefer(Pruefer $pruefer)
{
$this->pruefer->removeElement($pruefer);
}
/**
* Get pruefer
*
* @return \Doctrine\Common\Collections\Collection
*/
public function getPruefer()
{
return $this->pruefer;
}
/**
* Add pruefungen
*
* @param \JF\JuridicusBundle\Entity\Pruefung $pruefungen
* @return User
*/
public function addPruefungen(Pruefung $pruefungen)
{
$this->pruefungen[] = $pruefungen;
return $this;
}
/**
* Remove pruefungen
*
* @param \JF\JuridicusBundle\Entity\Pruefung $pruefungen
*/
public function removePruefungen(Pruefung $pruefungen)
{
$this->pruefungen->removeElement($pruefungen);
}
/**
* Get pruefungen
*
* @return \Doctrine\Common\Collections\Collection
*/
public function getPruefungen()
{
return $this->pruefungen;
}
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 ;
}
}