src/Util/SystemUtil.php line 57

Open in your IDE?
  1. <?php
  2. namespace App\Util;
  3. use App\Dto\OnlineCheckin\ReservationDetailResponseDto;
  4. use App\Entity\Client;
  5. use App\Entity\PaymentGateway;
  6. use App\Entity\PaymentGatewaySettings;
  7. use App\Entity\Property;
  8. use App\Entity\SonataMediaMedia;
  9. use App\Util\OnlineCheckin\DefaultAdapter;
  10. use Symfony\Component\HttpFoundation\RequestStack;
  11. use Symfony\Component\HttpFoundation\Session\SessionInterface;
  12. class SystemUtil
  13. {
  14.     protected $property;
  15.     protected $logo;
  16.     private $session null;
  17.     /**
  18.      * @var PropertyUtil
  19.      */
  20.     private $propertyUtil;
  21.     /**
  22.      * @var OnlineCheckinUtil
  23.      */
  24.     private $onlineCheckinUtil;
  25.     /**
  26.      * @var PMSConnectorUtil
  27.      */
  28.     private $connectorUtil;
  29.     /**
  30.      * @var RequestStack
  31.      */
  32.     private $requestStack;
  33.     /**
  34.      * @var ClientUtil
  35.      */
  36.     private $clientUtil;
  37.     public function __construct(PropertyUtil $propertyUtilSessionInterface $sessionOnlineCheckinUtil $onlineCheckinUtilPMSConnectorUtil $connectorUtilMediaUtil $mediaUtilRequestStack $requestStackClientUtil $clientUtil)
  38.     {
  39.         $this->clientUtil $clientUtil;
  40.         $this->requestStack $requestStack;
  41.         $this->mediaUtil $mediaUtil;
  42.         $this->propertyUtil $propertyUtil;
  43.         $this->onlineCheckinUtil $onlineCheckinUtil;
  44.         $this->connectorUtil $connectorUtil;
  45.         $this->session $session;
  46.     }
  47.     public function getCurrentPropertyIdentifier()
  48.     {
  49.         return $this->session->get('current_property_identifier'null);
  50.     }
  51.     public function setCurrentPropertyIdentifier($identifier)
  52.     {
  53.         $this->session->set('current_property_identifier'$identifier);
  54.     }
  55.     public function initProperty(?Property $property null): bool
  56.     {
  57.         if (!$property instanceof Property) {
  58.             $propertyId $this->session->get('current_property_id'0);
  59.             $property $this->propertyUtil->getProperty($propertyId);
  60.         }
  61.         if (!$property instanceof Property) {
  62.             return false;
  63.         }
  64.         $this->property $property;
  65.         $this->connectorUtil->setProperty($property);
  66.         $this->onlineCheckinUtil->initProperty($property);
  67.         $this->session->set('current_property_id'$property->getId());
  68.         return true;
  69.     }
  70.     /**
  71.      * @return mixed
  72.      */
  73.     public function getLogoPath()
  74.     {
  75.         if (!$this->property instanceof Property) {
  76.             return "";
  77.         }
  78.         if (!$this->property->getLogo() instanceof SonataMediaMedia) {
  79.             return "";
  80.         }
  81.         $logo $this->mediaUtil->getImageUrl($this->property->getLogo(), 'default_big');
  82.         return $logo;
  83.     }
  84.     /**
  85.      * @return mixed
  86.      */
  87.     public function getPropertyName()
  88.     {
  89.         if (!$this->property instanceof Property) {
  90.             return "";
  91.         }
  92.         return $this->property->getName();
  93.     }
  94.     /**
  95.      * @return mixed
  96.      */
  97.     public function isPaymentsActivated()
  98.     {
  99.         if (!$this->property instanceof Property) {
  100.             return false;
  101.         }
  102.         if (!$this->property->getPaymentGatewaySettings() instanceof PaymentGatewaySettings) {
  103.             return false;
  104.         }
  105.         if (!$this->property->getPaymentGatewaySettings()->getPaymentGateway() instanceof PaymentGateway) {
  106.             return false;
  107.         }
  108.         return true;
  109.     }
  110.     public function getCurrentClient() {
  111.         if (!$this->property instanceof Property) {
  112.             return null;
  113.         }
  114.         if (!$this->property->getClient() instanceof Client) {
  115.             return false;
  116.         }
  117.         return $this->property->getClient();
  118.     }
  119.     public function getRelevantProperties() {
  120.         $client $this->getCurrentClient();
  121.         if(!$client instanceof Client) {
  122.             return [];
  123.         }
  124.         return $client->getProperties()->toArray();
  125.     }
  126.     public function hasClientTickets()
  127.     {
  128.         if (!$this->property instanceof Property) {
  129.             return false;
  130.         }
  131.         if (!$this->property->getClient() instanceof Client) {
  132.             return false;
  133.         }
  134.         if ($this->property->getClient()->getId() == 1) {
  135.             return true;
  136.         }
  137.         return false;
  138.     }
  139.     public function getBaseUrl()
  140.     {
  141.         if (!$this->property instanceof Property) {
  142.             return "";
  143.         }
  144.         foreach ($this->property->getClient()->getUrls() as $url) {
  145.             if ($url->getIsDefault()) {
  146.                 return $url->getUrl();
  147.             }
  148.         }
  149.         return "";
  150.     }
  151.     
  152.     public function getClientByCurrentUrl() {
  153.         $url $this->requestStack->getCurrentRequest()->headers->get('host');
  154.         $client $this->clientUtil->getClientByUrl($url);
  155.         if(!$client instanceof Client) {
  156.             return;
  157.         }
  158.         return $client;
  159.     }
  160. }