src/Model/User.php line 53

Open in your IDE?
  1. <?php
  2. declare(strict_types=1);
  3. namespace Harmonizely\Model;
  4. use DateTimeImmutable;
  5. use DateTimeZone;
  6. use Doctrine\Common\Collections\ArrayCollection;
  7. use Doctrine\Common\Collections\Collection;
  8. use Doctrine\Common\Collections\Criteria;
  9. use Exception;
  10. use FOS\UserBundle\Model\User as BaseUser;
  11. use Harmonizely\Core\DTO\SecondFactorCredentialsDTO;
  12. use Harmonizely\Core\StringUtil;
  13. use Harmonizely\DTO\SuperAdmin\Customer\Response\CustomerDetailedDTO;
  14. use Harmonizely\DTO\User\Response\SimpleUserDTO;
  15. use Harmonizely\DTO\User\Response\UserDTO;
  16. use Harmonizely\Entity\Company\ApiKeyEntity;
  17. use Harmonizely\Entity\Company\Contract\INamedObjectEntity;
  18. use Harmonizely\Entity\Company\MigrationSubscriptionEntity;
  19. use Harmonizely\Entity\Company\OrganizationTagEntity;
  20. use Harmonizely\Entity\Company\PollEntity;
  21. use Harmonizely\Entity\Company\ReviewEntity;
  22. use Harmonizely\Entity\Company\RoutingFormEntity;
  23. use Harmonizely\Entity\Company\UserCancellationPolicyEntity;
  24. use Harmonizely\Entity\Company\UserEmailLogEntity;
  25. use Harmonizely\Entity\Company\UserEmailUnsubscribeEntity;
  26. use Harmonizely\Entity\Company\UserGoogleAuthenticatorEntity;
  27. use Harmonizely\Entity\Company\UserLimitEntity;
  28. use Harmonizely\Entity\Company\UserLoginCodeEntity;
  29. use Harmonizely\Entity\Company\UserOAuthEntity;
  30. use Harmonizely\Entity\Company\UserPushNotificationLogEntity;
  31. use Harmonizely\Entity\Company\UserRelationEntity;
  32. use Harmonizely\Entity\Company\UserSmsLogEntity;
  33. use Harmonizely\Entity\Company\UserSocialLinkEntity;
  34. use Harmonizely\Entity\Company\UserSsoEntity;
  35. use Harmonizely\Entity\Company\UserTaxEntity;
  36. use Harmonizely\Entity\Company\UserWidgetEntity;
  37. use Harmonizely\Entity\Company\ZapierEntity;
  38. use Harmonizely\Service\Subscription\Voter\SubscriptionVoter;
  39. use Harmonizely\Types\Company\CalendarLayoutType;
  40. use Harmonizely\Types\Company\DateFormatType;
  41. use Harmonizely\Types\Company\UserSsoLoginType;
  42. use libphonenumber\PhoneNumber;
  43. use libphonenumber\PhoneNumberFormat;
  44. use libphonenumber\PhoneNumberUtil;
  45. use Symfony\Component\HttpFoundation\File\File;
  46. use Symfony\Component\Security\Core\User\EquatableInterface;
  47. use Symfony\Component\Security\Core\User\UserInterface as BaseUserInterface;
  48. use Symfony\Component\Validator\Constraints as Assert;
  49. class User extends BaseUser implements EquatableInterfaceUserInterfaceINamedObjectEntityBannerInterface
  50. {
  51.     use RtlTrait;
  52.     use BannerTrait;
  53.     use AdaTrait;
  54.     use AllowLoginAsUserTrait;
  55.     use TimestampableTrait;
  56.     use UuidTrait {
  57.         __construct as private initUuid;
  58.     }
  59.     /**
  60.      * @var mixed
  61.      */
  62.     protected $id;
  63.     /**
  64.      * @var string
  65.      */
  66.     protected $firstName;
  67.     /**
  68.      * @var string
  69.      */
  70.     protected $lastName;
  71.     /**
  72.      * @var string
  73.      */
  74.     protected $fullName '';
  75.     /**
  76.      * @var CalendarAccountInterface
  77.      */
  78.     protected $calendarAccount;
  79.     /**
  80.      * @var CalendarAccountInterface[]|Collection
  81.      */
  82.     protected $calendarAccounts;
  83.     /**
  84.      * @Assert\NotBlank
  85.      *
  86.      * @var string
  87.      */
  88.     protected $slug;
  89.     /**
  90.      * @var string|null
  91.      */
  92.     protected $intro;
  93.     /**
  94.      * @var string
  95.      */
  96.     protected $timezone;
  97.     /**
  98.      * @var string
  99.      */
  100.     protected $locale 'auto';
  101.     /**
  102.      * @var File
  103.      */
  104.     protected $avatarFile;
  105.     /**
  106.      * @var string
  107.      */
  108.     protected $avatarName;
  109.     /**
  110.      * @var int
  111.      */
  112.     protected $avatarSize;
  113.     /**
  114.      * @var int|null
  115.      */
  116.     protected $companyLogoFile;
  117.     /**
  118.      * @var int|null
  119.      */
  120.     protected $companyLogoName;
  121.     /**
  122.      * @var int|null
  123.      */
  124.     protected $companyLogoSize;
  125.     /**
  126.      * @var SubscriptionInterface
  127.      */
  128.     protected $subscription;
  129.     /**
  130.      * @var Collection
  131.      */
  132.     protected $integrations;
  133.     /**
  134.      * @var bool
  135.      */
  136.     protected $brandingEnabled true;
  137.     /**
  138.      * @var bool
  139.      */
  140.     protected $isProxyEnabled false;
  141.     /**
  142.      * @var SchedulingPageAppearance
  143.      */
  144.     protected $schedulingPageAppearance;
  145.     /**
  146.      * @var string
  147.      */
  148.     private $domain;
  149.     /**
  150.      * @var Collection|Member[]
  151.      */
  152.     private $members;
  153.     /**
  154.      * @var Collection|Event[]
  155.      */
  156.     private $events;
  157.     /**
  158.      * @var Collection|UserSmsLogEntity[]
  159.      */
  160.     private $userSmsLog;
  161.     /**
  162.      * @var Collection|UserEmailLogEntity[]
  163.      */
  164.     private $userEmailLog;
  165.     /**
  166.      * @var Collection|UserPushNotificationLogEntity[]
  167.      */
  168.     private $userPushNotificationLog;
  169.     /**
  170.      * @var Collection|UserLimitEntity[]
  171.      */
  172.     private $userLimit;
  173.     /**
  174.      * @var Collection|UserTaxEntity[]
  175.      */
  176.     private $tax;
  177.     /**
  178.      * @var Collection|PollEntity[]
  179.      */
  180.     private $polls;
  181.     /**
  182.      * @var Collection|RoutingFormEntity[]
  183.      * */
  184.     private $routingForms;
  185.     /**
  186.      * @var Collection|ZapierEntity[]
  187.      */
  188.     private $zapiers;
  189.     /**
  190.      * @var Collection|ApiKeyEntity[]
  191.      */
  192.     private $apiKeys;
  193.     /**
  194.      * @var Collection|UserLoginCodeEntity[]
  195.      */
  196.     private $userLoginCode;
  197.     /**
  198.      * @var array|ArrayCollection
  199.      */
  200.     protected $socialLinks = [];
  201.     /**
  202.      * @var string|null
  203.      */
  204.     private $sender;
  205.     /**
  206.      * @var ApiKey
  207.      */
  208.     protected $apiKey;
  209.     protected ?string $timeFormat UserInterface::TWELVE_HOURS_TIME_FORMAT;
  210.     protected ?string $dateFormat DateFormatType::TYPE_DD_MM_YYYY;
  211.     protected ?string $clientTimeFormat UserInterface::AUTO_TIME_FORMAT;
  212.     private ?int $dayliteId;
  213.     private ?UserPreferences $preferences;
  214.     private ?PhoneNumber $phoneNumber;
  215.     protected ?int $consent UserInterface::CONSENT_ACCEPTED;
  216.     /**
  217.      * @var string|null
  218.      */
  219.     private ?string $referral;
  220.     /**
  221.      * @var string
  222.      */
  223.     private string $calendarLayout CalendarLayoutType::TYPE_WEEKLY;
  224.     /**
  225.      * @var bool
  226.      */
  227.     protected bool $hideUnavailableDates false;
  228.     /**
  229.      * @var bool
  230.      */
  231.     protected bool $sundayIsFirstDay false;
  232.     /**
  233.      * @var bool
  234.      */
  235.     protected bool $requireSetPassword false;
  236.     /**
  237.      * @var bool
  238.      */
  239.     protected bool $requireConfirmEmail false;
  240.     /**
  241.      * @var UserGoogleAuthenticatorEntity|null
  242.      */
  243.     private ?UserGoogleAuthenticatorEntity $googleAuthenticator null;
  244.     /**
  245.      * @var UserSocialLinkEntity|null $socialLink
  246.      */
  247.     private ?UserSocialLinkEntity $socialLink null;
  248.     /**
  249.      * @var UserSsoEntity|null
  250.      */
  251.     private ?UserSsoEntity $userSso null;
  252.     private ?UserCancellationPolicyEntity $userCancellationPolicy null;
  253.     private ?UserWidgetEntity $userWidget null;
  254.     /**
  255.      * @var Collection|null
  256.      */
  257.     private ?Collection $userToken null;
  258.     /**
  259.      * @var Collection|null
  260.      */
  261.     private ?Collection $userDeviceToken null;
  262.     /**
  263.      * @var Collection|null
  264.      */
  265.     private ?Collection $userApiStatistic null;
  266.     /**
  267.      * @var Collection|null
  268.      */
  269.     private ?Collection $userExport null;
  270.     /**
  271.      * @var Collection|UserOAuthEntity[]
  272.      */
  273.     private Collection $userOAuth;
  274.     /**
  275.      * @var Collection
  276.      */
  277.     protected Collection $userNews;
  278.     /**
  279.      * @var Collection
  280.      */
  281.     protected Collection $organizationTags;
  282.     /**
  283.      * @var Collection
  284.      */
  285.     protected Collection $userCategories;
  286.     /**
  287.      * @var MigrationSubscriptionEntity|null
  288.      */
  289.     protected ?MigrationSubscriptionEntity $migrationSubscription;
  290.     /**
  291.      * @var UserEmailUnsubscribeEntity |null
  292.      */
  293.     protected ?UserEmailUnsubscribeEntity $userEmailUnsubscribe;
  294.     /**
  295.      * @var ReviewEntity|null
  296.      */
  297.     protected ?ReviewEntity $review;
  298.     /**
  299.      * @var string|null
  300.      */
  301.     protected ?string $address '';
  302.     /**
  303.      * @var string|null
  304.      */
  305.     protected ?string $state '';
  306.     /**
  307.      * @var string|null
  308.      */
  309.     protected ?string $city '';
  310.     /**
  311.      * @var string|null
  312.      */
  313.     protected ?string $zip '';
  314.     /**
  315.      * @var string|null
  316.      */
  317.     protected ?string $countryId '';
  318.     /**
  319.      * @var float|null
  320.      */
  321.     protected ?float $lat null;
  322.     /**
  323.      * @var float|null
  324.      */
  325.     protected ?float $lng null;
  326.     /**
  327.      * @var int|null
  328.      */
  329.     protected ?int $verificationCode null;
  330.     /**
  331.      * @var string|null
  332.      */
  333.     protected ?string $otherCategory '';
  334.     /**
  335.      * @var bool
  336.      */
  337.     protected ?bool $showAddressInEmail true;
  338.     /**
  339.      * @var string|null
  340.      */
  341.     protected ?string $lastTwoFactorCode '';
  342.     /**
  343.      * @var bool
  344.      */
  345.     private bool $ssoLoginAllowed;
  346.     /**
  347.      * User subscriptions
  348.      *
  349.      * @var Collection
  350.      */
  351.     protected Collection $subscriptions;
  352.     /**
  353.      * @var Collection
  354.      */
  355.     protected Collection $userEventTypeTag;
  356.     /**
  357.      * @var Collection|UserRelationEntity[]
  358.      */
  359.     protected Collection $relatedUsers;
  360.     /**
  361.      * @var string|null
  362.      */
  363.     private ?string $welcomeTourStep;
  364.     /**
  365.      * @var bool
  366.      */
  367.     private bool $secondFactorSkipped false;
  368.     /**
  369.      * @var bool
  370.      */
  371.     private bool $tutorialSkipped false;
  372.     /**
  373.      * @var bool
  374.      */
  375.     private bool $onboardingSkipped false;
  376.     private ?string $gRecaptchaResponse null;
  377.     /**
  378.      * User constructor.
  379.      */
  380.     public function __construct()
  381.     {
  382.         $this->setCreatedAt(new DateTime());
  383.         $this->integrations = new ArrayCollection();
  384.         $this->members = new ArrayCollection();
  385.         $this->calendarAccounts = new ArrayCollection();
  386.         $this->organizationTags = new ArrayCollection();
  387.         $this->userCategories = new ArrayCollection();
  388.         $this->userOAuth = new ArrayCollection();
  389.         $this->userNews = new ArrayCollection();
  390.         $this->subscriptions = new ArrayCollection();
  391.         $this->socialLink = new UserSocialLinkEntity();
  392.         $this->relatedUsers = new ArrayCollection();
  393.         $this->initUuid();
  394.         $this->generateVerificationCode();
  395.         parent::__construct();
  396.     }
  397.     /**
  398.      * {@inheritdoc}
  399.      */
  400.     public function setLastLogin(\DateTime $time null)
  401.     {
  402.         if (!$this->lastLogin || $time->diff($this->lastLogin)->days 0) {
  403.             if (mt_rand(110) == 1) {
  404.                 $this->lastLogin $time;
  405.             }
  406.         }
  407.         return $this;
  408.     }
  409.     public function getDirectoryCompanyLogin(): string
  410.     {
  411.         return 'simplymeet_' $this->getId();
  412.     }
  413.     /**
  414.      * @return void
  415.      */
  416.     public function useVerificationCode(): void
  417.     {
  418.         $this->verificationCode null;
  419.     }
  420.     public function generateVerificationCode(): void
  421.     {
  422.         $this->verificationCode StringUtil::getSecretCode();
  423.     }
  424.     /**
  425.      * @return int|null
  426.      */
  427.     public function getVerificationCode(): ?int
  428.     {
  429.         return $this->verificationCode;
  430.     }
  431.     public function setEmail($email)
  432.     {
  433.         $email $email ?? '';
  434.         parent::setEmail($email);
  435.         $this->setUsername($email);
  436.     }
  437.     /**
  438.      * {@inheritdoc}
  439.      */
  440.     public function getFirstName(): string
  441.     {
  442.         $parts explode(' '$this->fullName);
  443.         return array_shift($parts);
  444.     }
  445.     /**
  446.      * {@inheritdoc}
  447.      */
  448.     public function setFirstName(string $firstName)
  449.     {
  450.         $this->firstName $firstName;
  451.     }
  452.     /**
  453.      * {@inheritdoc}
  454.      */
  455.     public function getLastName(): string
  456.     {
  457.         return $this->lastName;
  458.     }
  459.     /**
  460.      * {@inheritdoc}
  461.      */
  462.     public function setLastName(string $lastName)
  463.     {
  464.         $this->lastName $lastName;
  465.     }
  466.     /**
  467.      * @return CalendarAccountInterface[]|Collection
  468.      */
  469.     public function getCalendarAccounts(): Collection
  470.     {
  471.         return $this->calendarAccounts;
  472.     }
  473.     /**
  474.      * @return string|null
  475.      */
  476.     public function getInternalCalendarUuid(): ?string
  477.     {
  478.         foreach ($this->calendarAccounts as $calendarAccount) {
  479.             if ($calendarAccount->getCalendarService()->getType() === CalendarServiceInterface::TYPE_INTERNAL) {
  480.                 $firstCalendar $calendarAccount->getAvailableCalendars()->first();
  481.                 if ($firstCalendar) {
  482.                     return $firstCalendar->getUuid();
  483.                 }
  484.             }
  485.         }
  486.         return null;
  487.     }
  488.     /**
  489.      * @param int $id
  490.      * @return CalendarAccountInterface|null
  491.      */
  492.     public function getCalendarAccountById(int $id): ?CalendarAccountInterface
  493.     {
  494.         $calendarAccount $this->calendarAccounts->filter(function (CalendarAccountInterface $calendarAccount) use ($id) {
  495.             return $calendarAccount->getId() === $id;
  496.         })->first();
  497.         return $calendarAccount ?: null;
  498.     }
  499.     /**
  500.      * @return CalendarAccountInterface[]|Collection
  501.      */
  502.     public function getWritableCalendarAccounts(): Collection
  503.     {
  504.         return $this->calendarAccounts->filter(function (CalendarAccountInterface $calendarAccount) {
  505.             return $calendarAccount->isWritable();
  506.         });
  507.     }
  508.     public function setCalendarAccounts(Collection $calendarAccounts): void
  509.     {
  510.         $this->calendarAccounts $calendarAccounts;
  511.     }
  512.     public function addCalendarAccount(CalendarAccountInterface $calendarAccount): void
  513.     {
  514.         if (!$this->hasCalendarAccount($calendarAccount)) {
  515.             $this->calendarAccounts->add($calendarAccount);
  516.             $calendarAccount->setUser($this);
  517.         }
  518.     }
  519.     public function removeCalendarAccount(CalendarAccountInterface $calendarAccount): void
  520.     {
  521.         if ($this->hasCalendarAccount($calendarAccount)) {
  522.             $this->calendarAccounts->removeElement($calendarAccount);
  523.             $calendarAccount->setUser(null);
  524.         }
  525.     }
  526.     public function hasCalendarAccount(CalendarAccountInterface $calendarAccount): bool
  527.     {
  528.         return $this->calendarAccounts->contains($calendarAccount);
  529.     }
  530.     public function hasCalendarConnected(string $type): bool
  531.     {
  532.         foreach ($this->calendarAccounts as $calendarAccount) {
  533.             $calendarService $calendarAccount->getCalendarService();
  534.             if ($calendarService->getType() === $type) {
  535.                 return true;
  536.             }
  537.         }
  538.         return false;
  539.     }
  540.     /**
  541.      * {@inheritdoc}
  542.      */
  543.     public function getSlug(): ?string
  544.     {
  545.         return $this->slug;
  546.     }
  547.     /**
  548.      * {@inheritdoc}
  549.      */
  550.     public function setSlug(?string $slug): void
  551.     {
  552.         $this->slug $slug;
  553.     }
  554.     /**
  555.      * {@inheritdoc}
  556.      */
  557.     public function getFullName(): string
  558.     {
  559.         return $this->fullName;
  560.     }
  561.     /**
  562.      * {@inheritdoc}
  563.      */
  564.     public function setFullName(string $fullName): void
  565.     {
  566.         $this->fullName $fullName;
  567.     }
  568.     /**
  569.      * {@inheritdoc}
  570.      */
  571.     public function getIntro(): ?string
  572.     {
  573.         return $this->intro;
  574.     }
  575.     /**
  576.      * {@inheritdoc}
  577.      */
  578.     public function setIntro(?string $intro): void
  579.     {
  580.         $this->intro $intro;
  581.     }
  582.     /**
  583.      * {@inheritdoc}
  584.      */
  585.     public function getTimezone(): ?string
  586.     {
  587.         return $this->timezone;
  588.     }
  589.     /**
  590.      * {@inheritdoc}
  591.      */
  592.     public function setTimezone(?string $timezone): void
  593.     {
  594.         $this->timezone $timezone;
  595.     }
  596.     /**
  597.      * {@inheritdoc}
  598.      */
  599.     public function getLocale(): ?string
  600.     {
  601.         return $this->locale;
  602.     }
  603.     /**
  604.      * {@inheritdoc}
  605.      */
  606.     public function setLocale(?string $locale): void
  607.     {
  608.         $this->locale $locale;
  609.     }
  610.     /**
  611.      * @return bool
  612.      */
  613.     public function isAutoLocale(): bool
  614.     {
  615.         return $this->getLocale() === 'auto';
  616.     }
  617.     /**
  618.      * @return File
  619.      */
  620.     public function getAvatarFile(): ?File
  621.     {
  622.         return $this->avatarFile;
  623.     }
  624.     /**
  625.      * @param File $avatarFile
  626.      *
  627.      * @throws Exception
  628.      */
  629.     public function setAvatarFile(?File $avatarFile): void
  630.     {
  631.         $this->avatarFile $avatarFile;
  632.         if (null !== $avatarFile) {
  633.             $this->updatedAt = new DateTimeImmutable();
  634.         }
  635.     }
  636.     /**
  637.      * @return string
  638.      */
  639.     public function getAvatarName(): ?string
  640.     {
  641.         return $this->avatarName;
  642.     }
  643.     /**
  644.      * @param string $avatarName
  645.      */
  646.     public function setAvatarName(?string $avatarName): void
  647.     {
  648.         $this->avatarName $avatarName;
  649.     }
  650.     /**
  651.      * @return int
  652.      */
  653.     public function getAvatarSize(): ?int
  654.     {
  655.         return $this->avatarSize;
  656.     }
  657.     /**
  658.      * @param int $avatarSize
  659.      */
  660.     public function setAvatarSize(?int $avatarSize): void
  661.     {
  662.         $this->avatarSize $avatarSize;
  663.     }
  664.     public function getSubscription(): ?SubscriptionInterface
  665.     {
  666.         return $this->subscription;
  667.     }
  668.     public function setSubscription(?SubscriptionInterface $subscription): void
  669.     {
  670.         $this->subscription $subscription;
  671.     }
  672.     public function getIntegrations(): Collection
  673.     {
  674.         return $this->integrations;
  675.     }
  676.     public function setIntegrations(Collection $integrations): void
  677.     {
  678.         $this->integrations $integrations;
  679.     }
  680.     /**
  681.      * @param string $type
  682.      * @return false|IntegrationInterface
  683.      */
  684.     public function getIntegrationByType(string $type)
  685.     {
  686.         $criteria Criteria::create()->where(Criteria::expr()->eq('type'$type));
  687.         return $this->integrations->matching($criteria)->first();
  688.     }
  689.     public function addIntegration(IntegrationInterface $integration): void
  690.     {
  691.         if (!$this->hasIntegration($integration)) {
  692.             $this->integrations->add($integration);
  693.             $integration->setUser($this);
  694.         }
  695.     }
  696.     public function removeIntegration(IntegrationInterface $integration): void
  697.     {
  698.         if ($this->hasIntegration($integration)) {
  699.             $this->integrations->removeElement($integration);
  700.             $integration->setUser(null);
  701.         }
  702.     }
  703.     public function hasIntegration(IntegrationInterface $integration): bool
  704.     {
  705.         return $this->integrations->contains($integration);
  706.     }
  707.     public function isBrandingEnabled(): bool
  708.     {
  709.         if (!SubscriptionVoter::staticVoteOnAttribute(SubscriptionVoter::WHITE_LABEL$this)) {
  710.             return true;
  711.         }
  712.         return $this->brandingEnabled;
  713.     }
  714.     public function isCustomCssAvailable(): bool
  715.     {
  716.         return SubscriptionVoter::staticVoteOnAttribute(SubscriptionVoter::WHITE_LABEL$this);
  717.     }
  718.     public function setBrandingEnabled(bool $brandingEnabled): void
  719.     {
  720.         $this->brandingEnabled $brandingEnabled;
  721.     }
  722.     public function isProxyEnabled(): bool
  723.     {
  724.         return $this->isProxyEnabled;
  725.     }
  726.     public function setIsProxyEnabled(bool $isProxyEnabled): void
  727.     {
  728.         $this->isProxyEnabled $isProxyEnabled;
  729.     }
  730.     public function getDefaultOrganization(): ?Organization
  731.     {
  732.         foreach ($this->members as $member) {
  733.             if ($member->getStatus() === Member::STATUS_JOINED) {
  734.                 return $member->getOrganization();
  735.             }
  736.         }
  737.         return null;
  738.     }
  739.     public function getSchedulingPageAppearance(): SchedulingPageAppearance
  740.     {
  741.         if (false === $this->schedulingPageAppearance instanceof SchedulingPageAppearance) {
  742.             $schedulingPageAppearance = new UserSchedulingPageAppearance();
  743.             $schedulingPageAppearance->setUser($this);
  744.             $schedulingPageAppearance->setConfig(SchedulingPageAppearance::DEFAULT_CONFIG);
  745.             return $schedulingPageAppearance;
  746.         }
  747.         if (!$this->schedulingPageAppearance->getConfig()) {
  748.             $this->schedulingPageAppearance->setConfig(SchedulingPageAppearance::DEFAULT_CONFIG);
  749.         }
  750.         return $this->schedulingPageAppearance;
  751.     }
  752.     public function setSchedulingPageAppearance(?SchedulingPageAppearance $schedulingPageAppearance): void
  753.     {
  754.         $this->schedulingPageAppearance $schedulingPageAppearance;
  755.     }
  756.     public function getDomain(): ?string
  757.     {
  758.         return $this->domain;
  759.     }
  760.     public function getUserOrOrganizationDomain(): ?string
  761.     {
  762.         $domain null;
  763.         if ($this->domain) {
  764.             $domain $this->domain;
  765.         } else {
  766.             $organization $this->getDefaultOrganization();
  767.             if ($organization && $organization->getDomain()) {
  768.                 $domain $organization->getDomain();
  769.             }
  770.         }
  771.         return $domain;
  772.     }
  773.     public function setDomain(?string $domain): void
  774.     {
  775.         $this->domain $domain;
  776.     }
  777.     /**
  778.      * @return Collection|Member[]
  779.      */
  780.     public function getMembers(): Collection
  781.     {
  782.         return $this->members;
  783.     }
  784.     public function setMembers(Collection $members): void
  785.     {
  786.         $this->members $members;
  787.     }
  788.     public function belongsToOrganization(Organization $organization)
  789.     {
  790.         $members $organization->getMembers();
  791.         $user $members->filter(function (Member $member) {
  792.             return $member->getUser()->getId() === $this->getId();
  793.         });
  794.         return false === $user->isEmpty();
  795.     }
  796.     public function getSender(): ?string
  797.     {
  798.         return $this->sender;
  799.     }
  800.     public function setSender(?string $sender): void
  801.     {
  802.         $this->sender $sender;
  803.     }
  804.     public function getCompanyLogoFile(): ?File
  805.     {
  806.         return $this->companyLogoFile;
  807.     }
  808.     public function setCompanyLogoFile(?File $companyLogoFile): void
  809.     {
  810.         $this->companyLogoFile $companyLogoFile;
  811.         if (null !== $companyLogoFile) {
  812.             $this->updatedAt = new DateTimeImmutable();
  813.         }
  814.     }
  815.     public function getCompanyLogoName(): ?string
  816.     {
  817.         return $this->companyLogoName;
  818.     }
  819.     public function setCompanyLogoName(?string $companyLogoName): void
  820.     {
  821.         $this->companyLogoName $companyLogoName;
  822.     }
  823.     public function getCompanyLogoSize(): ?int
  824.     {
  825.         return $this->companyLogoSize;
  826.     }
  827.     public function setCompanyLogoSize(?int $companyLogoSize): void
  828.     {
  829.         $this->companyLogoSize $companyLogoSize;
  830.     }
  831.     public function getTimeFormat(): ?string
  832.     {
  833.         return $this->timeFormat;
  834.     }
  835.     public function setTimeFormat(?string $timeFormat): void
  836.     {
  837.         $this->timeFormat $timeFormat;
  838.     }
  839.     public function getDateFormat(): ?string
  840.     {
  841.         return $this->dateFormat;
  842.     }
  843.     public function setDateFormat(?string $dateFormat): void
  844.     {
  845.         $this->dateFormat $dateFormat;
  846.     }
  847.     /**
  848.      * @deprecated
  849.      * @return string|null
  850.      */
  851.     public function getClientTimeFormat(): ?string
  852.     {
  853.         return $this->clientTimeFormat;
  854.     }
  855.     /**
  856.      * @deprecated 
  857.      * @param string|null $clientTimeFormat
  858.      * @return void
  859.      */
  860.     public function setClientTimeFormat(?string $clientTimeFormat): void
  861.     {
  862.         $this->clientTimeFormat $clientTimeFormat;
  863.     }
  864.     public function getDayliteId(): ?int
  865.     {
  866.         return $this->dayliteId;
  867.     }
  868.     public function setDayliteId(?int $dayliteId): void
  869.     {
  870.         $this->dayliteId $dayliteId;
  871.     }
  872.     public function getPreferences(): UserPreferences
  873.     {
  874.         if (false === $this->preferences instanceof UserPreferences) {
  875.             $preferences = new UserPreferences();
  876.             $preferences->setUser($this);
  877.             return $preferences;
  878.         }
  879.         return $this->preferences;
  880.     }
  881.     public function setPreferences(?UserPreferences $preferences): void
  882.     {
  883.         $this->preferences $preferences;
  884.     }
  885.     public function getPhoneNumber(): ?PhoneNumber
  886.     {
  887.         return $this->phoneNumber;
  888.     }
  889.     public function getInternationalPhoneNumber(): string
  890.     {
  891.         if (!$this->phoneNumber instanceof PhoneNumber) {
  892.             return '';
  893.         }
  894.         $phoneUtil PhoneNumberUtil::getInstance();
  895.         return $phoneUtil->format($this->phoneNumberPhoneNumberFormat::E164);
  896.     }
  897.     public function setPhoneNumber(?PhoneNumber $phoneNumber): void
  898.     {
  899.         $this->phoneNumber $phoneNumber;
  900.     }
  901.     public function getHelpScoutSignature(): string
  902.     {
  903.         return hash_hmac(
  904.             'sha256',
  905.             $this->emailCanonical,
  906.             'yHXRcpT4sgbtldHeLccCrlUBl1k5yPTKc8xiojCcQRU='
  907.         );
  908.     }
  909.     public function getConsent(): ?int
  910.     {
  911.         return $this->consent;
  912.     }
  913.     public function setConsent(?int $consent): void
  914.     {
  915.         $this->consent $consent;
  916.     }
  917.     /**
  918.      * @param string|null $referral
  919.      */
  920.     public function setReferral(?string $referral): void
  921.     {
  922.         $this->referral $referral;
  923.     }
  924.     /**
  925.      * @return string|null
  926.      */
  927.     public function getReferral(): ?string
  928.     {
  929.         return $this->referral;
  930.     }
  931.     /**
  932.      * Return 2fa authentication type
  933.      *
  934.      * @return string|null
  935.      */
  936.     public function getSecondAuthenticationType(): ?string
  937.     {
  938.         $types $this->getAllowedSecondAuthenticationTypes();
  939.         $type reset($types);
  940.         if ($type) {
  941.             return $type;
  942.         }
  943.         return null;
  944.     }
  945.     /**
  946.      * Return allowed 2fa types
  947.      *
  948.      * @return array
  949.      */
  950.     public function getAllowedSecondAuthenticationTypes(): array
  951.     {
  952.         $result = [];
  953.         if ($this->googleAuthenticator) {
  954.             $result[] = SecondFactorCredentialsDTO::TYPE_GA;
  955.         }
  956.         return $result;
  957.     }
  958.     /**
  959.      * Return Google Authenticator secret code
  960.      *
  961.      * @return string|null
  962.      */
  963.     public function getGASecretCode(): ?string
  964.     {
  965.         if ($this->googleAuthenticator) {
  966.             return $this->googleAuthenticator->getSecret();
  967.         }
  968.         return null;
  969.     }
  970.     /**
  971.      * Return Google Authenticator secret code
  972.      *
  973.      * @param string $secret
  974.      * @return void
  975.      */
  976.     public function setGASecretCode(string $secret): void
  977.     {
  978.         if ($this->googleAuthenticator) {
  979.             $this->googleAuthenticator->changeSecret($secret);
  980.         } else {
  981.             $this->googleAuthenticator = new UserGoogleAuthenticatorEntity($this$secret);
  982.         }
  983.     }
  984.     /**
  985.      * @param UserGoogleAuthenticatorEntity|null $googleAuthenticator
  986.      */
  987.     public function setGoogleAuthenticator(?UserGoogleAuthenticatorEntity $googleAuthenticator): void
  988.     {
  989.         $this->googleAuthenticator $googleAuthenticator;
  990.     }
  991.     /**
  992.      * @return UserGoogleAuthenticatorEntity|null
  993.      */
  994.     public function getGoogleAuthenticator(): ?UserGoogleAuthenticatorEntity
  995.     {
  996.         return $this->googleAuthenticator;
  997.     }
  998.     /**
  999.      * Clear GA code
  1000.      */
  1001.     public function deleteGoogleAuthenticator(): void
  1002.     {
  1003.         $this->googleAuthenticator null;
  1004.     }
  1005.     /**
  1006.      * @param UserSsoEntity|null $userSso
  1007.      */
  1008.     public function setUserSso(?UserSsoEntity $userSso): void
  1009.     {
  1010.         $this->userSso $userSso;
  1011.     }
  1012.     /**
  1013.      * @return UserSsoEntity|null
  1014.      */
  1015.     public function getUserSso(): ?UserSsoEntity
  1016.     {
  1017.         return $this->userSso;
  1018.     }
  1019.     /**
  1020.      * @return Collection
  1021.      */
  1022.     public function getOrganizationTags(): Collection
  1023.     {
  1024.         return $this->organizationTags;
  1025.     }
  1026.     /**
  1027.      * Add organization tag
  1028.      *
  1029.      * @param OrganizationTagEntity $organizationTag
  1030.      */
  1031.     public function addOrganizationTag(OrganizationTagEntity $organizationTag): void
  1032.     {
  1033.         if (!$this->organizationTags->contains($organizationTag)) {
  1034.             $this->organizationTags->add($organizationTag);
  1035.         }
  1036.     }
  1037.     /**
  1038.      * @param OrganizationTagEntity $organizationTag
  1039.      * @return void
  1040.      */
  1041.     public function removeOrganizationTag(OrganizationTagEntity $organizationTag): void
  1042.     {
  1043.         if ($this->organizationTags->contains($organizationTag)) {
  1044.             $this->organizationTags->removeElement($organizationTag);
  1045.         }
  1046.     }
  1047.     /**
  1048.      * @return void
  1049.      */
  1050.     public function clearOrganizationTag(): void
  1051.     {
  1052.         $this->organizationTags = new ArrayCollection();
  1053.     }
  1054.     public function clearUserCategories(): void
  1055.     {
  1056.         $this->userCategories = new ArrayCollection();
  1057.     }
  1058.     /**
  1059.      * @return Collection
  1060.      */
  1061.     public function getUserCategories(): Collection
  1062.     {
  1063.         return $this->userCategories;
  1064.     }
  1065.     /**
  1066.      * @param Collection $userCategories
  1067.      */
  1068.     public function setUserCategories(Collection $userCategories): void
  1069.     {
  1070.         $this->userCategories $userCategories;
  1071.     }
  1072.     /**
  1073.      * @param string $calendarLayout
  1074.      */
  1075.     public function setCalendarLayout(string $calendarLayout): void
  1076.     {
  1077.         $this->calendarLayout $calendarLayout;
  1078.     }
  1079.     /**
  1080.      * @return string
  1081.      */
  1082.     public function getCalendarLayout(): string
  1083.     {
  1084.         return $this->calendarLayout;
  1085.     }
  1086.     /**
  1087.      * @param bool $hideUnavailableDates
  1088.      */
  1089.     public function setHideUnavailableDates(bool $hideUnavailableDates): void
  1090.     {
  1091.         $this->hideUnavailableDates $hideUnavailableDates;
  1092.     }
  1093.     /**
  1094.      * @return bool
  1095.      */
  1096.     public function isHideUnavailableDates(): bool
  1097.     {
  1098.         return $this->hideUnavailableDates;
  1099.     }
  1100.     /**
  1101.      * @param bool $sundayIsFirstDay
  1102.      */
  1103.     public function setSundayIsFirstDay(bool $sundayIsFirstDay): void
  1104.     {
  1105.         $this->sundayIsFirstDay $sundayIsFirstDay;
  1106.     }
  1107.     /**
  1108.      * @return bool
  1109.      */
  1110.     public function isSundayIsFirstDay(): bool
  1111.     {
  1112.         return $this->sundayIsFirstDay;
  1113.     }
  1114.     /**
  1115.      * @param bool $requireSetPassword
  1116.      */
  1117.     public function setRequireSetPassword(bool $requireSetPassword): void
  1118.     {
  1119.         $this->requireSetPassword $requireSetPassword;
  1120.     }
  1121.     /**
  1122.      * @return bool
  1123.      */
  1124.     public function isRequireSetPassword(): bool
  1125.     {
  1126.         return $this->requireSetPassword;
  1127.     }
  1128.     /**
  1129.      * @return bool
  1130.      */
  1131.     public function isRequireConfirmEmail(): bool
  1132.     {
  1133.         return $this->requireConfirmEmail;
  1134.     }
  1135.     /**
  1136.      * @param bool $requireConfirmEmail
  1137.      */
  1138.     public function setRequireConfirmEmail(bool $requireConfirmEmail): void
  1139.     {
  1140.         $this->requireConfirmEmail $requireConfirmEmail;
  1141.     }
  1142.     /**
  1143.      * @param string|null $address
  1144.      */
  1145.     public function setAddress(?string $address): void
  1146.     {
  1147.         $this->address $address;
  1148.     }
  1149.     /**
  1150.      * @return string|null
  1151.      */
  1152.     public function getAddress(): ?string
  1153.     {
  1154.         return $this->address;
  1155.     }
  1156.     /**
  1157.      * @return string|null
  1158.      */
  1159.     public function getState(): ?string
  1160.     {
  1161.         return $this->state;
  1162.     }
  1163.     /**
  1164.      * @param string|null $state
  1165.      */
  1166.     public function setState(?string $state): void
  1167.     {
  1168.         $this->state $state;
  1169.     }
  1170.     /**
  1171.      * @return string|null
  1172.      */
  1173.     public function getCity(): ?string
  1174.     {
  1175.         return $this->city;
  1176.     }
  1177.     /**
  1178.      * @param string|null $city
  1179.      */
  1180.     public function setCity(?string $city): void
  1181.     {
  1182.         $this->city $city;
  1183.     }
  1184.     /**
  1185.      * @return string|null
  1186.      */
  1187.     public function getZip(): ?string
  1188.     {
  1189.         return $this->zip;
  1190.     }
  1191.     /**
  1192.      * @param string|null $zip
  1193.      */
  1194.     public function setZip(?string $zip): void
  1195.     {
  1196.         $this->zip $zip;
  1197.     }
  1198.     /**
  1199.      * @return string|null
  1200.      */
  1201.     public function getCountryId(): ?string
  1202.     {
  1203.         return $this->countryId;
  1204.     }
  1205.     /**
  1206.      * @param string|null $countryId
  1207.      */
  1208.     public function setCountryId(?string $countryId): void
  1209.     {
  1210.         $this->countryId $countryId;
  1211.     }
  1212.     /**
  1213.      * @return string|null
  1214.      */
  1215.     public function getFormattedAddress(): ?string
  1216.     {
  1217.         if ($this->getCountryId()) {
  1218.             $address $this->getCountryId();
  1219.             $addressArr = [
  1220.                 $this->getState(),
  1221.                 $this->getCity(),
  1222.                 $this->getZip(),
  1223.                 $this->getAddress(),
  1224.             ];
  1225.             foreach ($addressArr as $value) {
  1226.                 if ($value) {
  1227.                     $address .= ', ' $value;
  1228.                 }
  1229.             }
  1230.         } else {
  1231.             $address $this->getAddress();
  1232.         }
  1233.         return $address;
  1234.     }
  1235.     /**
  1236.      * @return float|null
  1237.      */
  1238.     public function getLat(): ?float
  1239.     {
  1240.         return $this->lat;
  1241.     }
  1242.     /**
  1243.      * @param float|null $lat
  1244.      */
  1245.     public function setLat(?float $lat): void
  1246.     {
  1247.         $this->lat $lat;
  1248.     }
  1249.     /**
  1250.      * @return float|null
  1251.      */
  1252.     public function getLng(): ?float
  1253.     {
  1254.         return $this->lng;
  1255.     }
  1256.     /**
  1257.      * @param float|null $lng
  1258.      */
  1259.     public function setLng(?float $lng): void
  1260.     {
  1261.         $this->lng $lng;
  1262.     }
  1263.     /**
  1264.      * @param string|null $otherCategory
  1265.      */
  1266.     public function setOtherCategory(?string $otherCategory): void
  1267.     {
  1268.         $this->otherCategory $otherCategory;
  1269.     }
  1270.     /**
  1271.      * @return string|null
  1272.      */
  1273.     public function getOtherCategory(): ?string
  1274.     {
  1275.         return $this->otherCategory;
  1276.     }
  1277.     /**
  1278.      * @param bool|null $showAddressInEmail
  1279.      */
  1280.     public function setShowAddressInEmail(?bool $showAddressInEmail): void
  1281.     {
  1282.         $this->showAddressInEmail = !!$showAddressInEmail;
  1283.     }
  1284.     /**
  1285.      * @return bool
  1286.      */
  1287.     public function isShowAddressInEmail(): bool
  1288.     {
  1289.         return !!$this->showAddressInEmail;
  1290.     }
  1291.     /**
  1292.      * @return UserDTO
  1293.      */
  1294.     public function toDTO(): UserDTO
  1295.     {
  1296.         return $this->createUserDto(UserDTO::class);
  1297.     }
  1298.     /**
  1299.      * @return SimpleUserDTO
  1300.      */
  1301.     public function toSimpleDTO(): SimpleUserDTO
  1302.     {
  1303.         return new SimpleUserDTO(
  1304.             $this->getId(),
  1305.             $this->getEmail(),
  1306.             $this->getFullName()
  1307.         );
  1308.     }
  1309.     /**
  1310.      * @return CustomerDetailedDTO
  1311.      */
  1312.     public function toCustomerDto(): CustomerDetailedDTO
  1313.     {
  1314.         $dto $this->createUserDto(CustomerDetailedDTO::class);
  1315.         // todo add email limit here
  1316.         //$dto->addCustomerLimit(new CustomerLimitDTO(UserLimitType::TYPE_EMAIL, $this->getUserEmailLimit()));
  1317.         $expr Criteria::expr();
  1318.         $criteria Criteria::create();
  1319.         $criteria->andWhere($expr->eq('enabled'true));
  1320.         /** @var SubscriptionInterface $subscription */
  1321.         foreach ($this->subscriptions->matching($criteria) as $subscription) {
  1322.             $dto->addCustomerSubscription($subscription->toCustomerSubscriptionDTO());
  1323.             if ($subscription->isValid() && $subscription->isEnabled()) {
  1324.                 $dto->withActiveSubscription(true);
  1325.             }
  1326.         }
  1327.         return $dto;
  1328.     }
  1329.     /**
  1330.      * @return bool
  1331.      */
  1332.     public function isSsoLoginAllowed(): bool
  1333.     {
  1334.         return $this->userSso instanceof UserSsoEntity && $this->userSso->getLoginType() !== UserSsoLoginType::TYPE_PASSWORD;
  1335.     }
  1336.     /**
  1337.      * @param bool $ssoLoginAllowed
  1338.      */
  1339.     public function setSsoLoginAllowed(bool $ssoLoginAllowed): void
  1340.     {
  1341.         if (!$this->userSso) {
  1342.             $this->userSso = new UserSsoEntity(UserSsoLoginType::TYPE_PASSWORD$this);
  1343.         }
  1344.         if ($this->userSso->getLoginType() !== UserSsoLoginType::TYPE_SSO) {
  1345.             if ($ssoLoginAllowed) {
  1346.                 $this->userSso->setLoginType(UserSsoLoginType::TYPE_SSO_PASSWORD);
  1347.             } else {
  1348.                 $this->userSso->setLoginType(UserSsoLoginType::TYPE_PASSWORD);
  1349.             }
  1350.         }
  1351.     }
  1352.     /**
  1353.      * @return bool
  1354.      */
  1355.     public function isOnlySsoUser(): bool
  1356.     {
  1357.         return $this->getUserSso() && $this->getUserSso()->getLoginType() === UserSsoLoginType::TYPE_SSO;
  1358.     }
  1359.     /**
  1360.      * @param string|null $lastTwoFactorCode
  1361.      */
  1362.     public function setLastTwoFactorCode(?string $lastTwoFactorCode): void
  1363.     {
  1364.         $this->lastTwoFactorCode $lastTwoFactorCode;
  1365.     }
  1366.     /**
  1367.      * @return string|null
  1368.      */
  1369.     public function getLastTwoFactorCode(): ?string
  1370.     {
  1371.         return $this->lastTwoFactorCode;
  1372.     }
  1373.     /**
  1374.      * @return Collection|null
  1375.      */
  1376.     public function getUserOAuth(): ?Collection
  1377.     {
  1378.         return $this->userOAuth;
  1379.     }
  1380.     /**
  1381.      * @param string $provider
  1382.      * @return bool
  1383.      */
  1384.     public function hasOAuthProvider(string $provider): bool
  1385.     {
  1386.         $criteria Criteria::create()->where(Criteria::expr()->eq('provider'$provider));
  1387.         return (bool)$this->userOAuth->matching($criteria)->count();
  1388.     }
  1389.     /**
  1390.      * @param string $provider
  1391.      * @return UserOAuthEntity|null
  1392.      */
  1393.     public function getOAuthProvider(string $provider): ?UserOAuthEntity
  1394.     {
  1395.         $criteria Criteria::create()->where(Criteria::expr()->eq('provider'$provider));
  1396.         $oauthProvider $this->userOAuth->matching($criteria)->first();
  1397.         return $oauthProvider ?: null;
  1398.     }
  1399.     /**
  1400.      * @return UserEmailUnsubscribeEntity|null
  1401.      */
  1402.     public function getUserEmailUnsubscribe(): ?UserEmailUnsubscribeEntity
  1403.     {
  1404.         return $this->userEmailUnsubscribe;
  1405.     }
  1406.     /**
  1407.      * @param UserCancellationPolicyEntity|null $userCancellationPolicy
  1408.      */
  1409.     public function setUserCancellationPolicy(?UserCancellationPolicyEntity $userCancellationPolicy): void
  1410.     {
  1411.         $this->userCancellationPolicy $userCancellationPolicy;
  1412.         $this->userCancellationPolicy->setUser($this);
  1413.     }
  1414.     /**
  1415.      * @return UserCancellationPolicyEntity|null
  1416.      */
  1417.     public function getUserCancellationPolicy(): ?UserCancellationPolicyEntity
  1418.     {
  1419.         return $this->userCancellationPolicy;
  1420.     }
  1421.     /**
  1422.      * @return UserWidgetEntity|null
  1423.      */
  1424.     public function getUserWidget(): ?UserWidgetEntity
  1425.     {
  1426.         return $this->userWidget;
  1427.     }
  1428.     /**
  1429.      * @return string
  1430.      */
  1431.     public function getObjectName(): string
  1432.     {
  1433.         return $this->getEmail() . ' (' $this->getSlug() . ')';
  1434.     }
  1435.     /**
  1436.      * @return string
  1437.      */
  1438.     public function getObjectId(): string
  1439.     {
  1440.         return (string)$this->getid();
  1441.     }
  1442.     /**
  1443.      * Get current active subscriptions
  1444.      *
  1445.      * @return array|SubscriptionInterface[]
  1446.      */
  1447.     public function getCurrentSubscriptions(): array
  1448.     {
  1449.         $res = [];
  1450.         if ($this->getDefaultOrganization()) {
  1451.             /** @var Member $owner */
  1452.             foreach ($this->getDefaultOrganization()->getOwners() as $owner) {
  1453.                 $res array_merge($res$owner->getUser()->getPaidSubscriptions());
  1454.             }
  1455.             if (count($res)) {
  1456.                 return $res;
  1457.             }
  1458.         }
  1459.         $expr Criteria::expr();
  1460.         $criteria Criteria::create();
  1461.         $criteria
  1462.             ->andWhere($expr->eq('enabled'true))
  1463.             //->andWhere($expr->eq('status', 'active'))
  1464.             ->andWhere($expr->gte('expireAt', new DateTimeImmutable()))
  1465.             ->andWhere($expr->lte('startDate', new DateTimeImmutable()));
  1466.         return array_merge($res$this->subscriptions->matching($criteria)->toArray());
  1467.     }
  1468.     /**
  1469.      * Return user id for subscription
  1470.      *
  1471.      * @return string
  1472.      */
  1473.     public function getSubscriptionUserId(): string
  1474.     {
  1475.         if ($this->getDefaultOrganization()) {
  1476.             /** @var Member $owner */
  1477.             foreach ($this->getDefaultOrganization()->getOwners() as $owner) {
  1478.                 $ownerUser $owner->getUser();
  1479.                 if (!empty($ownerUser->getPaidSubscriptions())) {
  1480.                     return (string)$ownerUser->getId();
  1481.                 }
  1482.             }
  1483.         }
  1484.         return (string)$this->getId();
  1485.     }
  1486.     /**
  1487.      * Return subscription user
  1488.      *
  1489.      * @return UserInterface
  1490.      */
  1491.     public function getSubscriptionUser(): UserInterface
  1492.     {
  1493.         if ($this->getDefaultOrganization()) {
  1494.             /** @var Member $owner */
  1495.             foreach ($this->getDefaultOrganization()->getOwners() as $owner) {
  1496.                 if ($owner->getUser()->hasPaidSubscription()) {
  1497.                     return $owner->getUser();
  1498.                 }
  1499.             }
  1500.         }
  1501.         return $this;
  1502.     }
  1503.     /**
  1504.      * Get user paid subscriptions
  1505.      *
  1506.      * @return array
  1507.      */
  1508.     private function getPaidSubscriptions(): array
  1509.     {
  1510.         $expr Criteria::expr();
  1511.         $criteria Criteria::create();
  1512.         $criteria
  1513.             ->andWhere($expr->eq('enabled'true))
  1514.             //->andWhere($expr->eq('status', 'active'))
  1515.             ->andWhere($expr->gte('expireAt', new DateTimeImmutable()))
  1516.             ->andWhere($expr->lte('startDate', new DateTimeImmutable()))
  1517.             ->andWhere($expr->eq('free'false));
  1518.         return $this->getSubscriptions()->matching($criteria)->toArray();
  1519.     }
  1520.     /**
  1521.      * @return Collection
  1522.      */
  1523.     public function getSubscriptions(): Collection
  1524.     {
  1525.         return $this->subscriptions;
  1526.     }
  1527.     /**
  1528.      * Get current active subscriptions users limit
  1529.      *
  1530.      * @return int
  1531.      */
  1532.     public function getSubscriptionUsersLimit(): int
  1533.     {
  1534.         $res 0;
  1535.         /** @var SubscriptionInterface $subscription */
  1536.         foreach ($this->getCurrentSubscriptions() as $subscription) {
  1537.             $res += $subscription->getUsersTotal();
  1538.         }
  1539.         return $res;
  1540.     }
  1541.     /**
  1542.      * Get current active subscriptions bookings limit
  1543.      *
  1544.      * @return int
  1545.      */
  1546.     public function getSubscriptionBookingsLimit(): int
  1547.     {
  1548.         $res 0;
  1549.         /** @var SubscriptionInterface $subscription */
  1550.         foreach ($this->getCurrentSubscriptions() as $subscription) {
  1551.             $res += $subscription->getBookingsTotal();
  1552.         }
  1553.         return $res;
  1554.     }
  1555.     /**
  1556.      * Has paid subscription
  1557.      *
  1558.      * @param bool $skipTrial
  1559.      * @return bool
  1560.      */
  1561.     public function hasPaidSubscription(bool $skipTrial false): bool
  1562.     {
  1563.         foreach ($this->getCurrentSubscriptions() as $subscription) {
  1564.             if (!$subscription->isFree()) {
  1565.                 if ($skipTrial && $subscription->isTrial()) {
  1566.                     continue;
  1567.                 }
  1568.                 return true;
  1569.             }
  1570.         }
  1571.         return false;
  1572.     }
  1573.     /**
  1574.      * @return bool
  1575.      */
  1576.     public function hasTrialSubscription(): bool
  1577.     {
  1578.         foreach ($this->getCurrentSubscriptions() as $subscription) {
  1579.             if ($subscription->isTrial()) {
  1580.                 return true;
  1581.             }
  1582.         }
  1583.         return false;
  1584.     }
  1585.     /**
  1586.      * @return bool
  1587.      */
  1588.     public function hasCurrentSubscription(): bool
  1589.     {
  1590.         return !empty($this->getCurrentSubscriptions());
  1591.     }
  1592.     /**
  1593.      * @return int
  1594.      */
  1595.     public function getTrialDaysLeft(): int
  1596.     {
  1597.         $res 0;
  1598.         foreach ($this->getCurrentSubscriptions() as $subscription) {
  1599.             if ($subscription->isTrial()) {
  1600.                 return $subscription->getDaysLeft();
  1601.             }
  1602.         }
  1603.         return $res;
  1604.     }
  1605.     /**
  1606.      * Is main owner
  1607.      *
  1608.      * @return bool
  1609.      */
  1610.     public function isMainOwner(): bool
  1611.     {
  1612.         if ($this->getDefaultOrganization()) {
  1613.             /** @var Member $member */
  1614.             foreach ($this->getMembers() as $member) {
  1615.                 if ($member->getOrganization()->getId() === $this->getDefaultOrganization()->getId() && $member->getIsMainOwner()) {
  1616.                     return true;
  1617.                 }
  1618.             }
  1619.         }
  1620.         return false;
  1621.     }
  1622.     /**
  1623.      * @return Member|null
  1624.      */
  1625.     public function getMember(): ?Member
  1626.     {
  1627.         if ($this->getDefaultOrganization()) {
  1628.             /** @var Member $member */
  1629.             foreach ($this->getMembers() as $member) {
  1630.                 if ($member->getOrganization()->getId() === $this->getDefaultOrganization()->getId()) {
  1631.                     return $member;
  1632.                 }
  1633.             }
  1634.         }
  1635.         return null;
  1636.     }
  1637.     public function isOwner(): bool
  1638.     {
  1639.         if ($this->getDefaultOrganization()) {
  1640.             return $this->getDefaultOrganization()->isOrganizationOwner($this);
  1641.         }
  1642.         return false;
  1643.     }
  1644.     /**
  1645.      * @return UserSocialLinkEntity|null
  1646.      */
  1647.     public function getSocialLink(): ?UserSocialLinkEntity
  1648.     {
  1649.         return $this->socialLink;
  1650.     }
  1651.     /**
  1652.      * @param UserSocialLinkEntity|null $socialLink
  1653.      */
  1654.     public function setSocialLink(?UserSocialLinkEntity $socialLink): void
  1655.     {
  1656.         $this->socialLink $socialLink;
  1657.         $this->socialLink->setUser($this);
  1658.     }
  1659.     /**
  1660.      * @return Collection|UserTaxEntity[]
  1661.      */
  1662.     public function getTax(): Collection
  1663.     {
  1664.         return $this->tax;
  1665.     }
  1666.     /**
  1667.      * @param BaseUserInterface $user
  1668.      * @return bool
  1669.      */
  1670.     public function isEqualTo(BaseUserInterface $user)
  1671.     {
  1672.         $isEqualTo parent::isEqualTo($user);
  1673.         if ($user->isEnabled() !== $this->isEnabled()) {
  1674.             $isEqualTo false;
  1675.         }
  1676.         return $isEqualTo;
  1677.     }
  1678.     /**
  1679.      * @return Collection
  1680.      */
  1681.     public function getRelatedUsers(): Collection
  1682.     {
  1683.         return $this->relatedUsers;
  1684.     }
  1685.     /**
  1686.      * @param UserRelationEntity $relatedUser
  1687.      */
  1688.     public function addRelatedUser(UserRelationEntity $relatedUser): void
  1689.     {
  1690.         if (!$this->relatedUsers->contains($relatedUser)) {
  1691.             $this->relatedUsers->add($relatedUser);
  1692.         }
  1693.     }
  1694.     /**
  1695.      * @return array|UserInterface[]
  1696.      */
  1697.     public function getChildRelatedUsers(): array
  1698.     {
  1699.         $result = [];
  1700.         foreach ($this->relatedUsers as $relatedUser) {
  1701.             $result[] = $relatedUser->getChildUser();
  1702.         }
  1703.         return $result;
  1704.     }
  1705.     /**
  1706.      * @param UserRelationEntity $entity
  1707.      * @return bool
  1708.      */
  1709.     public function hasChildRelatedUser(UserRelationEntity $entity): bool
  1710.     {
  1711.         foreach ($this->relatedUsers as $relatedUser) {
  1712.             if ($relatedUser->getChildUser() === $entity->getChildUser()) {
  1713.                 return true;
  1714.             }
  1715.         }
  1716.         return false;
  1717.     }
  1718.     /**
  1719.      * @return string|null
  1720.      */
  1721.     public function getWelcomeTourStep(): ?string
  1722.     {
  1723.         return $this->welcomeTourStep;
  1724.     }
  1725.     /**
  1726.      * @param string|null $welcomeTourStep
  1727.      */
  1728.     public function setWelcomeTourStep(?string $welcomeTourStep): void
  1729.     {
  1730.         $this->welcomeTourStep $welcomeTourStep;
  1731.     }
  1732.     /**
  1733.      * @return bool
  1734.      */
  1735.     public function isSecondFactorSkipped(): bool
  1736.     {
  1737.         return true;
  1738.         return $this->secondFactorSkipped;
  1739.     }
  1740.     /**
  1741.      * @param bool $secondFactorSkipped
  1742.      */
  1743.     public function setSecondFactorSkipped(bool $secondFactorSkipped): void
  1744.     {
  1745.         $this->secondFactorSkipped $secondFactorSkipped;
  1746.     }
  1747.     /**
  1748.      * @return bool
  1749.      */
  1750.     public function isTutorialSkipped(): bool
  1751.     {
  1752.         $releaseDate = new DateTimeImmutable('2024-09-23');
  1753.         $oneMonthAfterRegistration = clone $this->createdAt;
  1754.         $oneMonthAfterRegistration $oneMonthAfterRegistration->modify('+1 month');
  1755.         // Check if the user registered after the release date and is within the first month of registration
  1756.         $isNewUser $this->createdAt $releaseDate;
  1757.         $isWithinFirstMonth = new DateTimeImmutable() <= $oneMonthAfterRegistration;
  1758.         // Return true if the tutorial has been skipped, or the user is not a new user, or if the one-month period has passed
  1759.         return $this->tutorialSkipped || !$isNewUser || !$isWithinFirstMonth;
  1760.     }
  1761.     /**
  1762.      * @return void
  1763.      */
  1764.     public function skipTutorial(): void
  1765.     {
  1766.         $this->tutorialSkipped true;
  1767.     }
  1768.     /**
  1769.      * @return bool
  1770.      */
  1771.     public function isOnboardingSkipped(): bool
  1772.     {
  1773.         $releaseDate = new DateTimeImmutable('2025-02-16');
  1774.         $oneMonthAfterRegistration = clone $this->createdAt;
  1775.         $oneMonthAfterRegistration $oneMonthAfterRegistration->modify('+1 month');
  1776.         // Check if the user registered after the release date and is within the first month of registration
  1777.         $isNewUser $this->createdAt $releaseDate;
  1778.         $isWithinFirstMonth = new DateTimeImmutable() <= $oneMonthAfterRegistration;
  1779.         // Return true if the onboarding has been skipped, or the user is not a new user, or if the one-month period has passed
  1780.         return $this->onboardingSkipped || !$isNewUser || !$isWithinFirstMonth;
  1781.     }
  1782.     /**
  1783.      * @return void
  1784.      */
  1785.     public function skipOnboarding(): void
  1786.     {
  1787.         $this->onboardingSkipped true;
  1788.     }
  1789.     /**
  1790.      * @return string|null
  1791.      */
  1792.     public function getGRecaptchaResponse(): ?string
  1793.     {
  1794.         return $this->gRecaptchaResponse;
  1795.     }
  1796.     /**
  1797.      * @param string|null $gRecaptchaResponse
  1798.      */
  1799.     public function setGRecaptchaResponse(?string $gRecaptchaResponse): void
  1800.     {
  1801.         $this->gRecaptchaResponse $gRecaptchaResponse;
  1802.     }
  1803.     /**
  1804.      * @return bool
  1805.      */
  1806.     public function hasCalendarError(): bool
  1807.     {
  1808.         foreach ($this->calendarAccounts as $calendarAccount) {
  1809.             if ($calendarAccount->getNotifiedCalendarServiceId()) {
  1810.                 return true;
  1811.             }
  1812.         }
  1813.         return false;
  1814.     }
  1815.     /**
  1816.      * @return int
  1817.      */
  1818.     public function countSubscriptions(): int
  1819.     {
  1820.         return count($this->subscriptions);
  1821.     }
  1822.     /**
  1823.      * {@inheritdoc}
  1824.      */
  1825.     public function serialize()
  1826.     {
  1827.         return serialize([
  1828.             $this->password,
  1829.             $this->salt,
  1830.             $this->usernameCanonical,
  1831.             $this->username,
  1832.             $this->enabled,
  1833.             $this->id,
  1834.             $this->email,
  1835.             $this->emailCanonical,
  1836.             $this->address,
  1837.             $this->state,
  1838.             $this->city,
  1839.             $this->zip,
  1840.             $this->countryId,
  1841.             $this->lat,
  1842.             $this->lng,
  1843.             $this->brandingEnabled,
  1844.             $this->showAddressInEmail,
  1845.             $this->fullName,
  1846.             $this->timezone,
  1847.             $this->timeFormat,
  1848.             $this->dateFormat,
  1849.             $this->userSso,
  1850.             $this->otherCategory,
  1851.         ]);
  1852.     }
  1853.     /**
  1854.      * {@inheritdoc}
  1855.      */
  1856.     public function unserialize($serialized)
  1857.     {
  1858.         $data unserialize($serialized);
  1859.         [
  1860.             $this->password,
  1861.             $this->salt,
  1862.             $this->usernameCanonical,
  1863.             $this->username,
  1864.             $this->enabled,
  1865.             $this->id,
  1866.             $this->email,
  1867.             $this->emailCanonical,
  1868.             $this->address,
  1869.             $this->state,
  1870.             $this->city,
  1871.             $this->zip,
  1872.             $this->countryId,
  1873.             $this->lat,
  1874.             $this->lng,
  1875.             $this->brandingEnabled,
  1876.             $this->showAddressInEmail,
  1877.             $this->fullName,
  1878.             $this->timezone,
  1879.             $this->timeFormat,
  1880.             $this->dateFormat,
  1881.             $this->userSso,
  1882.             $this->otherCategory,
  1883.         ] = $data;
  1884.     }
  1885.     /**
  1886.      * @param string $class
  1887.      * @return UserDto|CustomerDetailedDTO
  1888.      */
  1889.     private function createUserDto(string $class): object
  1890.     {
  1891.         $phone $this->getInternationalPhoneNumber();
  1892.         $organization $this->getDefaultOrganization();
  1893.         $connections = [];
  1894.         foreach ($this->userOAuth as $userOAuth) {
  1895.             $connections[] = $userOAuth->getProvider();
  1896.         }
  1897.         try {
  1898.             $timezone $this->getTimezone() ?? 'UTC';
  1899.             $currentDate = new DateTimeImmutable('now', new DateTimeZone($timezone));
  1900.             $timezoneOffset $currentDate->format('P');
  1901.         } catch (Exception $e) {
  1902.             $timezone 'UTC';
  1903.             $timezoneOffset '+00:00';
  1904.         }
  1905.         return new $class(
  1906.             $this->getId(),
  1907.             $this->getUuid(),
  1908.             $this->getEmail(),
  1909.             $this->getFullName(),
  1910.             $this->getSlug(),
  1911.             $this->getSubscriptionUsersLimit(),
  1912.             count($this->getAllowedSecondAuthenticationTypes()) > 0,
  1913.             $this->isEnabled(),
  1914.             $this->hasPaidSubscription(),
  1915.             $this->getCalendarAccounts()->count() > 1,
  1916.             $this->getDateFormat(),
  1917.             $this->getTimeFormat(),
  1918.             $timezone,
  1919.             $timezoneOffset,
  1920.             $this->isAllowLoginAsUser(),
  1921.             $this->getAddress(),
  1922.             $this->getState(),
  1923.             $this->getCity(),
  1924.             $this->getZip(),
  1925.             $this->getCountryId(),
  1926.             $this->getLat(),
  1927.             $this->getLng(),
  1928.             $this->getDomain(),
  1929.             $phone ?: null,
  1930.             $this->getCompanyLogoName(),
  1931.             $this->getAvatarName(),
  1932.             $organization $organization->toDTO() : null,
  1933.             $this->getCreatedAt(),
  1934.             $this->getLastLogin(),
  1935.             $connections
  1936.         );
  1937.     }
  1938. }