src/Entity/User.php line 24

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use Doctrine\ORM\Mapping as ORM;
  4. use App\Entity\Password;
  5. use App\Controller\AppBundle\Interact\UserInformation;
  6. use App\Controller\AppBundle\Interact\UserInformationANVA;
  7. use App\Controller\AppBundle\Interact\UserInformationAssu;
  8. use Doctrine\ORM\EntityManagerInterface;
  9. use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
  10. use Symfony\Component\Security\Core\Encoder\BCryptPasswordEncoder;
  11. use Symfony\Component\Security\Core\Encoder\EncoderFactory;
  12. use Symfony\Component\Security\Core\Encoder\UserPasswordEncoder;
  13. use Symfony\Component\Security\Core\User\PasswordAuthenticatedUserInterface;
  14. use Symfony\Component\Security\Core\User\UserInterface;
  15. /**
  16.  * User
  17.  */
  18. #[ORM\Table(name'user')]
  19. #[ORM\Entity(repositoryClass'App\Repository\UserRepository')]
  20. class User implements UserInterface\SerializablePasswordAuthenticatedUserInterface
  21. {
  22.     /**
  23.      * @var int
  24.      */
  25.     #[ORM\Column(name'id'type'integer')]
  26.     #[ORM\Id]
  27.     #[ORM\GeneratedValue(strategy'AUTO')]
  28.     private $id;
  29.     /**
  30.      * @var string
  31.      */
  32.     #[ORM\Column(name'email'type'string'length255)]
  33.     private $email;
  34.     /**
  35.      * @var string
  36.      */
  37.     #[ORM\Column(name'password'type'string'length255)]
  38.     private $password;
  39.     /**
  40.      * @var string
  41.      */
  42.     #[ORM\Column(name'anvaKey'type'string'length255)]
  43.     private $anvaKey;
  44.     /**
  45.      * @var boolean
  46.      */
  47.     #[ORM\Column(name'assu'type'boolean'nullabletrue)]
  48.     private $assu;
  49.     /**
  50.      * @var boolean
  51.      */
  52.     #[ORM\Column(name'ff'type'boolean'nullabletrue)]
  53.     public $ff false;
  54.     /**
  55.      * Get id
  56.      *
  57.      * @return int
  58.      */
  59.     public function getId()
  60.     {
  61.         return $this->id;
  62.     }
  63.     /**
  64.      * Set email
  65.      *
  66.      * @param string $email
  67.      *
  68.      * @return User
  69.      */
  70.     public function setEmail($email)
  71.     {
  72.         $this->email $email;
  73.         return $this;
  74.     }
  75.     /**
  76.      * Get email
  77.      *
  78.      * @return string
  79.      */
  80.     public function getEmail()
  81.     {
  82.         return $this->email;
  83.     }
  84.     /**
  85.      * Set password
  86.      *
  87.      * @param string $password
  88.      *
  89.      * @return User
  90.      */
  91.     public function setPassword($password)
  92.     {
  93.         $this->password $password;
  94.         return $this;
  95.     }
  96.     /**
  97.      * Get password
  98.      *
  99.      * @return string
  100.      */
  101.     public function getPassword(): null|string
  102.     {
  103.         return $this->password;
  104.     }
  105.     /**
  106.      * Set anvaKey
  107.      *
  108.      * @param string $anvaKey
  109.      *
  110.      * @return User
  111.      */
  112.     public function setAnvaKey($anvaKey)
  113.     {
  114.         $this->anvaKey $anvaKey;
  115.         return $this;
  116.     }
  117.     /**
  118.      * Get anvaKey
  119.      *
  120.      * @return string
  121.      */
  122.     public function getAnvaKey()
  123.     {
  124.         return $this->anvaKey;
  125.     }
  126.     /**
  127.      * Returns the roles granted to the user.
  128.      * @return string[] The user roles
  129.      */
  130.     public function getRoles(): array
  131.     {
  132.         return ['ROLE_USER'];
  133.     }
  134.     /**
  135.      * Returns the salt that was originally used to encode the password.
  136.      * @return string|null The salt
  137.      */
  138.     public function getSalt()
  139.     {
  140.         return null;
  141.     }
  142.     /**
  143.      * Returns the username used to authenticate the user.
  144.      *
  145.      * @return string The username
  146.      */
  147.     public function getUsername()
  148.     {
  149.         return $this->getEmail();
  150.     }
  151.     /**
  152.      * Returns the username used to authenticate the user.
  153.      *
  154.      * @return string The username
  155.      */
  156.     public function getUserIdentifier(): string
  157.     {
  158.         return $this->getEmail();
  159.     }
  160.     /**
  161.      * Removes sensitive data from the user.
  162.      *
  163.      * This is important if, at any given point, sensitive information like
  164.      * the plain-text password is stored on this object.
  165.      */
  166.     public function eraseCredentials()
  167.     {
  168.     }
  169.     /**
  170.      * @param bool $saveToSession
  171.      * @return UserInformation|array
  172.      * @throws \Exception
  173.      */
  174.     public function info($saveToSession true$bedrijf null)
  175.     {
  176.         if ($this->inAssu()) {
  177.             return new UserInformationAssu($thisfalse$saveToSession);
  178.         }
  179.         return new UserInformationANVA($thisfalse$saveToSession);
  180.     }
  181.     public function inAssu()
  182.     {
  183.         if (isset($this->assu)) {
  184.             return $this->assu;
  185.         }
  186.         return false;
  187.     }
  188.     public function hasAnvaPolicies()
  189.     {
  190.         if (!$this->inAssu() && !$this->inFF()) {
  191.             return true;
  192.         }
  193.         $polissen $this->info()->collection('polissen');
  194.         foreach ($polissen as $polis) {
  195.             if (substr($polis->view('polisnummer'), 05) == "8056-") {
  196.                 return substr($polis->view('polisnummer'), 0strpos($polis->view('polisnummer'), "-"5));
  197.             }
  198.         }
  199.         return false;
  200.     }
  201.     public function isLinked(EntityManagerInterface $em)
  202.     {
  203.         if ($this->inAssu()) {
  204.             $link $em->getRepository(AssuAnvaLink::class)->findOneByKeyASSU($this->getAnvaKey());
  205.         } elseif ($this->inFF()) {
  206.             $link $em->getRepository(FFAnvaLink::class)->findOneByKeyFF($this->getAnvaKey());
  207.         } else {
  208.             $link $em->getRepository(AssuAnvaLink::class)->findOneByKeyANVA($this->getAnvaKey());
  209.             if (!isset($link)) {
  210.                 $link $em->getRepository(FFAnvaLink::class)->findOneByKeyANVA($this->getAnvaKey());
  211.             }
  212.         }
  213.         if (isset($link)) {
  214.             return true;
  215.         }
  216.         return false;
  217.     }
  218.     public function getLinkedAnva(EntityManagerInterface $em)
  219.     {
  220.         if ($this->isLinked($em)) {
  221.             if ($this->inAssu()) {
  222.                 $link $em->getRepository(AssuAnvaLink::class)->findOneByKeyASSU($this->getAnvaKey());
  223.             } elseif ($this->inFF()) {
  224.                 $link $em->getRepository(AssuAnvaLink::class)->findOneByKeyASSU($this->getAnvaKey());
  225.             }
  226.             return $link->getKeyAnva();
  227.         }
  228.         return null;
  229.     }
  230.     public function getLinkedAssu(EntityManagerInterface $em)
  231.     {
  232.         if ($this->isLinked($em)) {
  233.             $link $em->getRepository(AssuAnvaLink::class)->findOneByKeyANVA($this->getAnvaKey());
  234.             return $link->getKeyAssu();
  235.         }
  236.         return null;
  237.     }
  238.     /**
  239.      * @param $password Password that will be checked
  240.      * @return bool Is this password for this user
  241.      */
  242.     public function validatePassword($password)
  243.     {
  244.         $encoders = [
  245.             User::class => new BCryptPasswordEncoder(13)
  246.         ];
  247.         $encoderFactory = new EncoderFactory($encoders);
  248.         $encoder = new UserPasswordEncoder($encoderFactory);
  249.         return $encoder->isPasswordValid($this$password);
  250.     }
  251.     /**
  252.      * String representation of object.
  253.      * @return string the string representation of the object or null
  254.      */
  255.     public function serialize()
  256.     {
  257.         return serialize([
  258.             $this->id,
  259.             $this->email,
  260.             $this->password,
  261.             $this->anvaKey,
  262.             $this->assu,
  263.             $this->ff,
  264.         ]);
  265.     }
  266.     /**
  267.      * Constructs the object.
  268.      * @param string $serialized
  269.      * @return void
  270.      */
  271.     public function unserialize($serialized)
  272.     {
  273.         [
  274.             $this->id,
  275.             $this->email,
  276.             $this->password,
  277.             $this->anvaKey,
  278.             $this->assu,
  279.             $this->ff
  280.         ] = unserialize($serialized);
  281.     }
  282.     /**
  283.      * @return boolean
  284.      */
  285.     public function getAssu()
  286.     {
  287.         return $this->assu;
  288.     }
  289.     /**
  290.      * @param boolean $assu
  291.      */
  292.     public function setAssu($assu)
  293.     {
  294.         $this->assu $assu;
  295.     }
  296.     public function inFF()
  297.     {
  298.         if (isset($this->ff)) {
  299.             return $this->ff;
  300.         }
  301.         return false;
  302.     }
  303. }