Advertisement
Guest User

Untitled

a guest
Jul 17th, 2018
128
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 5.69 KB | None | 0 0
  1. <?php
  2.  
  3. // Deps
  4. foreach (glob( get_template_directory() . "/inc/iTravel/*.php") as $filename)
  5. {
  6.     include $filename;
  7. }
  8.  
  9. // ...
  10.  
  11.  
  12. class iTravel extends SoapClient {
  13.  
  14.     private static $username = "info@caribbean-unpackaged.com";
  15.     private static $password = "sWA95Huj";
  16.    
  17.     public function __construct() {
  18.        
  19.         $ns   = "http://tempuri.org/";
  20.        
  21.         $headerParams = array(
  22.             'ns1:Username' => self::$username,
  23.             'ns1:Password' => self::$password
  24.         );
  25.        
  26.         $auth_vals    = new SoapVar($headerParams, SOAP_ENC_OBJECT);
  27.        
  28.         $authenticate = new SoapHeader($ns, 'AuthHeader', $auth_vals, false);
  29.        
  30.         parent::__construct( "http://caribbean.itravelsoftware.com/itravel/API/WebService/iTravelAPI_3_0.asmx?wsdl" );
  31.        
  32.         $this->__setSoapHeaders(array($authenticate));
  33.        
  34.     }
  35.    
  36.     // ...
  37.    
  38.     private function queryAccommodation( $oid, $filters ) {
  39.        
  40.         $from = 0;
  41.         $to = 0;
  42.         $adults = 0;
  43.         $children = 0;
  44.  
  45.         extract( $filters );
  46.        
  47.         $from = $from ? new DateTime( str_replace( "/", "-", $from ) ) : new DateTime();
  48.        
  49.         if( null != $to ) :
  50.             $to = new DateTime( str_replace( "/", "-", $to ) );
  51.         else :
  52.             $to = new DateTime();
  53.             $to->modify('+7 days'); // dummy date range for estimated price
  54.         endif;
  55.  
  56.         $parameters = new GetDetailedDescriptionParameters();
  57.         $parameters->StartDate = $from->format(DateTime::W3C);
  58.         $parameters->EndDate = $to->format(DateTime::W3C);
  59.        
  60.         $adults = $adults ? $adults : 1;
  61.         $children = $children ? $children : 0;
  62.        
  63.         $parameters->NumberOfPersons = $adults;
  64.         $parameters->ObjectID = $oid;
  65.         $parameters->LanguageID = "en";
  66.         $parameters->InPriceType = "PerDay";
  67.         $getDetailedDescription = new GetDetailedDescription();
  68.         $getDetailedDescription->getDetailedDescriptionParameters = $parameters;
  69.        
  70.         return $this->__soapCall( 'GetDetailedDescription', array( $getDetailedDescription ) );
  71.        
  72.     }
  73.    
  74.     // ...
  75.    
  76.     public function getMinimumPrice( $oid ) {
  77.        
  78.         $query = $this->queryAccommodation( $oid, $_GET );
  79.    
  80.         // Make sure we have results work with
  81.         if(
  82.             "Error" == $query->GetDetailedDescriptionResult->Status->Code ||
  83.             ! (array) $query->GetDetailedDescriptionResult->AccommodationObject->UnitList
  84.         )
  85.             return false;
  86.            
  87.         $accUnits = $query->GetDetailedDescriptionResult->AccommodationObject->UnitList->AccommodationUnit;
  88.  
  89.         // When there is only one it does not go back as array.
  90.         if(!is_array($accUnits)) {  
  91.             $accUnits = array($accUnits);
  92.         }
  93.        
  94.         foreach($accUnits as $accUnit) {
  95.            
  96.             if( ! is_object( $accUnit ) )
  97.                 continue;
  98.        
  99.             $price1 = $accUnit->CalculatedPriceInfo->CalculatedPrice;//$accomodationDetails;
  100.             $price2 = $accUnit->UnitMinimumPriceInfo->Price;
  101.             if(($price1 == 0) || ($price2 == 0)) {
  102.                 $result[] = max($price1, $price2);
  103.             } else {
  104.                 $result[] = min($price1, $price2);
  105.             }
  106.         }
  107.        
  108.         return isset( $result[0] ) ? floor( $result[0] ) : false;
  109.        
  110.     }
  111.    
  112.     // ...
  113.    
  114.     // The idea is to loop through available rooms and build an array to render a pricing table
  115.     public function getRooms( $oid ) {
  116.        
  117.         $query = $this->queryAccommodation( $oid, $_GET );
  118.        
  119.         // Make sure we have results work with
  120.         if(
  121.             "Error" == $query->GetDetailedDescriptionResult->Status->Code ||
  122.             ! (array) $query->GetDetailedDescriptionResult->AccommodationObject->UnitList
  123.         )
  124.             return false;
  125.            
  126.         $accUnits = $query->GetDetailedDescriptionResult->AccommodationObject->UnitList->AccommodationUnit;
  127.        
  128.         $rooms = array();
  129.        
  130.         // When there is only one it does not go back as array.
  131.         if(!is_array($accUnits)) {  
  132.             $accUnits = array($accUnits);
  133.         }
  134.  
  135.         foreach($accUnits as $acc) {
  136.            
  137.             if( ! is_object( $acc ) )
  138.                 continue;
  139.                
  140.             $rooms[$acc->UnitID]['name'] = $acc->AttributeGroupList->AttributeGroup->AttributeList->Attribute[1]->AttributeValue;
  141.            
  142.             // Services
  143.             if( ! empty( $acc->ServiceList->Service ) ) :
  144.                
  145.                 $i = 0;
  146.                
  147.                 foreach( $acc->ServiceList->Service as $service ) :
  148.                    
  149.                     // Basic types are actual meal plans, others are just discounts
  150.                     if( ! isset( $service->ServiceType ) || $service->ServiceType != 'Basic' )
  151.                         continue;
  152.                        
  153.                     $rooms[$acc->UnitID]['service'][$i]['name'] = $service->ServiceName;
  154.                     $rooms[$acc->UnitID]['service'][$i]['price'] = floor( $service->Price );
  155.            
  156.                     $i++;
  157.                
  158.                 endforeach;
  159.            
  160.             endif;
  161.            
  162.             // Final check for services - we can't have a room without a service so...
  163.             if( ! isset( $rooms[$acc->UnitID]['service'] ) ) :
  164.                 $rooms[$acc->UnitID]['service'][0]['name'] = "TBC";
  165.                 $rooms[$acc->UnitID]['service'][0]['price'] = 0;
  166.             endif;
  167.                
  168.         }
  169.  
  170.         return $rooms;
  171.        
  172.     }
  173.    
  174. }
  175.  
  176. $itravel = new iTravel;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement