<?php
namespace App\Entity;
use Doctrine\ORM\Mapping as ORM;
use App\Entity\Password;
use App\Controller\AppBundle\Interact\UserInformation;
use App\Controller\AppBundle\Interact\UserInformationANVA;
use App\Controller\AppBundle\Interact\UserInformationAssu;
use Doctrine\ORM\EntityManagerInterface;
use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
use Symfony\Component\Security\Core\Encoder\BCryptPasswordEncoder;
use Symfony\Component\Security\Core\Encoder\EncoderFactory;
use Symfony\Component\Security\Core\Encoder\UserPasswordEncoder;
use Symfony\Component\Security\Core\User\PasswordAuthenticatedUserInterface;
use Symfony\Component\Security\Core\User\UserInterface;
/**
* User
*/
#[ORM\Table(name: 'user')]
#[ORM\Entity(repositoryClass: 'App\Repository\UserRepository')]
class User implements UserInterface, \Serializable, PasswordAuthenticatedUserInterface
{
/**
* @var int
*/
#[ORM\Column(name: 'id', type: 'integer')]
#[ORM\Id]
#[ORM\GeneratedValue(strategy: 'AUTO')]
private $id;
/**
* @var string
*/
#[ORM\Column(name: 'email', type: 'string', length: 255)]
private $email;
/**
* @var string
*/
#[ORM\Column(name: 'password', type: 'string', length: 255)]
private $password;
/**
* @var string
*/
#[ORM\Column(name: 'anvaKey', type: 'string', length: 255)]
private $anvaKey;
/**
* @var boolean
*/
#[ORM\Column(name: 'assu', type: 'boolean', nullable: true)]
private $assu;
/**
* @var boolean
*/
#[ORM\Column(name: 'ff', type: 'boolean', nullable: true)]
public $ff = false;
/**
* Get id
*
* @return int
*/
public function getId()
{
return $this->id;
}
/**
* Set email
*
* @param string $email
*
* @return User
*/
public function setEmail($email)
{
$this->email = $email;
return $this;
}
/**
* Get email
*
* @return string
*/
public function getEmail()
{
return $this->email;
}
/**
* Set password
*
* @param string $password
*
* @return User
*/
public function setPassword($password)
{
$this->password = $password;
return $this;
}
/**
* Get password
*
* @return string
*/
public function getPassword(): null|string
{
return $this->password;
}
/**
* Set anvaKey
*
* @param string $anvaKey
*
* @return User
*/
public function setAnvaKey($anvaKey)
{
$this->anvaKey = $anvaKey;
return $this;
}
/**
* Get anvaKey
*
* @return string
*/
public function getAnvaKey()
{
return $this->anvaKey;
}
/**
* Returns the roles granted to the user.
* @return string[] The user roles
*/
public function getRoles(): array
{
return ['ROLE_USER'];
}
/**
* Returns the salt that was originally used to encode the password.
* @return string|null The salt
*/
public function getSalt()
{
return null;
}
/**
* Returns the username used to authenticate the user.
*
* @return string The username
*/
public function getUsername()
{
return $this->getEmail();
}
/**
* Returns the username used to authenticate the user.
*
* @return string The username
*/
public function getUserIdentifier(): string
{
return $this->getEmail();
}
/**
* Removes sensitive data from the user.
*
* This is important if, at any given point, sensitive information like
* the plain-text password is stored on this object.
*/
public function eraseCredentials()
{
}
/**
* @param bool $saveToSession
* @return UserInformation|array
* @throws \Exception
*/
public function info($saveToSession = true, $bedrijf = null)
{
if ($this->inAssu()) {
return new UserInformationAssu($this, false, $saveToSession);
}
return new UserInformationANVA($this, false, $saveToSession);
}
public function inAssu()
{
if (isset($this->assu)) {
return $this->assu;
}
return false;
}
public function hasAnvaPolicies()
{
if (!$this->inAssu() && !$this->inFF()) {
return true;
}
$polissen = $this->info()->collection('polissen');
foreach ($polissen as $polis) {
if (substr($polis->view('polisnummer'), 0, 5) == "8056-") {
return substr($polis->view('polisnummer'), 0, strpos($polis->view('polisnummer'), "-", 5));
}
}
return false;
}
public function isLinked(EntityManagerInterface $em)
{
if ($this->inAssu()) {
$link = $em->getRepository(AssuAnvaLink::class)->findOneByKeyASSU($this->getAnvaKey());
} elseif ($this->inFF()) {
$link = $em->getRepository(FFAnvaLink::class)->findOneByKeyFF($this->getAnvaKey());
} else {
$link = $em->getRepository(AssuAnvaLink::class)->findOneByKeyANVA($this->getAnvaKey());
if (!isset($link)) {
$link = $em->getRepository(FFAnvaLink::class)->findOneByKeyANVA($this->getAnvaKey());
}
}
if (isset($link)) {
return true;
}
return false;
}
public function getLinkedAnva(EntityManagerInterface $em)
{
if ($this->isLinked($em)) {
if ($this->inAssu()) {
$link = $em->getRepository(AssuAnvaLink::class)->findOneByKeyASSU($this->getAnvaKey());
} elseif ($this->inFF()) {
$link = $em->getRepository(AssuAnvaLink::class)->findOneByKeyASSU($this->getAnvaKey());
}
return $link->getKeyAnva();
}
return null;
}
public function getLinkedAssu(EntityManagerInterface $em)
{
if ($this->isLinked($em)) {
$link = $em->getRepository(AssuAnvaLink::class)->findOneByKeyANVA($this->getAnvaKey());
return $link->getKeyAssu();
}
return null;
}
/**
* @param $password Password that will be checked
* @return bool Is this password for this user
*/
public function validatePassword($password)
{
$encoders = [
User::class => new BCryptPasswordEncoder(13)
];
$encoderFactory = new EncoderFactory($encoders);
$encoder = new UserPasswordEncoder($encoderFactory);
return $encoder->isPasswordValid($this, $password);
}
/**
* String representation of object.
* @return string the string representation of the object or null
*/
public function serialize()
{
return serialize([
$this->id,
$this->email,
$this->password,
$this->anvaKey,
$this->assu,
$this->ff,
]);
}
/**
* Constructs the object.
* @param string $serialized
* @return void
*/
public function unserialize($serialized)
{
[
$this->id,
$this->email,
$this->password,
$this->anvaKey,
$this->assu,
$this->ff
] = unserialize($serialized);
}
/**
* @return boolean
*/
public function getAssu()
{
return $this->assu;
}
/**
* @param boolean $assu
*/
public function setAssu($assu)
{
$this->assu = $assu;
}
public function inFF()
{
if (isset($this->ff)) {
return $this->ff;
}
return false;
}
}