<?

/************************************************************************
*
*                  OMS Web Service Functions 1.4
*                  -----------------------------
*
*     Copyright:   (C) 2007 moving primates GmbH
*      Function:   GetArtistReviews
*   Description:   Gets all reviews information of one artist which is
*                  online.
*   Change Date:   12/Jun/2007
*
*************************************************************************
*
*   REQUIRED ELEMENTS:
*
*   The following elements must be send with the request:
*
*   - ArtistID  < value must be numeric
*   - Page      < value must be numeric
*   - PageSize  < value must be numeric
*   - Fieldlist < must contain at least one child element
*
*   FIELD ELEMTNES:
*   
*   The following are Field elements which define what you get back from
*   the Web Service function. They must be named "Field", their value
*   must be the exact name of the following enumeration and they must be
*   created as a child element of "Fieldlist".
*
*   Field elements are optional, however it is required that you
*   create at least one; their send order is irrelevant.
*
*   - ReviewFirstName
*   - ReviewLastName
*   - ReviewEmail
*   - ReviewText
*   - ReviewDate
*
*************************************************************************
*   More info about elements and the functions can be found inside
*   the documentation.
************************************************************************/

$ArtistID = "35748"; // Example ID from an artist
include("inc/config.php"); // Example path, point it to your config.php


$dom = create_document();
$root = create_root_element($dom, "OMS");
create_element_attribute($root, "xmlns", $oms_cfg['artist_data_xmlns'] . "/GetArtistReviews");


// Here we are defining the REQUIRED elements

$el_artist_id = create_element($dom, "ArtistID");
set_element_value($dom, $el_artist_id, $ArtistID);

$el_page = create_element($dom, "Page");
set_element_value($dom, $el_page, "1");

$el_page_size = create_element($dom, "PageSize");
set_element_value($dom, $el_page_size, "5");

$el_fields_list = create_element($dom, "FieldList");


// Here we are defining the FIELDLIST and its elements (requesting all available)

$el_field = create_element($dom, "Field");
set_element_value($dom, $el_field, "ReviewFirstName");
add_child_element($el_fields_list, $el_field);

$el_field = create_element($dom, "Field");
set_element_value($dom, $el_field, "ReviewLastName");
add_child_element($el_fields_list, $el_field);

$el_field = create_element($dom, "Field");
set_element_value($dom, $el_field, "ReviewEmail");
add_child_element($el_fields_list, $el_field);

$el_field = create_element($dom, "Field");
set_element_value($dom, $el_field, "ReviewText");
add_child_element($el_fields_list, $el_field);

$el_field = create_element($dom, "Field");
set_element_value($dom, $el_field, "ReviewDate");
add_child_element($el_fields_list, $el_field);


// Preparing the XML which is going to be send

add_child_element($root, $el_artist_id);
add_child_element($root, $el_fields_list);
add_child_element($root, $el_page);
add_child_element($root, $el_page_size);

$xml_str = dump_to_string($dom);

$par = array("String_1" => $oms_cfg['ws_login'],
            
"String_2" => $oms_cfg['ws_password'],
            
"String_3" => $xml_str );


// Executing the Web Service function "GetArtistReviews"

$GetArtistReviews = ProcessWSCall($oms_cfg['artist_data_ws_url'], "GetArtistReviews", $par, $oms_cfg['artist_data_xmlns']);

// Counting available reviews

if(isset($GetArtistReviews['ArtistID']))
{
    if(isset(
$GetArtistReviews['ReviewList'][0]['Review']))
    {
        
$reviews_count = sizeof($GetArtistReviews['ReviewList'][0]['Review']);
    }
    else
    {
        
$reviews_count = 0;
    }
}

/************************************************************************
*
*   From here on we assign the content of the array to variables and
*   create some example output. This was done so you can see something
*   when opening the PHP files with your browser.
*
*   If you are looking for this code without any comments or output,
*   then check out the folder 'minimal_code'.
*
************************************************************************/

?>
<style type="text/css">
<!--
.font {
    font-family: Verdana, Arial, Helvetica, sans-serif;
    font-size: 12px;
}
-->
</style>
<span class="font"> <strong>We sent the following elements with our <u>REQUEST</u>:</strong><br />
<ul>
    <li><em>ArtistID</em> - value was &quot;35748&quot;, an example ID from an artist</li>
    <li><em>Page</em> - value was &quot;1&quot;</li>
    <li><em>PageSize</em> - value was &quot;5&quot;</li>
    <li><em>Fieldlist</em> - the requested child elements were: <i>
        <ul>
            <li>ReviewFirstName</li>
            <li>ReviewLastName</li>
            <li>ReviewEmail</li>
            <li>ReviewText</li>
            <li>ReviewDate</li>
        </ul>
        </i> </li>
</ul>
<br />
<strong>We got back the following array in <u>RESPONSE</u>:</strong><br />
<pre><? var_dump($GetArtistReviews); ?>
</pre>
<br />
<strong>We assign the array to  seperate variables and <u>OUTPUT</u> these (without any design here):</strong><br />
<?
    $ArtistID
= $GetArtistReviews['ArtistID'][0];
    
$ReviewCount = $GetArtistReviews['ReviewCount'][0];
    
$Page = $GetArtistReviews['Page'][0];
    
$PageSize = $GetArtistReviews['PageSize'][0];
?>
<ul>
<li>Artist ID: <? echo $ArtistID; ?></li>
<li>Review Count: <? echo $ReviewCount; ?></li>
<li>Page: <? echo $Page; ?></li>
<li>Page Size: <? echo $PageSize; ?></li>
</ul>
<br />
We are at page <? echo $Page; ?>, page size is set to <? echo $PageSize; ?>.<br />
Let's read out the <? echo $PageSize; ?> entries from the array:<br />
<br />
<ul>
<?
    
for($i=0;$i<$reviews_count;$i++)
    {
        
$ReviewFirstName = $GetArtistReviews['ReviewList'][0]['Review'][$i]['ReviewFirstName'];
        
$ReviewLastName = $GetArtistReviews['ReviewList'][0]['Review'][$i]['ReviewLastName'];
        
$ReviewEmail = $GetArtistReviews['ReviewList'][0]['Review'][$i]['ReviewEmail'];
        
$ReviewText = $GetArtistReviews['ReviewList'][0]['Review'][$i]['ReviewText'];
        
$ReviewDate = $GetArtistReviews['ReviewList'][0]['Review'][$i]['ReviewDate'];
?>
<p><strong>Entry No. <? echo $i+1; ?></strong></p>
<li>Review First Name: <? echo $ReviewFirstName; ?></li>
<li>Review Last Name: <? echo $ReviewLastName; ?></li>
<li>Review Email: <? echo $ReviewEmail; ?></li>
<li>Review Text: <? echo $ReviewText; ?></li>
<li>Review Date: <? echo $ReviewDate; ?></li>
<?
    
}
?>
</ul>
</span>