Solved

assign multiple variables of same name in soap php

Posted on 2012-04-09
4
231 Views
Last Modified: 2016-02-26
I have a soap call which I'm currently successfully making in our system, however I'm only able to query one short_name at a time.
This is the function that calls it.

  public function getCalendarSearch($values)
    {
        $request = new stdClass();
        $request->Channels->DistributionChannel = array("id"=>$this->auth->channelid, "key" => $this->auth->channelkey);
        $request->Providers =  $values["txtShortName"]; //checked short name list
        $request->Query->IndustryCategory = $values["selIndustryCategory"];
        $request->Query->Criteria = array("start_date"=>$values["txtStartDate"], "days"=>$values["txtDays"]);
        //Cache Mode
        if ($values["rdoAuto"] == "on") //Auto
            $request->Query = array("cache"=>"Auto");
            
        if ($values["rdoOn"] == "on") //On
            $request->Query = array("cache"=>"On");
            
        if ($values["rdoOff"] == "on") //Off
            $request->Query = array("cache"=>"Off");
            
        //Show Product Info in results
        if ($values["chkShowProduct"] == "on")
            $request->Response = array("product_calendar"=>true);
        else
            $request->Response = array("product_calendar"=>false);
            
        try {
            echo "<pre>".print_r($request, true)."</pre>";
            $res = $this->v3Client->CalendarSearch($request);
            echo "<pre>".print_r($res, true)."</pre>";
            if($res->Status->Success) {
                return $res->Channels->Channel->Providers->Provider;
            }
            
        } catch (SoapFault $exception) {
            echo $exception;
        }
        
        return null;
    }

Open in new window


The problem however is that we are meant to be able to make calls with the following xml
  <Providers>
    <Provider short_name="Test_ToothnNailLodge" xmlns="http://www.v3leisure.com/Schemas/CABS/1.0/CABS_Common.xsd" />
    <Provider short_name="Black_Jack_Get-A-Way" xmlns="http://www.v3leisure.com/Schemas/CABS/1.0/CABS_Common.xsd" />
    <Provider short_name="escapegoat_adventures" xmlns="http://www.v3leisure.com/Schemas/CABS/1.0/CABS_Common.xsd" />
    <Provider short_name="gekko_safari" xmlns="http://www.v3leisure.com/Schemas/CABS/1.0/CABS_Common.xsd" />
    <Provider short_name="Dereks" xmlns="http://www.v3leisure.com/Schemas/CABS/1.0/CABS_Common.xsd" />
    <Provider short_name="Trafalger_House" xmlns="http://www.v3leisure.com/Schemas/CABS/1.0/CABS_Common.xsd" />
    <Provider short_name="ChateauElan" xmlns="http://www.v3leisure.com/Schemas/CABS/1.0/CABS_Common.xsd" />
    <Provider short_name="Hunter_Resort" xmlns="http://www.v3leisure.com/Schemas/CABS/1.0/CABS_Common.xsd" />
    <Provider short_name="segenhoe_hotel" xmlns="http://www.v3leisure.com/Schemas/CABS/1.0/CABS_Common.xsd" />
    <Provider short_name="Tea_Gardens" xmlns="http://www.v3leisure.com/Schemas/CABS/1.0/CABS_Common.xsd" />
    <Provider short_name="BlackJackGetAWay" xmlns="http://www.v3leisure.com/Schemas/CABS/1.0/CABS_Common.xsd" />
  </Providers>

currently to call it we use something like this

$array = array('Provider' => array('short_name' => 'Naimanya_Cottage'));

Which works well, but we need more than one to be queried at one time. If we have more than one short_name called at the one time, then it would simply reassign the variable.

Does anyone have a workaround for this.

so that we can have it make just one call with multiple Provider-> short_name
presently we are looping through about 10 of these calls which isn't practical really. One call would be much better.

thanks for any help
0
Comment
Question by:paulp75
4 Comments
 
LVL 34

Expert Comment

