src/Service/Common/UrlHelper.php line 33

Open in your IDE?
  1. <?php
  2. namespace Harmonizely\Service\Common;
  3. use Harmonizely\Model\EventTypeInterface;
  4. class UrlHelper
  5. {
  6.     /**
  7.      * @var UrlHelper
  8.      */
  9.     private static UrlHelper $instance;
  10.     /**
  11.      * @var string
  12.      */
  13.     private string $host;
  14.     /**
  15.      * @param string $host
  16.      */
  17.     public function __construct(string $host)
  18.     {
  19.         $this->host $host;
  20.     }
  21.     /**
  22.      * Init instance
  23.      *
  24.      * @return void
  25.      */
  26.     public function init(): void
  27.     {
  28.         self::$instance $this;
  29.     }
  30.     /**
  31.      * @param EventTypeInterface $eventType
  32.      * @return string
  33.      */
  34.     public static function buildEventTypeDirectUrl(EventTypeInterface $eventType): string
  35.     {
  36.         $type $eventType->getType();
  37.         $slug $eventType->getSlug();
  38.         $user $eventType->getUser();
  39.         $userDomain $user->getDomain();
  40.         $organization $user->getDefaultOrganization();
  41.         if ($organization && ($type === EventTypeInterface::TYPE_ROUND_ROBIN || $type === EventTypeInterface::TYPE_COLLECTIVE)) {
  42.             $organizationDomain $organization->getDomain();
  43.             if ($organizationDomain) {
  44.                 return sprintf('https://%s/%s'$organizationDomain$slug);
  45.             }
  46.             return sprintf('https://%s/o/%s/%s'self::$instance->host$organization->getSlug(), $slug);
  47.         } else {
  48.             if ($userDomain) {
  49.                 return sprintf('https://%s/%s'$userDomain$slug);
  50.             }
  51.             if ($organization) {
  52.                 $organizationDomain $organization->getDomain();
  53.                 if ($organizationDomain) {
  54.                     return sprintf('https://%s/%s/%s'$organizationDomain$user->getSlug(), $slug);
  55.                 }
  56.             }
  57.             return sprintf('https://%s/%s/%s'self::$instance->host$user->getSlug(), $slug);
  58.         }
  59.     }
  60. }
  61. function buildEventTypeDirectUrl(EventTypeInterface $eventType): string
  62. {
  63.     return UrlHelper::buildEventTypeDirectUrl($eventType);
  64. }