Solved

assign multiple variables of same name in soap php

Posted on 2012-04-09
4
240 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

MIM Survival Guide for Service Desk Managers

Major incidents can send mastered service desk processes into disorder. Systems and tools produce the data needed to resolve these incidents, but your challenge is getting that information to the right people fast. Check out the Survival Guide and begin bringing order to chaos.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

To properly understand GitHub, let’s divide it into two words ‘Git’ and ‘Hub’. Git is basically a ‘Distribution Version Control’ (DVC) and ‘Source Code Management’ (SCM) system widely used by software programmers while Hub means the efficient centre…
These days socially coordinated efforts have turned into a critical requirement for enterprises.
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
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…

856 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