Create Location Hierarchy (PHP 5)

PHP 5 Sample Code

This is sample PHP 5 code that creates a simple location hierarchy. It requires the following location types to be defined already:

  • Region (top-level)
    • Distributor

<?php
// only show errors
error_reporting(E_ERROR | E_PARSE);

require_once('LmsService1.inc');

define('WSDL_ENDPOINT', 'https://demo.firmwater.com/lms/webservices/lmsservice1.asmx?wsdl');
define('CLIENT_ID', 'your-licensee-login-id');
define('USERNAME', 'your-username');
define('PASSWORD', 'your-password');

//********************************************************************
// functions
//********************************************************************

function createLocationObject($id, $name, $externalId, $type, $parentId, $parentName)
{
$loc = new LmsLocationObject();
if (!empty($id))
$loc->Id = $id;

$loc->LicenseeId = CLIENT_ID;

if (!empty($name))
$loc->LocationName = $name;

if (!empty($externalId))
$loc->ExternalLocationId = $externalId;

if (!empty($type))
$loc->LocationType = $type;

if (!empty($parentId))
$loc->ParentId = $parentId;

if (!empty($parentName))
$loc->ParentLocationName = $parentName;

return $loc;
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<title>Creating simple location hierarchy...</title>
</head>

<body>
<?php
$lmsBinding = new LmsService1(WSDL_ENDPOINT, true, true, true);

// authenticate and set endpoint address
print('<p>Calling Login method...');
try
{
$loginResult = $lmsBinding->Login(CLIENT_ID, USERNAME, PASSWORD);
print('done.</p><code>');
print_r($loginResult);
print('</code>');
}
catch (LmsService1_Exception $e)
{
print('</p><h2>ERROR:</h2>');
print('</code>' . $e->getMessage() . '</code>');
}

if ($loginResult != null)
{
// create location objects
print('<p>Creating top-level location object...');
$region = createLocationObject(null, 'Eastern Region', 'east', 'Region', null, null);
print('done.</p><code>');
print_r($region);
print('</code>');

print('<p>Creating child location object...');
$distributor = createLocationObject(null, 'Strombo Cranes', '0012', 'Distributor', null, 'Eastern Region');
print('done.</p><code>');
print_r($distributor);
print('</code>');
// create or update locations
$saveResult = null;
try
{
print('<p>Creating or updating locations...');
$saveResult = $lmsBinding->CreateOrUpdate(array($region, $distributor));
print('done.</p><code>');
print_r($saveResult);
print('</code>');

print('<h2>SUCCESS!</h2>');
}
catch (LmsService1_Exception $e)
{
print('</p><h2>ERROR:</h2>');
print('</code>' . $e->getMessage() . '</code>');
}
}
?>
</body>
</html>


ċ
LmsService1.inc
(15k)
Stefan Leyhane,
Aug 11, 2014, 12:10 PM