src/WebBundle/Entity/User.php line 31

Open in your IDE?
  1. <?php
  2. namespace WebBundle\Entity;
  3. use DateTime;
  4. use Doctrine\Common\Collections\ArrayCollection;
  5. use Doctrine\ORM\Mapping as ORM;
  6. use Doctrine\ORM\PersistentCollection;
  7. use Exception;
  8. use FlexApp\Constant\TimeConstant;
  9. use Serializable;
  10. use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
  11. use Symfony\Component\Security\Core\User\PasswordAuthenticatedUserInterface;
  12. use Symfony\Component\Security\Core\User\UserInterface;
  13. use Symfony\Component\Serializer\Annotation\Groups;
  14. use WebBundle\Helper\App;
  15. use WebBundle\Helper\UserHelper;
  16. use WebBundle\Validator\Constraints as AcmeAssert;
  17. /**
  18.  * User.
  19.  *
  20.  * @AcmeAssert\UniqueUserEmail
  21.  * @AcmeAssert\ValidUserEmail
  22.  * @AcmeAssert\ValidUserPass
  23.  * @ORM\Table(name="user", indexes={@ORM\Index(name="user_token_idx", columns={"token"})},
  24.  *     options={"comment" = "Пользователи"})
  25.  * @ORM\Entity(repositoryClass="WebBundle\Repository\UserRepository")
  26.  * @UniqueEntity("email")
  27.  */
  28. class User implements UserInterfacePasswordAuthenticatedUserInterfaceSerializable
  29. {
  30.     public const ROLE_DEFAULT 'ROLE_USER';
  31.     /**
  32.      * @var int|null
  33.      * @Groups("serialize")
  34.      *
  35.      * @ORM\Column(name="id", type="integer")
  36.      * @ORM\Id
  37.      * @ORM\GeneratedValue(strategy="AUTO")
  38.      */
  39.     protected $id;
  40.     /**
  41.      * @var ?string
  42.      * @Groups("serialize")
  43.      *
  44.      * @ORM\Column(name="unid", type="string", unique=true, nullable=true, length=36,
  45.      * options={"comment" = "идентификатор пользователя на портале"})
  46.      */
  47.     private ?string $unid null;
  48.     /**
  49.      * @var ?string
  50.      * @Groups("serialize")
  51.      *
  52.      * @ORM\Column(name="corporate_unid", type="string", unique=true, nullable=true, length=36,
  53.      * options={"comment" = "идентификатор юр. польователя на портале"})
  54.      */
  55.     private ?string $corporateUnid null;
  56.     /**
  57.      * @var string
  58.      * @Groups("serialize")
  59.      *
  60.      * @ORM\Column(name="token", type="string", length=64, unique=true)
  61.      */
  62.     private $token;
  63.     /**
  64.      * @var bool
  65.      *
  66.      * @ORM\Column(name="is_active", type="boolean",
  67.      * options={"default" = 1, "comment"="Активирован (1 - да, 0 - нет)"}))
  68.      */
  69.     private $isActive;
  70.     /**
  71.      * @var bool
  72.      *
  73.      * @ORM\Column(name="proved", type="boolean", nullable=true,
  74.      * options={"default" = false, "comment"="Проверенный, снимает ограничение на лимит в заказе (true - да, false - нет)"}))
  75.      */
  76.     private $proved;
  77.     /**
  78.      * @var string
  79.      *
  80.      * @ORM\Column(name="alias", type="string", length=300)
  81.      * options={"comment"="Псевдоним пользователя"}))
  82.      */
  83.     private $alias;
  84.     /**
  85.      * @var string
  86.      *
  87.      * @ORM\Column(name="foreign_alias", type="string", length=300, nullable=true)
  88.      * options={"comment"="Псевдоним для иностранцев"}))
  89.      */
  90.     private $foreignAlias;
  91.     /**
  92.      * @var string
  93.      *
  94.      * @ORM\Column(name="lotus_name", type="string", length=100, nullable=true)
  95.      */
  96.     private $lotusName;
  97.     /**
  98.      * @ORM\OneToMany(targetEntity="Factory", mappedBy="user", cascade={"persist", "remove"})
  99.      **/
  100.     private $factories;
  101.     /**
  102.      * @ORM\OneToMany(targetEntity="TransExEntity", mappedBy="autor")
  103.      */
  104.     private $transEx;
  105.     /**
  106.      * @var PersistentCollection|OrderAddress[]
  107.      * @ORM\OneToMany(targetEntity="OrderAddress", mappedBy="user", cascade={"persist", "remove"})
  108.      */
  109.     private $orderAddresses;
  110.     /**
  111.      * Encrypted password.
  112.      *
  113.      * @ORM\Column(type="string")
  114.      * @var string
  115.      */
  116.     protected $password;
  117.     /** @var bool */
  118.     protected $changePassword null;
  119.     /** @var string */
  120.     protected $passwordNew;
  121.     /** @var string */
  122.     protected $passwordRepeat;
  123.     /** @var string */
  124.     protected $passwordOld;
  125.     /**
  126.      * @ORM\ManyToMany(targetEntity="Participant", mappedBy="participants")
  127.      */
  128.     private $participants;
  129.     /**
  130.      * @var bool
  131.      *
  132.      * @ORM\Column(name="expired", type="boolean", nullable=true)
  133.      */
  134.     private $expired null;
  135.     /**
  136.      * @var DateTime
  137.      *
  138.      * @ORM\Column(name="expires_at", type="datetime", nullable=true)
  139.      */
  140.     private $expires_at null;
  141.     /**
  142.      * @var bool
  143.      *
  144.      * @ORM\Column(name="credentials_expired", type="boolean", nullable=true)
  145.      */
  146.     private $credentials_expired null;
  147.     /**
  148.      * @var DateTime
  149.      *
  150.      * @ORM\Column(name="credentials_expire_at", type="datetime", nullable=true)
  151.      */
  152.     private $credentials_expire_at null;
  153.     /**
  154.      * @ORM\OneToMany(targetEntity="FactoryUser", mappedBy="user")
  155.      */
  156.     private $factoryUser;
  157.     /**
  158.      * @var string
  159.      *
  160.      * @ORM\Column(name="last_ip", type="string", length=130, nullable=true)
  161.      * options={"comment"="Последний IP юзера"}))
  162.      */
  163.     private $lastIp;
  164.     /**
  165.      * @var string
  166.      *
  167.      * @ORM\Column(name="source", type="string", length=130, nullable=true)
  168.      * options={"comment"="Помечаем откуда пришел клиент"}))
  169.      */
  170.     private $source;
  171.     /**
  172.      * @var string
  173.      */
  174.     private $country;
  175.     /**
  176.      * @var string
  177.      */
  178.     private $zip;
  179.     /**
  180.      * @var string|null
  181.      * @ORM\Column(name="social_network", type="string", length=130, nullable=true)
  182.      * options={"comment"="указываем какой соц.сеть"}))
  183.      */
  184.     private $social_network;
  185.     /**
  186.      * @var string|null
  187.      * @ORM\Column(name="social_network_id", type="string", nullable=true)
  188.      * options={"comment"="id соц.сеть"}))
  189.      */
  190.     private $social_network_id;
  191.     /**
  192.      * @var string
  193.      * @ORM\Column(name="google_id", type="string", nullable=true)
  194.      */
  195.     private $google_id;
  196.     /**
  197.      * @var string
  198.      * @ORM\Column(name="fb_id", type="string", nullable=true,
  199.      * options={"comment"="facebook id соц.сеть"})
  200.      */
  201.     private $fb_id;
  202.     /**
  203.      * @var string
  204.      * @ORM\Column(name="vk_id", type="string", nullable=true)
  205.      */
  206.     private $vk_id;
  207.     /**
  208.      * @var string
  209.      * @ORM\Column(name="ig_id", type="string", nullable=true)
  210.      * options={"comment"="instagram id соц.сеть"})
  211.      */
  212.     private $ig_id;
  213.     /**
  214.      * @var string
  215.      * @ORM\Column(name="test", type="boolean", nullable=true)
  216.      * options={"comment"="для проверки тестового функционала"})
  217.      */
  218.     private $test;
  219.     /**
  220.      * Токен контакта на портале исправлен
  221.      *
  222.      * @var bool|null
  223.      * @ORM\Column(name="token_fixed", type="boolean", nullable=true)
  224.      */
  225.     private $tokenFixed;
  226.     /**
  227.      * @var int|null
  228.      * @ORM\Column(name="bid",  type="integer", nullable=true, options={"comment" = "ID привязанной фабрики"})
  229.      */
  230.     private $bid;
  231.     /**
  232.      * @Groups("serialize")
  233.      * @ORM\Column(name="email", type="string", length=180, unique=true)
  234.      */
  235.     private $email;
  236.     /**
  237.      * @ORM\Column(name="salt", type="string", nullable=true)
  238.      */
  239.     private $salt;
  240.     /**
  241.      * @ORM\Column(name="review_request_sent", type="boolean", nullable=true)
  242.      */
  243.     public ?bool $reviewRequestSent;
  244.     private $plainPassword;
  245.     /**
  246.      * @ORM\Column(name="username", type="string", length=180, nullable=true)
  247.      */
  248.     private $username;
  249.     /**
  250.      * @ORM\Column(type="array")
  251.      */
  252.     private array $roles = [];
  253.     /**
  254.      * @ORM\Column(type="boolean")
  255.      */
  256.     private $enabled true;
  257.     /**
  258.      * @ORM\Column(name="confirmation_token", type="string", length=180, nullable=true, unique=true)
  259.      */
  260.     private $confirmationToken;
  261.     /**
  262.      * @ORM\Column(name="last_login", type="datetime", nullable=true)
  263.      */
  264.     private $lastLogin;
  265.     /**
  266.      * @ORM\Column(name="password_requested_at", type="datetime", nullable=true)
  267.      */
  268.     private $passwordRequestedAt;
  269.     /**
  270.      * Поле безопасности для нового сайта (БД используется одна и та же, поэтому добавляем изначально здесь)
  271.      *
  272.      * @ORM\Column(name="security_field", type="string", options={"default" = ""})
  273.      */
  274.     private string $securityField '';
  275.     /**
  276.      * @ORM\Column(name="created_at", type="datetime", nullable=true)
  277.      */
  278.     private ?DateTime $createdAt;
  279.     /**
  280.      * @ORM\Column(name="is_legal_entity", type="boolean", nullable=true)
  281.      */
  282.     private ?bool $isLegalEntity;
  283.     /**
  284.      * @ORM\Column(name="companyName", type="string", nullable=true)
  285.      */
  286.     private ?string $companyName;
  287.     /**
  288.      * @ORM\Column(name="vatNumber", type="string", nullable=true)
  289.      */
  290.     private ?string $vatNumber;
  291.     /**
  292.      * @ORM\Column(name="lang", type="string", nullable=true)
  293.      */
  294.     private ?string $lang;
  295.     /**
  296.      * @return string
  297.      */
  298.     public function getFactoriesCount()
  299.     {
  300.         return count($this->factories);
  301.     }
  302.     public function __construct()
  303.     {
  304.         $this->isActive true;
  305.         $this->factories = new ArrayCollection();
  306.         $this->participants = new ArrayCollection();
  307.         $this->factoryUser = new ArrayCollection();
  308.         $this->transEx = new ArrayCollection();
  309.         $this->orderAddresses = new ArrayCollection();
  310.         $this->createdAt = new DateTime();
  311.     }
  312.     /**
  313.      * Get stringRoles.
  314.      *
  315.      * @return string
  316.      */
  317.     public function getStringRoles()
  318.     {
  319.         return $this->roles implode(','$this->roles) : '';
  320.     }
  321.     /**
  322.      * Get id.
  323.      *
  324.      * @return int|null
  325.      */
  326.     public function getId(): ?int
  327.     {
  328.         return $this->id;
  329.     }
  330.     /**
  331.      * Set unid.
  332.      *
  333.      * @param string|null $unid
  334.      *
  335.      * @return User
  336.      */
  337.     public function setUnid(?string $unid): User
  338.     {
  339.         $this->unid $unid;
  340.         return $this;
  341.     }
  342.     /**
  343.      * Get unid.
  344.      *
  345.      * @return string
  346.      */
  347.     public function getUnid()
  348.     {
  349.         return $this->unid;
  350.     }
  351.     /**
  352.      * Set unid.
  353.      *
  354.      * @param string|null $unid
  355.      *
  356.      * @return User
  357.      */
  358.     public function setCorporateUnid(?string $unid): User
  359.     {
  360.         $this->corporateUnid $unid;
  361.         return $this;
  362.     }
  363.     /**
  364.      * Get unid.
  365.      *
  366.      * @return ?string
  367.      */
  368.     public function getCorporateUnid(): ?string
  369.     {
  370.         return $this->corporateUnid;
  371.     }
  372.     /**
  373.      * Set token.
  374.      *
  375.      * @param string $token
  376.      *
  377.      * @return User
  378.      */
  379.     public function setToken($token): User
  380.     {
  381.         $this->token $token;
  382.         return $this;
  383.     }
  384.     /**
  385.      * Get token.
  386.      *
  387.      * @return string
  388.      */
  389.     public function getToken(): ?string
  390.     {
  391.         return $this->token;
  392.     }
  393.     /**
  394.      * Set isActive.
  395.      *
  396.      * @param bool $isActive
  397.      *
  398.      * @return User
  399.      */
  400.     public function setIsActive($isActive): User
  401.     {
  402.         $this->isActive $isActive;
  403.         return $this;
  404.     }
  405.     /**
  406.      * Get isActive.
  407.      *
  408.      * @return bool
  409.      */
  410.     public function getIsActive(): bool
  411.     {
  412.         return $this->isActive;
  413.     }
  414.     /**
  415.      * Set alias.
  416.      *
  417.      * @param string $alias
  418.      *
  419.      * @return User
  420.      */
  421.     public function setAlias(string $alias): User
  422.     {
  423.         $this->alias $alias;
  424.         return $this;
  425.     }
  426.     /**
  427.      * Get alias.
  428.      * @Groups("serialize")
  429.      * @return string
  430.      */
  431.     public function getAlias(): string
  432.     {
  433.         return $this->alias;
  434.     }
  435.     /**
  436.      * @return string
  437.      */
  438.     public function getAliasOrEmail(): string
  439.     {
  440.         return  $this->alias $this->getAlias() : $this->getEmail();
  441.     }
  442.     /**
  443.      * Set foreignAlias.
  444.      *
  445.      * @param string $foreignAlias
  446.      *
  447.      * @return User
  448.      */
  449.     public function setForeignAlias($foreignAlias): User
  450.     {
  451.         $this->foreignAlias $foreignAlias;
  452.         return $this;
  453.     }
  454.     /**
  455.      * Get foreignAlias.
  456.      *
  457.      * @return ?string
  458.      */
  459.     public function getForeignAlias(): ?string
  460.     {
  461.         return $this->foreignAlias;
  462.     }
  463.     /**
  464.      * Get nameComment.
  465.      *
  466.      * @return ?string
  467.      */
  468.     public function getNameComment(): ?string
  469.     {
  470.         return $this->foreignAlias ?: $this->alias;
  471.     }
  472.     /**
  473.      * {@inheritdoc}
  474.      */
  475.     public function eraseCredentials()
  476.     {
  477.     }
  478.     /**
  479.      * @see Serializable::serialize()
  480.      */
  481.     public function serialize()
  482.     {
  483.         return serialize([
  484.                 $this->id,
  485.                 $this->email,
  486.                 $this->password,
  487.                 // see section on salt below
  488.                  $this->salt,
  489.                 $this->username,
  490.             ]);
  491.     }
  492.     /**
  493.      * @see \Serializable::unserialize()
  494.      *
  495.      * @param string $serialized
  496.      */
  497.     public function unserialize($serialized)
  498.     {
  499.         [$this->id$this->email$this->password,            // see section on salt below
  500.          $this->salt$this->username,
  501.         ] = unserialize($serialized);
  502.     }
  503.     public function setPassSalt($pass$salt)
  504.     {
  505.         $this->password $pass;
  506.         $this->salt $salt;
  507.     }
  508.     public function isAccountNonExpired()
  509.     {
  510.         return true;
  511.     }
  512.     public function isAccountNonLocked()
  513.     {
  514.         return true;
  515.     }
  516.     public function isCredentialsNonExpired()
  517.     {
  518.         return true;
  519.     }
  520.     public function isEnabled()
  521.     {
  522.         return $this->enabled;
  523.     }
  524.     /**
  525.      * Добавил временно, т.к. по умолчанию сделано для всех, что активен
  526.      * как везде проставим нормально, то поправить на
  527.      * AdmBundle/Service/UsersService.php.
  528.      *
  529.      * @return bool
  530.      */
  531.     public function isEnabledAlt()
  532.     {
  533.         return $this->enabled;
  534.     }
  535.     public function __toString()
  536.     {
  537.         return $this->alias $this->alias '(' $this->getUsername() . ')' $this->getUsername();
  538.     }
  539.     /**
  540.      * @return mixed
  541.      */
  542.     public function getFactories()
  543.     {
  544.         return $this->factories;
  545.     }
  546.     /**
  547.      * @param mixed $factories
  548.      */
  549.     public function setFactories($factories)
  550.     {
  551.         $this->factories $factories;
  552.     }
  553.     /**
  554.      * Set proved.
  555.      *
  556.      * @param bool $proved
  557.      *
  558.      * @return User
  559.      */
  560.     public function setProved($proved)
  561.     {
  562.         $this->proved $proved $proved false;
  563.         return $this;
  564.     }
  565.     /**
  566.      * Get proved.
  567.      *
  568.      * @return bool
  569.      */
  570.     public function getProved()
  571.     {
  572.         return $this->proved;
  573.     }
  574.     /**
  575.      * Add factory.
  576.      *
  577.      * @return User
  578.      */
  579.     public function addFactory(Factory $factory)
  580.     {
  581.         $this->factories[] = $factory;
  582.         return $this;
  583.     }
  584.     /**
  585.      * Remove factory.
  586.      */
  587.     public function removeFactory(Factory $factory)
  588.     {
  589.         $this->factories->removeElement($factory);
  590.     }
  591.     /**
  592.      * @return bool
  593.      */
  594.     public function isChangePassword()
  595.     {
  596.         return $this->changePassword;
  597.     }
  598.     /**
  599.      * @param bool $changePassword
  600.      */
  601.     public function setChangePassword($changePassword)
  602.     {
  603.         $this->changePassword $changePassword;
  604.     }
  605.     /**
  606.      * @return string
  607.      */
  608.     public function getPasswordRepeat()
  609.     {
  610.         return $this->passwordRepeat;
  611.     }
  612.     /**
  613.      * @param string $passwordRepeat
  614.      */
  615.     public function setPasswordRepeat($passwordRepeat)
  616.     {
  617.         $this->passwordRepeat $passwordRepeat;
  618.     }
  619.     /**
  620.      * @return string
  621.      */
  622.     public function getPasswordNew()
  623.     {
  624.         return $this->passwordNew;
  625.     }
  626.     /**
  627.      * @param string $passwordNew
  628.      */
  629.     public function setPasswordNew($passwordNew)
  630.     {
  631.         $this->passwordNew $passwordNew;
  632.     }
  633.     /**
  634.      * @return string
  635.      */
  636.     public function getPasswordOld()
  637.     {
  638.         return $this->passwordOld;
  639.     }
  640.     /**
  641.      * @param string $passwordOld
  642.      */
  643.     public function setPasswordOld($passwordOld)
  644.     {
  645.         $this->passwordOld $passwordOld;
  646.     }
  647.     /**
  648.      * @return ArrayCollection
  649.      */
  650.     public function getParticipants()
  651.     {
  652.         return $this->participants;
  653.     }
  654.     /**
  655.      * Add participants.
  656.      *
  657.      * @return $this
  658.      */
  659.     public function addParticipants(Participant $participants)
  660.     {
  661.         $this->participants[] = $participants;
  662.         return $this;
  663.     }
  664.     /**
  665.      * Remove participants.
  666.      */
  667.     public function removeParticipants(Participant $participants)
  668.     {
  669.         $this->participants->removeElement($participants);
  670.     }
  671.     /**
  672.      * @return mixed
  673.      */
  674.     public function getFactoryUser()
  675.     {
  676.         return $this->factoryUser;
  677.     }
  678.     /**
  679.      * @param mixed $factoryUser
  680.      */
  681.     public function setFactoryUser($factoryUser)
  682.     {
  683.         $this->factoryUser $factoryUser;
  684.     }
  685.     /**
  686.      * @param string $lastIp
  687.      *
  688.      * @return User
  689.      */
  690.     public function setLastIp($lastIp null)
  691.     {
  692.         $this->lastIp $lastIp $lastIp null;
  693.         return $this;
  694.     }
  695.     /**
  696.      * @return string
  697.      */
  698.     public function getLastIp()
  699.     {
  700.         return $this->lastIp;
  701.     }
  702.     /**
  703.      * @return string
  704.      */
  705.     public function getCountry()
  706.     {
  707.         return $this->country;
  708.     }
  709.     /**
  710.      * @param string $country
  711.      */
  712.     public function setCountry($country)
  713.     {
  714.         $this->country $country;
  715.     }
  716.     /**
  717.      * @return string
  718.      */
  719.     public function getZip()
  720.     {
  721.         return $this->zip;
  722.     }
  723.     /**
  724.      * @param string $zip
  725.      */
  726.     public function setZip($zip)
  727.     {
  728.         $this->zip $zip;
  729.     }
  730.     /**
  731.      * @return string
  732.      */
  733.     public function getSource()
  734.     {
  735.         return $this->source;
  736.     }
  737.     /**
  738.      * @param string|null $source
  739.      * @return $this
  740.      */
  741.     public function setSource(?string $source): User
  742.     {
  743.         $this->source $source;
  744.         return $this;
  745.     }
  746.     /**
  747.      * @return $this
  748.      */
  749.     public function addTransEx(TransExEntity $transEx): User
  750.     {
  751.         if (!$this->transEx->contains($transEx)) {
  752.             $this->transEx->add($transEx);
  753.             $transEx->setAutor($this);
  754.         }
  755.         return $this;
  756.     }
  757.     public function removeTransEx(TransExEntity $transEx)
  758.     {
  759.         $this->transEx->removeElement($transEx);
  760.     }
  761.     /**
  762.      * @return \Doctrine\Common\Collections\Collection
  763.      */
  764.     public function getTransEx()
  765.     {
  766.         return $this->transEx;
  767.     }
  768.     public function addOrderAddress(OrderAddress $orderAddress): User
  769.     {
  770.         $orderAddress->setUser($this);
  771.         $this->orderAddresses[] = $orderAddress;
  772.         return $this;
  773.     }
  774.     /**
  775.      * Remove orderAddress.
  776.      */
  777.     public function removeOrderAddress(OrderAddress $orderAddress)
  778.     {
  779.         $this->orderAddresses->removeElement($orderAddress);
  780.     }
  781.     /**
  782.      * Get orderAddresses.
  783.      *
  784.      * @return ArrayCollection
  785.      */
  786.     public function getOrderAddresses()
  787.     {
  788.         return $this->orderAddresses;
  789.     }
  790.     /**
  791.      * Set expired.
  792.      *
  793.      * @param bool|null $expired
  794.      *
  795.      * @return User
  796.      */
  797.     public function setExpired($expired null)
  798.     {
  799.         $this->expired $expired;
  800.         return $this;
  801.     }
  802.     /**
  803.      * Get expired.
  804.      *
  805.      * @return bool|null
  806.      */
  807.     public function getExpired()
  808.     {
  809.         return $this->expired;
  810.     }
  811.     /**
  812.      * Set expiresAt.
  813.      *
  814.      * @param DateTime|null $expiresAt
  815.      *
  816.      * @return User
  817.      */
  818.     public function setExpiresAt($expiresAt null)
  819.     {
  820.         $this->expires_at $expiresAt;
  821.         return $this;
  822.     }
  823.     /**
  824.      * Get expiresAt.
  825.      *
  826.      * @return DateTime|null
  827.      */
  828.     public function getExpiresAt()
  829.     {
  830.         return $this->expires_at;
  831.     }
  832.     /**
  833.      * Set credentialsExpired.
  834.      *
  835.      * @param bool|null $credentialsExpired
  836.      *
  837.      * @return User
  838.      */
  839.     public function setCredentialsExpired($credentialsExpired null)
  840.     {
  841.         $this->credentials_expired $credentialsExpired;
  842.         return $this;
  843.     }
  844.     /**
  845.      * Get credentialsExpired.
  846.      *
  847.      * @return bool|null
  848.      */
  849.     public function getCredentialsExpired()
  850.     {
  851.         return $this->credentials_expired;
  852.     }
  853.     /**
  854.      * Set credentialsExpireAt.
  855.      *
  856.      * @param DateTime|null $credentialsExpireAt
  857.      *
  858.      * @return User
  859.      */
  860.     public function setCredentialsExpireAt($credentialsExpireAt null)
  861.     {
  862.         $this->credentials_expire_at $credentialsExpireAt;
  863.         return $this;
  864.     }
  865.     /**
  866.      * Get credentialsExpireAt.
  867.      *
  868.      * @return DateTime|null
  869.      */
  870.     public function getCredentialsExpireAt()
  871.     {
  872.         return $this->credentials_expire_at;
  873.     }
  874.     /**
  875.      * Add participant.
  876.      *
  877.      * @return User
  878.      */
  879.     public function addParticipant(Participant $participant)
  880.     {
  881.         $this->participants[] = $participant;
  882.         return $this;
  883.     }
  884.     /**
  885.      * Remove participant.
  886.      *
  887.      * @return bool TRUE if this collection contained the specified element, FALSE otherwise
  888.      */
  889.     public function removeParticipant(Participant $participant)
  890.     {
  891.         return $this->participants->removeElement($participant);
  892.     }
  893.     /**
  894.      * Add factoryUser.
  895.      *
  896.      * @return User
  897.      */
  898.     public function addFactoryUser(FactoryUser $factoryUser)
  899.     {
  900.         $this->factoryUser[] = $factoryUser;
  901.         return $this;
  902.     }
  903.     /**
  904.      * Remove factoryUser.
  905.      *
  906.      * @return bool TRUE if this collection contained the specified element, FALSE otherwise
  907.      */
  908.     public function removeFactoryUser(FactoryUser $factoryUser)
  909.     {
  910.         return $this->factoryUser->removeElement($factoryUser);
  911.     }
  912.     /**
  913.      * Set lotusName.
  914.      *
  915.      * @param string|null $lotusName
  916.      *
  917.      * @return User
  918.      */
  919.     public function setLotusName($lotusName null)
  920.     {
  921.         $this->lotusName $lotusName;
  922.         return $this;
  923.     }
  924.     /**
  925.      * Get lotusName.
  926.      *
  927.      * @return string|null
  928.      */
  929.     public function getLotusName()
  930.     {
  931.         return $this->lotusName;
  932.     }
  933.     /**
  934.      * @return array|mixed|string
  935.      */
  936.     public function getContactWorkGroup()
  937.     {
  938.         $oMemcache App::getMemcache();
  939.         $keyCache 'contact_work_group-' $this->username;
  940.         $data $oMemcache->get($keyCache);
  941.         if (!$data) {
  942.             $portal App::getContainer()->get('portal');
  943.             $result $portal->getContactWorkGroup($this->username);
  944.             if (!empty($result['success']) and $result['success']) {
  945.                 $data $result['result'];
  946.                 $positionRu = !empty($data['workGroup']) ? $data['workGroup'] : null;
  947.                 $positionEn $data['workGroupEng'];
  948.                 $oMemcache->set($keyCache$dataMEMCACHE_COMPRESSED, (int) TimeConstant::HOUR 8);
  949.             }
  950.         }
  951.         $positionRu = !empty($data['workGroup']) ? $data['workGroup'] : null;
  952.         $position = (is_array($positionRu) and !empty($positionRu['0'])) ? $positionRu['0'] : null;
  953.         return $position;
  954.     }
  955.     /**
  956.      * Get alias.
  957.      *
  958.      * @return string
  959.      */
  960.     public function getAliasJob()
  961.     {
  962.         $alias explode(' '$this->alias);
  963.         $out $this->alias;
  964.         if ($alias and is_array($alias)) {
  965.             $out = (!empty($alias['0']) ? $alias['0'] : null) . ' ' . (!empty($alias['1']) ? $alias['1'] : null);
  966.         }
  967.         return $out;
  968.     }
  969.     public function setSocialNetwork(string $social_network)
  970.     {
  971.         $this->social_network $social_network;
  972.         return $this;
  973.     }
  974.     public function getSocialNetwork(): ?string
  975.     {
  976.         return $this->social_network;
  977.     }
  978.     public function setSocialNetworkId(string $social_network_id)
  979.     {
  980.         $this->social_network_id $social_network_id;
  981.         return $this;
  982.     }
  983.     public function getSocialNetworkId(): ?string
  984.     {
  985.         return $this->social_network_id;
  986.     }
  987.     public function setGoogleId(string $google_id): User
  988.     {
  989.         $this->google_id $google_id;
  990.         return $this;
  991.     }
  992.     public function getGoogleId(): ?string
  993.     {
  994.         return $this->google_id;
  995.     }
  996.     public function setFbId(string $fb_id): User
  997.     {
  998.         $this->fb_id $fb_id;
  999.         return $this;
  1000.     }
  1001.     public function getFbId(): ?string
  1002.     {
  1003.         return $this->fb_id;
  1004.     }
  1005.     public function setVkId(string $vk_id): User
  1006.     {
  1007.         $this->vk_id $vk_id;
  1008.         return $this;
  1009.     }
  1010.     public function getVkId(): ?string
  1011.     {
  1012.         return $this->vk_id;
  1013.     }
  1014.     public function setIgId(string $ig_id): User
  1015.     {
  1016.         $this->ig_id $ig_id;
  1017.         return $this;
  1018.     }
  1019.     public function getIgId(): ?string
  1020.     {
  1021.         return $this->ig_id;
  1022.     }
  1023.     public function setTest(bool $test): User
  1024.     {
  1025.         $this->test $test;
  1026.         return $this;
  1027.     }
  1028.     /**
  1029.      * @return bool|null
  1030.      */
  1031.     public function getTest()
  1032.     {
  1033.         return $this->test;
  1034.     }
  1035.     public function getTokenFixed(): bool
  1036.     {
  1037.         return (bool) $this->tokenFixed;
  1038.     }
  1039.     public function setTokenFixed(?bool $tokenFixed): void
  1040.     {
  1041.         $this->tokenFixed = (bool) $tokenFixed;
  1042.     }
  1043.     public function getBid(): ?int
  1044.     {
  1045.         return $this->bid;
  1046.     }
  1047.     public function setBid(?int $bid): User
  1048.     {
  1049.         $this->bid $bid;
  1050.         return $this;
  1051.     }
  1052.     public function isEqualTo(UserInterface $user)
  1053.     {
  1054.         return $this->id === $user->getId();
  1055.     }
  1056.     /**
  1057.      * @return string
  1058.      */
  1059.     public function getPassword(): string
  1060.     {
  1061.         return $this->password;
  1062.     }
  1063.     /**
  1064.      * @param string $password
  1065.      */
  1066.     public function setPassword(string $password): void
  1067.     {
  1068.         $this->password $password;
  1069.     }
  1070.     public function getSalt()
  1071.     {
  1072.         return $this->salt;
  1073.     }
  1074.     public function getUsername(): string
  1075.     {
  1076.         if (UserHelper::isEmployee($this->email)) {
  1077.             return (string) $this->username;
  1078.         }
  1079.         return (string) $this->email;
  1080.     }
  1081.     public function getUserIdentifier(): string
  1082.     {
  1083.         return (string) $this->email;
  1084.     }
  1085.     /**
  1086.      * @return mixed
  1087.      */
  1088.     public function getPlainPassword()
  1089.     {
  1090.         return $this->plainPassword;
  1091.     }
  1092.     /**
  1093.      * @param mixed $plainPassword
  1094.      */
  1095.     public function setPlainPassword($plainPassword): self
  1096.     {
  1097.         $this->plainPassword $plainPassword;
  1098.         return $this;
  1099.     }
  1100.     /**
  1101.      * @return mixed
  1102.      */
  1103.     public function getEmail()
  1104.     {
  1105.         return $this->email;
  1106.     }
  1107.     /**
  1108.      * @param mixed $email
  1109.      */
  1110.     public function setEmail(string $email): self
  1111.     {
  1112.         $encoding mb_detect_encoding($email);
  1113.         $email $encoding
  1114.             mb_convert_case($emailMB_CASE_LOWER$encoding)
  1115.             : mb_convert_case($emailMB_CASE_LOWER);
  1116.         $this->email $email;
  1117.         return $this;
  1118.     }
  1119.     /**
  1120.      * @param mixed $username
  1121.      * @throws Exception
  1122.      */
  1123.     public function setUsername($username): User
  1124.     {
  1125.         if (empty($this->email)) {
  1126.             throw new Exception('Email пользователя необходимо устанавливать до установки username, чтоб можно было выполнить проверку isEmployee() при установке username.');
  1127.         }
  1128.         if (!UserHelper::isEmployee((string) $this->email)) {
  1129.             $this->username null;
  1130.             return $this;
  1131.         }
  1132.         if ((null === $username || '' === $username) && UserHelper::isEmployee((string) $this->email)) {
  1133.             return $this;
  1134.         }
  1135.         $this->username $username;
  1136.         return $this;
  1137.     }
  1138.     /**
  1139.      * @return mixed
  1140.      */
  1141.     public function getConfirmationToken()
  1142.     {
  1143.         return $this->confirmationToken;
  1144.     }
  1145.     /**
  1146.      * @param mixed $confirmationToken
  1147.      */
  1148.     public function setConfirmationToken($confirmationToken): void
  1149.     {
  1150.         $this->confirmationToken $confirmationToken;
  1151.     }
  1152.     /**
  1153.      * @param mixed $salt
  1154.      */
  1155.     public function setSalt($salt): void
  1156.     {
  1157.         $this->salt $salt;
  1158.     }
  1159.     public function getRoles()
  1160.     {
  1161.         $roles $this->roles;
  1162.         // we need to make sure to have at least one role
  1163.         $roles[] = static::ROLE_DEFAULT;
  1164.         return array_values(array_unique($roles));
  1165.     }
  1166.     public function hasRole($role): bool
  1167.     {
  1168.         return in_array(strtoupper($role), $this->getRoles(), true);
  1169.     }
  1170.     public function isSuperAdmin(): bool
  1171.     {
  1172.         return $this->hasRole('ROLE_SUPER_ADMIN');
  1173.     }
  1174.     public function removeRole($role)
  1175.     {
  1176.         if (false !== $key array_search(strtoupper($role), $this->rolestrue)) {
  1177.             unset($this->roles[$key]);
  1178.             $this->roles array_values($this->roles);
  1179.         }
  1180.         return $this;
  1181.     }
  1182.     public function setRoles(array $roles)
  1183.     {
  1184.         $this->roles = [];
  1185.         foreach ($roles as $role) {
  1186.             $this->addRole($role);
  1187.         }
  1188.         return $this;
  1189.     }
  1190.     public function addRole($role)
  1191.     {
  1192.         $role strtoupper($role);
  1193.         if ($role === static::ROLE_DEFAULT) {
  1194.             return $this;
  1195.         }
  1196.         if (!in_array($role$this->rolestrue)) {
  1197.             $this->roles[] = $role;
  1198.         }
  1199.         return $this;
  1200.     }
  1201.     /**
  1202.      * @return mixed
  1203.      */
  1204.     public function getLastLogin()
  1205.     {
  1206.         return $this->lastLogin;
  1207.     }
  1208.     /**
  1209.      * @param mixed $lastLogin
  1210.      */
  1211.     public function setLastLogin($lastLogin): void
  1212.     {
  1213.         $this->lastLogin $lastLogin;
  1214.     }
  1215.     /**
  1216.      * @return mixed
  1217.      */
  1218.     public function getPasswordRequestedAt()
  1219.     {
  1220.         return $this->passwordRequestedAt;
  1221.     }
  1222.     /**
  1223.      * @param mixed $passwordRequestedAt
  1224.      */
  1225.     public function setPasswordRequestedAt($passwordRequestedAt): void
  1226.     {
  1227.         $this->passwordRequestedAt $passwordRequestedAt;
  1228.     }
  1229.     /**
  1230.      * @param bool $enabled
  1231.      */
  1232.     public function setEnabled(bool $enabled): void
  1233.     {
  1234.         $this->enabled $enabled;
  1235.     }
  1236.     /**
  1237.      * @throws Exception
  1238.      */
  1239.     public function getMainRecipientAddress(): OrderAddress
  1240.     {
  1241.         if ($this->orderAddresses->count() === 0) {
  1242.             $orderAddress = new OrderAddress();
  1243.             $orderAddress->setIsMainRecipient(true);
  1244.             $orderAddress->setToken($this->token ?: UserHelper::getInstance()->getToken());
  1245.             $this->addOrderAddress($orderAddress);
  1246.             return $orderAddress;
  1247.         }
  1248.         foreach ($this->orderAddresses as $orderAddress) {
  1249.             if ($orderAddress->isMainRecipient()) {
  1250.                 return $orderAddress;
  1251.             }
  1252.         }
  1253.         //Если ни один из адресов не является главным - возвращаем первый из них
  1254.         /** @var OrderAddress $orderAddress */
  1255.         $orderAddress $this->orderAddresses->first();
  1256.         $orderAddress->setIsMainRecipient(true);
  1257.         return $orderAddress;
  1258.     }
  1259.     /**
  1260.      * @Groups("serialize")
  1261.      */
  1262.     public function getSex(): ?int
  1263.     {
  1264.         if (!empty($this->orderAddresses) && $this->orderAddresses->count() > 0) {
  1265.             foreach ($this->orderAddresses as $orderAddress) {
  1266.                 if ($orderAddress->getSex() !== null) {
  1267.                     return $orderAddress->getSex();
  1268.                 }
  1269.             }
  1270.         }
  1271.         return null;
  1272.     }
  1273.     /**
  1274.      * @return DateTime|null
  1275.      */
  1276.     public function getCreatedAt(): ?DateTime
  1277.     {
  1278.         return $this->createdAt;
  1279.     }
  1280.     /**
  1281.      * @param DateTime|null $createdAt
  1282.      */
  1283.     public function setCreatedAt(?DateTime $createdAt): void
  1284.     {
  1285.         $this->createdAt $createdAt;
  1286.     }
  1287.     /**
  1288.      * @return bool|null
  1289.      */
  1290.     public function getIsLegalEntity(): ?bool
  1291.     {
  1292.         return $this->isLegalEntity;
  1293.     }
  1294.     /**
  1295.      * @param bool|null $isLegalEntity
  1296.      */
  1297.     public function setIsLegalEntity(?bool $isLegalEntity): void
  1298.     {
  1299.         $this->isLegalEntity $isLegalEntity;
  1300.     }
  1301.     public function getDeliveryAddresses(): ?\Generator
  1302.     {
  1303.         foreach ($this->orderAddresses as $address) {
  1304.             /** @var OrderAddress $address */
  1305.             if ($address->isDelivery()) {
  1306.                 yield $address;
  1307.             }
  1308.         }
  1309.         return null;
  1310.     }
  1311.     public function getPaymentAddress(): ?OrderAddress
  1312.     {
  1313.         /** @var OrderAddress $address */
  1314.         foreach ($this->orderAddresses as $address) {
  1315.             if ($address->isPayment()) {
  1316.                 return $address;
  1317.             }
  1318.         }
  1319.         return null;
  1320.     }
  1321.     /**
  1322.      * @return string|null
  1323.      */
  1324.     public function getLang(): ?string
  1325.     {
  1326.         return $this->lang;
  1327.     }
  1328.     /**
  1329.      * @param string|null $lang
  1330.      */
  1331.     public function setLang(string $lang 'en'): self
  1332.     {
  1333.         $this->lang $lang;
  1334.         return $this;
  1335.     }
  1336.     /**
  1337.      * @param string $securityField
  1338.      */
  1339.     public function setSecurityField(string $securityField): void
  1340.     {
  1341.         $this->securityField $securityField;
  1342.     }
  1343. }