by:Beverley Portlock
ID: 37827055
I am not really clear what you want here, but is the following of any assistance? For my own convenience I have loaded the XML as a string to generate an XML object which I process one entry at a time and store all the outputs in a result array keyed by the short name

<?php

/*----- Set up test data ----- */

$data = '<?xml version="1.0" ?>
  <Providers>
    <Provider short_name="Test_ToothnNailLodge" xmlns="http://www.v3leisure.com/Schemas/CABS/1.0/CABS_Common.xsd" />
    <Provider short_name="Black_Jack_Get-A-Way" xmlns="http://www.v3leisure.com/Schemas/CABS/1.0/CABS_Common.xsd" />
    <Provider short_name="escapegoat_adventures" xmlns="http://www.v3leisure.com/Schemas/CABS/1.0/CABS_Common.xsd" />
    <Provider short_name="gekko_safari" xmlns="http://www.v3leisure.com/Schemas/CABS/1.0/CABS_Common.xsd" />
    <Provider short_name="Dereks" xmlns="http://www.v3leisure.com/Schemas/CABS/1.0/CABS_Common.xsd" />
    <Provider short_name="Trafalger_House" xmlns="http://www.v3leisure.com/Schemas/CABS/1.0/CABS_Common.xsd" />
    <Provider short_name="ChateauElan" xmlns="http://www.v3leisure.com/Schemas/CABS/1.0/CABS_Common.xsd" />
    <Provider short_name="Hunter_Resort" xmlns="http://www.v3leisure.com/Schemas/CABS/1.0/CABS_Common.xsd" />
    <Provider short_name="segenhoe_hotel" xmlns="http://www.v3leisure.com/Schemas/CABS/1.0/CABS_Common.xsd" />
    <Provider short_name="Tea_Gardens" xmlns="http://www.v3leisure.com/Schemas/CABS/1.0/CABS_Common.xsd" />
    <Provider short_name="BlackJackGetAWay" xmlns="http://www.v3leisure.com/Schemas/CABS/1.0/CABS_Common.xsd" />
  </Providers>
';


$xml = simplexml_load_string( $data );

$result = array();

/* ----- End of test data set up ----- */





foreach( $xml as $aProvider ) {

     $att = $aProvider->attributes();

     // do SOAP call with $att['short_name'];
     
     $result [$att['short_name'] ] = .... result from SOAP call
}

Open in new window

0
 
LVL 6

Accepted Solution

by:
paulp75 earned 0 total points
ID: 37828426
I finally worked it out
I set the following as $request->Providers->Provider and it worked. thanks for your help anyway
Array
(
    [0] => Array
        (
            [short_name] => Barossa_Shiraz_Estate
        )

    [1] => Array
        (
            [short_name] => Barossa_Trike
        )

    [2] => Array
        (
            [short_name] => stonwellcottages
        )

    [3] => Array
        (
            [short_name] => greenocks_old_telegraph
        )

    [4] => Array
        (
            [short_name] => naimanya_cottage
        )

    [5] => Array
        (
            [short_name] => kooringalhomestead
        )

    [6] => Array
        (
            [short_name] => angel_rest
        )

    [7] => Array
        (
            [short_name] => Eagle_Foundry_Bed_and_Breakfast
        )

    [8] => Array
        (
            [short_name] => Barossa_ShirazEstate
        )

    [9] => Array
        (
            [short_name] => Normas_Place
        )

    [10] => Array
        (
            [short_name] => MiriamsCottage
        )

)
0

Featured Post

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

Part of the Global Positioning System A geocode (https://developers.google.com/maps/documentation/geocoding/) is the major subset of a GPS coordinate (http://en.wikipedia.org/wiki/Global_Positioning_System), the other parts being the altitude and t…
These instructions are based on installing Owncloud on your new raspberry pi connected with a usb HDD. What do you need Part A? A Raspberry Pi, model B. A boot SD card for the Raspberry Pi. A usb HDD An Ethernet cable to connect to the lo…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

758 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now