Skip to content

Commit

Permalink
> Version updated to 0.3.0.
Browse files Browse the repository at this point in the history
> Supported API version updated to 0.3.0.

> WSDL now loaded from public URL instead of local file.
+ Support for getEmployees() function.
+ Support for getShifts() function.
> Tweaks made to arrayToObject() function.
  • Loading branch information
Mplus Software committed Jul 24, 2014
1 parent 6cbc19c commit 3edb254
Showing 1 changed file with 163 additions and 9 deletions.
172 changes: 163 additions & 9 deletions Mplusqapiclient.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@

class MplusQAPIclient
{
const CLIENT_VERSION = '0.1.0';
const CLIENT_VERSION = '0.3.0';

var $MIN_API_VERSION_MAJOR = 0;
var $MIN_API_VERSION_MINOR = 2;
var $MIN_API_VERSION_MINOR = 3;
var $MIN_API_VERSION_REVIS = 0;

var $MAX_API_VERSION_MAJOR = 0;
var $MAX_API_VERSION_MINOR = 2;
var $MAX_API_VERSION_MINOR = 3;
var $MAX_API_VERSION_REVIS = 0;

/**
Expand Down Expand Up @@ -179,7 +179,7 @@ public function initClient()
throw new MplusQAPIException('Fingerprint of SSL certificate doesn\'t match.');
}

$this->client = new SoapClient('MplusQapi.wsdl', $options);
$this->client = new SoapClient('https://api.mpluskassa.nl/MplusQapi.wsdl', $options);
$this->checkApiVersion();
// i($this->client->__getTypes());
// $this->client = new SoapClient(null, $options);
Expand Down Expand Up @@ -321,6 +321,20 @@ public function getProducts($articleNumbers = array(), $groupNumbers = array(),

//----------------------------------------------------------------------------

public function getEmployees($employeeNumbers = array())
{
try {
$result = $this->client->getEmployees($this->parser->convertGetEmployeesRequest($employeeNumbers));
return $this->parser->parseEmployees($result);
} catch (SoapFault $e) {
throw new MplusQAPIException("SoapFault occurred: ".$e->getMessage(), 0, $e);
} catch (Exception $e) {
throw new MplusQAPIException("Exception occurred: ".$e->getMessage(), 0, $e);
}
} // END getEmployees()

//----------------------------------------------------------------------------

public function createProduct($product)
{
try {
Expand Down Expand Up @@ -379,6 +393,20 @@ public function getStock($branchNumber, $articleNumbers = array())

//----------------------------------------------------------------------------

public function getShifts($financialDate, $branchNumbers = array(), $employeeNumbers = array())
{
try {
$result = $this->client->getShifts($this->parser->convertGetShiftsRequest($financialDate, $branchNumbers, $employeeNumbers));
return $this->parser->parseShifts($result);
} catch (SoapFault $e) {
throw new MplusQAPIException("SoapFault occurred: ".$e->getMessage(), 0, $e);
} catch (Exception $e) {
throw new MplusQAPIException("Exception occurred: ".$e->getMessage(), 0, $e);
}
} // END getShifts()

//----------------------------------------------------------------------------

public function findOrder($extOrderId)
{
try {
Expand Down Expand Up @@ -722,7 +750,23 @@ public function parseProducts($soapProducts) {
return $products;
}
return false;
} // END parseProducts()
} // END parseProductsemployees

//----------------------------------------------------------------------------

public function parseEmployees($soapEmployees)
{
if (isset($soapEmployees->employeeList)) {
$soapEmployees = $soapEmployees->employeeList;
$employees = array();
if (isset($soapEmployees->employee)) {
$soapEmployees = $soapEmployees->employee;
$employees = objectToArray($soapEmployees);
}
return $employees;
}
return false;
} // END parseEmployees()

//----------------------------------------------------------------------------

Expand Down Expand Up @@ -783,7 +827,33 @@ public function parseStock($soapStock) {
return $articleStocks;
}
return false;
} // END parseStock();
} // END parseStock()

//----------------------------------------------------------------------------

public function parseShifts($soapShifts) {
if (isset($soapShifts->shiftList)) {
$soapShifts = $soapShifts->shiftList;
$shifts = array();
if (isset($soapShifts->shift)) {
$shifts = objectToArray($soapShifts->shift);
foreach ($shifts as $key => $shift) {
if (isset($shift['financialDate'])) {
$shift['financialDate'] = $this->parseMplusDate($shift['financialDate']);
}
if (isset($shift['startTimestamp'])) {
$shift['startTimestamp'] = $this->parseMplusDateTime($shift['startTimestamp']);
}
if (isset($shift['endTimestamp'])) {
$shift['endTimestamp'] = $this->parseMplusDateTime($shift['endTimestamp']);
}
$shifts[$key] = $shift;
}
}
return $shifts;
}
return false;
} // END parseShifts()

//----------------------------------------------------------------------------

Expand Down Expand Up @@ -1085,6 +1155,41 @@ public function convertGetProductsRequest($articleNumbers, $groupNumbers, $pluNu

//----------------------------------------------------------------------------

public function convertGetEmployeesRequest($employeeNumbers)
{
if ( ! is_array($employeeNumbers)) {
$employeeNumbers = array($employeeNumbers);
}
$object = arrayToObject(array('request'=>array(
'employeeNumbers'=>empty($employeeNumbers)?null:array_values($employeeNumbers),
)));
return $object;
} // END convertGetEmployeesRequest()

//----------------------------------------------------------------------------

public function convertGetShiftsRequest($financialDate, $branchNumbers, $employeeNumbers)
{
if ( ! isset($financialDate) or is_null($financialDate) or empty($financialDate)) {
$financialDate = time();
}
$financialDate = $this->convertMplusDate($financialDate);
if ( ! is_array($branchNumbers)) {
$branchNumbers = array($branchNumbers);
}
if ( ! is_array($employeeNumbers)) {
$employeeNumbers = array($employeeNumbers);
}
$object = arrayToObject(array('request'=>array(
'financialDate'=>$financialDate,
'branchNumbers'=>empty($branchNumbers)?null:array_values($branchNumbers),
'employeeNumbers'=>empty($employeeNumbers)?null:array_values($employeeNumbers),
)));
return $object;
} // END convertGetShiftsRequest()

//----------------------------------------------------------------------------

public function convertPluNumbers($pluNumbers)
{
$text = array();
Expand Down Expand Up @@ -1472,18 +1577,53 @@ public function convertOrderLineList($lineList, $is_preparationList=false)

public function convertMplusDateTime($timestamp)
{
return $timestamp;
return array(
'day' => date('j', $timestamp),
'mon' => date('n', $timestamp),
'year' => date('Y', $timestamp),
);
} // END convertMplusDateTime()

//----------------------------------------------------------------------------

public function parseMplusDateTime($mplus_date_time)
{
if ($mplus_date_time['day'] == 0 || $mplus_date_time['mon'] == 0 || $mplus_date_time['year'] == 0) {
return null;
} else {
return mktime($mplus_date_time['hour'], $mplus_date_time['min'], $mplus_date_time['sec'], $mplus_date_time['mon'], $mplus_date_time['day'], $mplus_date_time['year']);
}
} // END parseMplusDateTime()

//----------------------------------------------------------------------------

public function convertMplusDate($timestamp)
{
return $timestamp;
return array(
'day' => date('j', $timestamp),
'mon' => date('n', $timestamp),
'year' => date('Y', $timestamp),
'hour' => date('H', $timestamp),
'min' => date('i', $timestamp),
'sec' => date('s', $timestamp),
'isdst' => false,
'timezone' => 0,
);
} // END convertMplusDate()

//----------------------------------------------------------------------------

public function parseMplusDate($mplus_date)
{
if ($mplus_date['day'] == 0 || $mplus_date['mon'] == 0 || $mplus_date['year'] == 0) {
return null;
} else {
return mktime(0, 0, 0, $mplus_date['mon'], $mplus_date['day'], $mplus_date['year']);
}
} // END parseMplusDate()

//----------------------------------------------------------------------------

public function convertYearNumber($year_number)
{
return $year_number;
Expand Down Expand Up @@ -1602,16 +1742,27 @@ function objectToArray($d) {

//------------------------------------------------------------------------------

function arrayToObject($d) {
$global_leave_as_array = null;
function arrayToObject($d, $leave_as_array=null) {
global $global_leave_as_array;
if ( ! is_null($leave_as_array)) {
$global_leave_as_array = $leave_as_array;
}
if (is_array($d)) {
/*
* Return array converted to object
* Using __FUNCTION__ (Magic constant)
* for recursive call
*/
if (isset($d['articleNumbers']) or isset($d['groupNumbers'])) {
if ( ! is_null($leave_as_array)) {
$global_leave_as_array = null;
}
return (object) $d;
}
elseif ( ! is_null($global_leave_as_array) and is_array($d) and isset($d[0]) and is_array($d[0]) and isset($d[0][$global_leave_as_array])) {
return array_map(__FUNCTION__, $d);
}
elseif (is_array($d) and isset($d[0]) and is_array($d[0]) and isset($d[0]['text'])) {
return array_map(__FUNCTION__, $d);
}
Expand All @@ -1633,6 +1784,9 @@ function arrayToObject($d) {
}
else {
// Return object
if ( ! is_null($leave_as_array)) {
$global_leave_as_array = null;
}
return $d;
}
} // END arrayToObject()
Expand Down

0 comments on commit 3edb254

Please sign in to comment.