Jump to content

Andy2024

Members
  • Posts

    23
  • Joined

  • Last visited

Community Answers

  1. Andy2024's post in Booking/Availability Calendar Help was marked as the answer   
    I managed to sort it, my question was a bit misleading. I had a calendar that was only showing 1 booked date range but that was because i had used = instead of == so now it shows all bookings
     

  2. Andy2024's post in Date range and Arrays was marked as the answer   
    I've managed to sort it and it works perfectly. I've also put it into a class, here is code if anyone wants to use it.
     
    Thank you for all your help!
     
     

    class Calendar
    {

        public static function bookedArray($strDateFrom,$strDateTo)
        {
          $aryRange = [];
          $iDateFrom = strtotime($strDateFrom);
          $iDateTo = strtotime($strDateTo);
          if ($iDateTo >= $iDateFrom) {
              array_push($aryRange, date('Y-m-d', $iDateFrom)); // first entry
              while ($iDateFrom<$iDateTo) {
                  $iDateFrom += 86400; // add 24 hours
                  array_push($aryRange, date('Y-m-d', $iDateFrom));
              }
          }
          return $aryRange;
        }
      
        public static function flattenCalendar($array) {
          $flatArray = [];
          array_walk_recursive($array, function($value) use (&$flatArray) {
              $flatArray[] = $value;
          });
          return $flatArray;
        }
      
        public static function estimatePrice($checkin, $checkout, $stdArray, $specArray) {
                
          $requestDates = self::bookedArray($checkin, $checkout);
          $specialRate = array();
          $standardRate = array();
          $cost = array();
          
          //return var_dump($requestDates);
          if(!empty($stdArray)) {
            foreach($stdArray as $row) {
              if($row->SeasonName == 'Standard Weekday') {
                $standardRate['Weekday'] = $row->SeasonPrice;
              }
              if($row->SeasonName == 'Standard Weekend') {
                $standardRate['Weekend'] = $row->SeasonPrice;
              }
            }
          }

          if(!empty($specArray)) {
            $i = 0;
            foreach($specArray as $row) {
                $specialRate[$i]['start'] = $row->SeasonStart;
                $specialRate[$i]['end'] = $row->SeasonEnd;
                $specialRate[$i]['price'] = $row->SeasonPrice;
              $i++;
            }
          }

          $specialCount = count($specialRate);
          $standardCount = count($stdArray);
          $flatRequest = self::flattenCalendar($requestDates); // Reqested Dated into One Array
          $cost = array();
          $specialCost = array();
          $days = count($flatRequest);

          foreach($flatRequest as $key => $val) {
            $specialDays = 0;
            for($i=0; $i<count($specialRate); $i++) {
              $range = self::bookedArray($specialRate[$i]['start'], $specialRate[$i]['end']);
              array_pop($range);
              if(in_array($val, $range)) {
                array_push($specialCost, $specialRate[$i]['price']);
                $specialDays++;
                unset($flatRequest[$key]);
              } 
            }
          }
          array_pop($flatRequest);
          foreach($flatRequest as $key => $val) {
            if( date('l', strtotime($val)) == 'Saturday' || date('l', strtotime($val)) == 'Sunday' ) {
              array_push($cost, $standardRate['Weekend']);
            } else {
              array_push($cost, $standardRate['Weekday']);
            }
          }
          
          
              
          if(!empty($cost) && !empty($specialCost)) {
            return array_sum(array_merge($cost, $specialCost));
          }
          elseif(!empty($specialCost) && empty($cost)) {
            array_pop($specialCost);
            return array_sum($specialCost);
          }
          else {
            return array_sum($cost);
          }
          
          
        }
    }
  3. Andy2024's post in Problems reading session array was marked as the answer   
    Thanks you so much, i couldn't see the wood for the trees
     
    i'd put $cartItems = $itemArray; instead of $cartItems[] = $itemArray; before setting the session Session::set("cart_item", $cartItems);
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.