src/Entity/User.php line 18

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Model\BitrixSerialize;
  4. use Doctrine\ORM\Mapping as ORM;
  5. use JMS\Serializer\Annotation as JMS;
  6. use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
  7. use Symfony\Component\PasswordHasher\Hasher\PasswordHasherAwareInterface;
  8. use Symfony\Component\Security\Core\User\PasswordAuthenticatedUserInterface;
  9. use Symfony\Component\Security\Core\User\UserInterface;
  10. use Symfony\Component\Validator\Constraints as Assert;
  11. /**
  12.  * @ORM\MappedSuperclass
  13.  * @UniqueEntity("email")
  14.  */
  15. class User implements UserInterfaceBitrixSerializePasswordHasherAwareInterfacePasswordAuthenticatedUserInterface
  16. {
  17.     /**
  18.      * Действия над юзером
  19.      */
  20.     public const ACTION_BAN 'ban';
  21.     public const ACTION_DELETE 'delete';
  22.     public const ACTION_UNBAN 'unban';
  23.     /**
  24.      * @ORM\Id
  25.      * @ORM\GeneratedValue
  26.      * @ORM\Column(type="integer")
  27.      * @JMS\Type("integer")
  28.      */
  29.     protected $id;
  30.     /**
  31.      * @ORM\Column(type="string", length=180, unique=true)
  32.      * @Assert\Email
  33.      * @JMS\Type("string")
  34.      */
  35.     protected $email;
  36.     /**
  37.      * @ORM\Column(type="json")
  38.      * @JMS\Type("array")
  39.      */
  40.     protected $roles = [];
  41.     /**
  42.      * @var string The hashed password
  43.      * @ORM\Column(type="string")
  44.      * @JMS\Type("string")
  45.      */
  46.     protected $password;
  47.     /**
  48.      * @ORM\Column(type="integer")
  49.      * @JMS\Type("integer")
  50.      *
  51.      * @var integer
  52.      */
  53.     protected $selectedServiceGroupId 1;
  54.     public function getId(): ?int
  55.     {
  56.         return $this->id;
  57.     }
  58.     /**
  59.      * @param mixed $id
  60.      */
  61.     public function setId($id): void
  62.     {
  63.         $this->id $id;
  64.     }
  65.     public function getEmail(): ?string
  66.     {
  67.         return $this->email;
  68.     }
  69.     public function setEmail(string $email): self
  70.     {
  71.         $this->email $email;
  72.         return $this;
  73.     }
  74.     /**
  75.      * A visual identifier that represents this user.
  76.      *
  77.      * @see UserInterface
  78.      */
  79.     public function getUsername(): string
  80.     {
  81.         return (string) $this->email;
  82.     }
  83.     /**
  84.      * @see UserInterface
  85.      */
  86.     public function getRoles(): array
  87.     {
  88.         $roles $this->roles;
  89.         // guarantee every user at least has ROLE_USER
  90.         $roles[] = 'ROLE_USER';
  91.         return array_unique($roles);
  92.     }
  93.     public function setRoles(array $roles): self
  94.     {
  95.         $this->roles $roles;
  96.         return $this;
  97.     }
  98.     /**
  99.      * @see UserInterface
  100.      */
  101.     public function getPassword(): string
  102.     {
  103.         return (string) $this->password;
  104.     }
  105.     public function setPassword(string $password): self
  106.     {
  107.         $this->password $password;
  108.         return $this;
  109.     }
  110.     /**
  111.      * @see UserInterface
  112.      */
  113.     public function getSalt()
  114.     {
  115.         // not needed when using the "bcrypt" algorithm in security.yaml
  116.     }
  117.     /**
  118.      * @see UserInterface
  119.      */
  120.     public function eraseCredentials()
  121.     {
  122.         // If you store any temporary, sensitive data on the user, clear it here
  123.         // $this->plainPassword = null;
  124.     }
  125.     /**
  126.      * @return int
  127.      */
  128.     public function getSelectedServiceGroupId(): int
  129.     {
  130.         return $this->selectedServiceGroupId;
  131.     }
  132.     /**
  133.      * @param int $selectedServiceGroupId
  134.      */
  135.     public function setSelectedServiceGroupId(int $selectedServiceGroupId): void
  136.     {
  137.         $this->selectedServiceGroupId $selectedServiceGroupId;
  138.     }
  139.     public function serializeBitrix(): array
  140.     {
  141.         return [
  142.             'EMAIL'   => [
  143.                 "n0" => [
  144.                     "VALUE"      => $this->getEmail(),
  145.                     "VALUE_TYPE" => "WORK",
  146.                 ]
  147.             ],
  148.             "TYPE_ID" => "CLIENT",
  149.         ];
  150.     }
  151.     /**
  152.      * @return bool
  153.      */
  154.     public function isBanned(): bool
  155.     {
  156.         return in_array('ROLE_BAN'$this->getRoles());
  157.     }
  158.     /**
  159.      * Returns the identifier for this user (e.g. its username or email address).
  160.      */
  161.     public function getUserIdentifier(): string
  162.     {
  163.         return (string) $this->email;
  164.     }
  165.     public function getPasswordHasherName(): ?string
  166.     {
  167.         return 'harsh';
  168.     }
  169. }