src/Vendor/Helper.php line 134

Open in your IDE?
  1. <?php
  2. namespace App\Vendor;
  3. use App\Interfaces\HelperInterface;
  4. use App\Interfaces\IHotels;
  5. use Psr\Log\LoggerInterface;
  6. use Psr\Log\LogLevel;
  7. use Symfony\Component\HttpFoundation\Request;
  8. class Helper implements HelperInterface
  9. {
  10.     private LoggerInterface $zstLogger;
  11.     public function __construct(LoggerInterface $zstLogger){
  12.         $this->zstLogger $zstLogger;
  13.     }
  14.     public function logZst($start false$end false$params = []){
  15.         $message "";
  16.         $time date("Y-m-d H:i:s");
  17.         if(empty($params["error"])){
  18.             if(!empty($params["dumpType"])){
  19.                 if(!empty($start)){
  20.                     $message .= "Start processing hotel ".$params["dumpType"].". Time:".$time;
  21.                 }
  22.                 if(!empty($end)){
  23.                     $message .= "End processing hotel ".$params["dumpType"].". Time:".$time;
  24.                 }
  25.             } else{
  26.                 $message "";
  27.             }
  28.             $this->zstLogger->log(LogLevel::INFO$message);
  29.         } else {
  30.             $this->zstLogger->log(LogLevel::ERROR$params["error"]);
  31.         }
  32.     }
  33.     public static function uuid4($data null) {
  34.         $data $data ?? random_bytes(16);
  35.         assert(strlen($data) == 16);
  36.         $data[6] = chr(ord($data[6]) & 0x0f 0x40);
  37.         $data[8] = chr(ord($data[8]) & 0x3f 0x80);
  38.         return vsprintf('%s%s-%s-%s-%s-%s%s%s'str_split(bin2hex($data), 4));
  39.     }
  40.     public static function gen_uuid() {
  41.         return sprintf'%04x%04x-%04x-%04x-%04x-%04x%04x%04x',
  42.             // 32 bits for "time_low"
  43.             mt_rand00xffff ), mt_rand00xffff ),
  44.             // 16 bits for "time_mid"
  45.             mt_rand00xffff ),
  46.             // 16 bits for "time_hi_and_version",
  47.             // four most significant bits holds version number 4
  48.             mt_rand00x0fff ) | 0x4000,
  49.             // 16 bits, 8 bits for "clk_seq_hi_res",
  50.             // 8 bits for "clk_seq_low",
  51.             // two most significant bits holds zero and one for variant DCE1.1
  52.             mt_rand00x3fff ) | 0x8000,
  53.             // 48 bits for "node"
  54.             mt_rand00xffff ), mt_rand00xffff ), mt_rand00xffff )
  55.         );
  56.     }
  57.     public static function dateDiffInDays($date1$date2)
  58.     {
  59.         // Calculating the difference in timestamps
  60.         $diff strtotime($date2) - strtotime($date1);
  61.         // 1 day = 24 hours
  62.         // 24 * 60 * 60 = 86400 seconds
  63.         return abs(round($diff 86400));
  64.     }
  65.     public static function defaultParams(string $hotelId, array $paramsIHotels $hotelServiceRequest $request){
  66.         if(empty($params["search"]["checkin"]) || empty($params["search"]["checkout"])){
  67.             $currentDay date("Y-m-d");
  68.             $params["search"]["checkin"] = date("Y-m-d"strtotime($currentDay ' +1 day'));
  69.             $params["search"]["checkout"] =  date("Y-m-d"strtotime($currentDay ' +2 day'));
  70.         }
  71.         $region $hotelService->getByHotelId($hotelId$request->getLocale());
  72.         if(!empty($region)){
  73.             $regionData["id"] = $region[0]["id"];
  74.             $regionData["name"] = $region[0]["name"];
  75.         }
  76.         $checkIn =  empty($params["search"]["checkin"]) ? date("Y-m-d") : $params["search"]["checkin"];
  77.         $params["search"]["checkin"] =$checkIn;
  78.         $params["search"]["checkout"] = empty($params["search"]["checkout"]) ? date('Y-m-d'strtotime($checkIn ' +1 day'))  : $params["search"]["checkout"];
  79.         $hotelService->guestsRoomsDaysCount($params);
  80. //        $hotel = $hotelService->hotelPage($hotelId, $request);
  81.         return [];
  82.     }
  83.     public static function defaultSearchParams(){
  84.         $params = [
  85.             "search" => [
  86.                 "location" => "2395",
  87.                 "guests" => [
  88.                     [
  89.                         "adults" => "2",
  90.                         "children" => ["NaN"]
  91.                     ]
  92.                 ],
  93.                 "currency" => "RUB",
  94.                 "language" => "ru"
  95.             ]
  96.         ];
  97.         $currentDay date("Y-m-d");
  98.         $params["search"]["checkin"] = date("Y-m-d"strtotime($currentDay ' +1 day'));
  99.         $params["search"]["checkout"] =  date("Y-m-d"strtotime($currentDay ' +2 day'));
  100.         return $params;
  101.     }
  102.     public static function clearSession(Request $request){
  103.         $session $request->getSession();
  104.         if($session->has("guests_data")){
  105.             $session->remove("guests_data");
  106.         }
  107.         if($session->has("all_params")){
  108.             $session->remove("all_params");
  109.         }
  110.         if($session->has("bookingResult")){
  111.             $session->remove("bookingResult");
  112.         }
  113.         if($session->has("rate")){
  114.             $session->remove("rate");
  115.         }
  116. //        if($session->has('list')){
  117. //            $session->remove('list');
  118. //        }
  119. //        if($session->has('hotel')){
  120. //            $session->remove('hotel');
  121. //        }
  122.         if($session->has('back_url')){
  123.             $session->remove('back_url');
  124.         }
  125.     }
  126.     public static function interval($seconds){
  127.         $startDate date('Y-m-d H:i:s');
  128.         $start 0;
  129.         $k true;
  130.         while ($k){
  131.             $endDate date('Y-m-d H:i:s');
  132.             $diff strtotime($endDate) - strtotime($startDate);
  133.             $l abs(round($diff));
  134.             if(intval($l) == $seconds){
  135.                 $k false;
  136.             }
  137.             $start++;
  138.         }
  139.     }
  140. }