src/Model/User.php line 54

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