<?php
namespace Harmonizely\Service\Common;
use Harmonizely\Model\EventTypeInterface;
class UrlHelper
{
/**
* @var UrlHelper
*/
private static UrlHelper $instance;
/**
* @var string
*/
private string $host;
/**
* @param string $host
*/
public function __construct(string $host)
{
$this->host = $host;
}
/**
* Init instance
*
* @return void
*/
public function init(): void
{
self::$instance = $this;
}
/**
* @param EventTypeInterface $eventType
* @return string
*/
public static function buildEventTypeDirectUrl(EventTypeInterface $eventType): string
{
$type = $eventType->getType();
$slug = $eventType->getSlug();
$user = $eventType->getUser();
$userDomain = $user->getDomain();
$organization = $user->getDefaultOrganization();
if ($organization && ($type === EventTypeInterface::TYPE_ROUND_ROBIN || $type === EventTypeInterface::TYPE_COLLECTIVE)) {
$organizationDomain = $organization->getDomain();
if ($organizationDomain) {
return sprintf('https://%s/%s', $organizationDomain, $slug);
}
return sprintf('https://%s/o/%s/%s', self::$instance->host, $organization->getSlug(), $slug);
} else {
if ($userDomain) {
return sprintf('https://%s/%s', $userDomain, $slug);
}
if ($organization) {
$organizationDomain = $organization->getDomain();
if ($organizationDomain) {
return sprintf('https://%s/%s/%s', $organizationDomain, $user->getSlug(), $slug);
}
}
return sprintf('https://%s/%s/%s', self::$instance->host, $user->getSlug(), $slug);
}
}
}
function buildEventTypeDirectUrl(EventTypeInterface $eventType): string
{
return UrlHelper::buildEventTypeDirectUrl($eventType);
}