<?php
namespace App\Util;
use App\Dto\OnlineCheckin\ReservationDetailResponseDto;
use App\Entity\Client;
use App\Entity\PaymentGateway;
use App\Entity\PaymentGatewaySettings;
use App\Entity\Property;
use App\Entity\SonataMediaMedia;
use App\Util\OnlineCheckin\DefaultAdapter;
use Symfony\Component\HttpFoundation\RequestStack;
use Symfony\Component\HttpFoundation\Session\SessionInterface;
class SystemUtil
{
protected $property;
protected $logo;
private $session = null;
/**
* @var PropertyUtil
*/
private $propertyUtil;
/**
* @var OnlineCheckinUtil
*/
private $onlineCheckinUtil;
/**
* @var PMSConnectorUtil
*/
private $connectorUtil;
/**
* @var RequestStack
*/
private $requestStack;
/**
* @var ClientUtil
*/
private $clientUtil;
public function __construct(PropertyUtil $propertyUtil, SessionInterface $session, OnlineCheckinUtil $onlineCheckinUtil, PMSConnectorUtil $connectorUtil, MediaUtil $mediaUtil, RequestStack $requestStack, ClientUtil $clientUtil)
{
$this->clientUtil = $clientUtil;
$this->requestStack = $requestStack;
$this->mediaUtil = $mediaUtil;
$this->propertyUtil = $propertyUtil;
$this->onlineCheckinUtil = $onlineCheckinUtil;
$this->connectorUtil = $connectorUtil;
$this->session = $session;
}
public function getCurrentPropertyIdentifier()
{
return $this->session->get('current_property_identifier', null);
}
public function setCurrentPropertyIdentifier($identifier)
{
$this->session->set('current_property_identifier', $identifier);
}
public function initProperty(?Property $property = null): bool
{
if (!$property instanceof Property) {
$propertyId = $this->session->get('current_property_id', 0);
$property = $this->propertyUtil->getProperty($propertyId);
}
if (!$property instanceof Property) {
return false;
}
$this->property = $property;
$this->connectorUtil->setProperty($property);
$this->onlineCheckinUtil->initProperty($property);
$this->session->set('current_property_id', $property->getId());
return true;
}
/**
* @return mixed
*/
public function getLogoPath()
{
if (!$this->property instanceof Property) {
return "";
}
if (!$this->property->getLogo() instanceof SonataMediaMedia) {
return "";
}
$logo = $this->mediaUtil->getImageUrl($this->property->getLogo(), 'default_big');
return $logo;
}
/**
* @return mixed
*/
public function getPropertyName()
{
if (!$this->property instanceof Property) {
return "";
}
return $this->property->getName();
}
/**
* @return mixed
*/
public function isPaymentsActivated()
{
if (!$this->property instanceof Property) {
return false;
}
if (!$this->property->getPaymentGatewaySettings() instanceof PaymentGatewaySettings) {
return false;
}
if (!$this->property->getPaymentGatewaySettings()->getPaymentGateway() instanceof PaymentGateway) {
return false;
}
return true;
}
public function getCurrentClient() {
if (!$this->property instanceof Property) {
return null;
}
if (!$this->property->getClient() instanceof Client) {
return false;
}
return $this->property->getClient();
}
public function getRelevantProperties() {
$client = $this->getCurrentClient();
if(!$client instanceof Client) {
return [];
}
return $client->getProperties()->toArray();
}
public function hasClientTickets()
{
if (!$this->property instanceof Property) {
return false;
}
if (!$this->property->getClient() instanceof Client) {
return false;
}
if ($this->property->getClient()->getId() == 1) {
return true;
}
return false;
}
public function getBaseUrl()
{
if (!$this->property instanceof Property) {
return "";
}
foreach ($this->property->getClient()->getUrls() as $url) {
if ($url->getIsDefault()) {
return $url->getUrl();
}
}
return "";
}
public function getClientByCurrentUrl() {
$url = $this->requestStack->getCurrentRequest()->headers->get('host');
$client = $this->clientUtil->getClientByUrl($url);
if(!$client instanceof Client) {
return;
}
return $client;
}
}