Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- // Deps
- foreach (glob( get_template_directory() . "/inc/iTravel/*.php") as $filename)
- {
- include $filename;
- }
- // ...
- class iTravel extends SoapClient {
- private static $username = "info@caribbean-unpackaged.com";
- private static $password = "sWA95Huj";
- public function __construct() {
- $ns = "http://tempuri.org/";
- $headerParams = array(
- 'ns1:Username' => self::$username,
- 'ns1:Password' => self::$password
- );
- $auth_vals = new SoapVar($headerParams, SOAP_ENC_OBJECT);
- $authenticate = new SoapHeader($ns, 'AuthHeader', $auth_vals, false);
- parent::__construct( "http://caribbean.itravelsoftware.com/itravel/API/WebService/iTravelAPI_3_0.asmx?wsdl" );
- $this->__setSoapHeaders(array($authenticate));
- }
- // ...
- private function queryAccommodation( $oid, $filters ) {
- $from = 0;
- $to = 0;
- $adults = 0;
- $children = 0;
- extract( $filters );
- $from = $from ? new DateTime( str_replace( "/", "-", $from ) ) : new DateTime();
- if( null != $to ) :
- $to = new DateTime( str_replace( "/", "-", $to ) );
- else :
- $to = new DateTime();
- $to->modify('+7 days'); // dummy date range for estimated price
- endif;
- $parameters = new GetDetailedDescriptionParameters();
- $parameters->StartDate = $from->format(DateTime::W3C);
- $parameters->EndDate = $to->format(DateTime::W3C);
- $adults = $adults ? $adults : 1;
- $children = $children ? $children : 0;
- $parameters->NumberOfPersons = $adults;
- $parameters->ObjectID = $oid;
- $parameters->LanguageID = "en";
- $parameters->InPriceType = "PerDay";
- $getDetailedDescription = new GetDetailedDescription();
- $getDetailedDescription->getDetailedDescriptionParameters = $parameters;
- return $this->__soapCall( 'GetDetailedDescription', array( $getDetailedDescription ) );
- }
- // ...
- public function getMinimumPrice( $oid ) {
- $query = $this->queryAccommodation( $oid, $_GET );
- // Make sure we have results work with
- if(
- "Error" == $query->GetDetailedDescriptionResult->Status->Code ||
- ! (array) $query->GetDetailedDescriptionResult->AccommodationObject->UnitList
- )
- return false;
- $accUnits = $query->GetDetailedDescriptionResult->AccommodationObject->UnitList->AccommodationUnit;
- // When there is only one it does not go back as array.
- if(!is_array($accUnits)) {
- $accUnits = array($accUnits);
- }
- foreach($accUnits as $accUnit) {
- if( ! is_object( $accUnit ) )
- continue;
- $price1 = $accUnit->CalculatedPriceInfo->CalculatedPrice;//$accomodationDetails;
- $price2 = $accUnit->UnitMinimumPriceInfo->Price;
- if(($price1 == 0) || ($price2 == 0)) {
- $result[] = max($price1, $price2);
- } else {
- $result[] = min($price1, $price2);
- }
- }
- return isset( $result[0] ) ? floor( $result[0] ) : false;
- }
- // ...
- // The idea is to loop through available rooms and build an array to render a pricing table
- public function getRooms( $oid ) {
- $query = $this->queryAccommodation( $oid, $_GET );
- // Make sure we have results work with
- if(
- "Error" == $query->GetDetailedDescriptionResult->Status->Code ||
- ! (array) $query->GetDetailedDescriptionResult->AccommodationObject->UnitList
- )
- return false;
- $accUnits = $query->GetDetailedDescriptionResult->AccommodationObject->UnitList->AccommodationUnit;
- $rooms = array();
- // When there is only one it does not go back as array.
- if(!is_array($accUnits)) {
- $accUnits = array($accUnits);
- }
- foreach($accUnits as $acc) {
- if( ! is_object( $acc ) )
- continue;
- $rooms[$acc->UnitID]['name'] = $acc->AttributeGroupList->AttributeGroup->AttributeList->Attribute[1]->AttributeValue;
- // Services
- if( ! empty( $acc->ServiceList->Service ) ) :
- $i = 0;
- foreach( $acc->ServiceList->Service as $service ) :
- // Basic types are actual meal plans, others are just discounts
- if( ! isset( $service->ServiceType ) || $service->ServiceType != 'Basic' )
- continue;
- $rooms[$acc->UnitID]['service'][$i]['name'] = $service->ServiceName;
- $rooms[$acc->UnitID]['service'][$i]['price'] = floor( $service->Price );
- $i++;
- endforeach;
- endif;
- // Final check for services - we can't have a room without a service so...
- if( ! isset( $rooms[$acc->UnitID]['service'] ) ) :
- $rooms[$acc->UnitID]['service'][0]['name'] = "TBC";
- $rooms[$acc->UnitID]['service'][0]['price'] = 0;
- endif;
- }
- return $rooms;
- }
- }
- $itravel = new iTravel;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement