Skip to content

Commit 3edb254

Browse files
author
Mplus Software
committed
> Version updated to 0.3.0.
> 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.
1 parent 6cbc19c commit 3edb254

File tree

1 file changed

+163
-9
lines changed

1 file changed

+163
-9
lines changed

Mplusqapiclient.php

Lines changed: 163 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,14 @@
66

77
class MplusQAPIclient
88
{
9-
const CLIENT_VERSION = '0.1.0';
9+
const CLIENT_VERSION = '0.3.0';
1010

1111
var $MIN_API_VERSION_MAJOR = 0;
12-
var $MIN_API_VERSION_MINOR = 2;
12+
var $MIN_API_VERSION_MINOR = 3;
1313
var $MIN_API_VERSION_REVIS = 0;
1414

1515
var $MAX_API_VERSION_MAJOR = 0;
16-
var $MAX_API_VERSION_MINOR = 2;
16+
var $MAX_API_VERSION_MINOR = 3;
1717
var $MAX_API_VERSION_REVIS = 0;
1818

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

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

322322
//----------------------------------------------------------------------------
323323

324+
public function getEmployees($employeeNumbers = array())
325+
{
326+
try {
327+
$result = $this->client->getEmployees($this->parser->convertGetEmployeesRequest($employeeNumbers));
328+
return $this->parser->parseEmployees($result);
329+
} catch (SoapFault $e) {
330+
throw new MplusQAPIException("SoapFault occurred: ".$e->getMessage(), 0, $e);
331+
} catch (Exception $e) {
332+
throw new MplusQAPIException("Exception occurred: ".$e->getMessage(), 0, $e);
333+
}
334+
} // END getEmployees()
335+
336+
//----------------------------------------------------------------------------
337+
324338
public function createProduct($product)
325339
{
326340
try {
@@ -379,6 +393,20 @@ public function getStock($branchNumber, $articleNumbers = array())
379393

380394
//----------------------------------------------------------------------------
381395

396+
public function getShifts($financialDate, $branchNumbers = array(), $employeeNumbers = array())
397+
{
398+
try {
399+
$result = $this->client->getShifts($this->parser->convertGetShiftsRequest($financialDate, $branchNumbers, $employeeNumbers));
400+
return $this->parser->parseShifts($result);
401+
} catch (SoapFault $e) {
402+
throw new MplusQAPIException("SoapFault occurred: ".$e->getMessage(), 0, $e);
403+
} catch (Exception $e) {
404+
throw new MplusQAPIException("Exception occurred: ".$e->getMessage(), 0, $e);
405+
}
406+
} // END getShifts()
407+
408+
//----------------------------------------------------------------------------
409+
382410
public function findOrder($extOrderId)
383411
{
384412
try {
@@ -722,7 +750,23 @@ public function parseProducts($soapProducts) {
722750
return $products;
723751
}
724752
return false;
725-
} // END parseProducts()
753+
} // END parseProductsemployees
754+
755+
//----------------------------------------------------------------------------
756+
757+
public function parseEmployees($soapEmployees)
758+
{
759+
if (isset($soapEmployees->employeeList)) {
760+
$soapEmployees = $soapEmployees->employeeList;
761+
$employees = array();
762+
if (isset($soapEmployees->employee)) {
763+
$soapEmployees = $soapEmployees->employee;
764+
$employees = objectToArray($soapEmployees);
765+
}
766+
return $employees;
767+
}
768+
return false;
769+
} // END parseEmployees()
726770

727771
//----------------------------------------------------------------------------
728772

@@ -783,7 +827,33 @@ public function parseStock($soapStock) {
783827
return $articleStocks;
784828
}
785829
return false;
786-
} // END parseStock();
830+
} // END parseStock()
831+
832+
//----------------------------------------------------------------------------
833+
834+
public function parseShifts($soapShifts) {
835+
if (isset($soapShifts->shiftList)) {
836+
$soapShifts = $soapShifts->shiftList;
837+
$shifts = array();
838+
if (isset($soapShifts->shift)) {
839+
$shifts = objectToArray($soapShifts->shift);
840+
foreach ($shifts as $key => $shift) {
841+
if (isset($shift['financialDate'])) {
842+
$shift['financialDate'] = $this->parseMplusDate($shift['financialDate']);
843+
}
844+
if (isset($shift['startTimestamp'])) {
845+
$shift['startTimestamp'] = $this->parseMplusDateTime($shift['startTimestamp']);
846+
}
847+
if (isset($shift['endTimestamp'])) {
848+
$shift['endTimestamp'] = $this->parseMplusDateTime($shift['endTimestamp']);
849+
}
850+
$shifts[$key] = $shift;
851+
}
852+
}
853+
return $shifts;
854+
}
855+
return false;
856+
} // END parseShifts()
787857

788858
//----------------------------------------------------------------------------
789859

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

10861156
//----------------------------------------------------------------------------
10871157

1158+
public function convertGetEmployeesRequest($employeeNumbers)
1159+
{
1160+
if ( ! is_array($employeeNumbers)) {
1161+
$employeeNumbers = array($employeeNumbers);
1162+
}
1163+
$object = arrayToObject(array('request'=>array(
1164+
'employeeNumbers'=>empty($employeeNumbers)?null:array_values($employeeNumbers),
1165+
)));
1166+
return $object;
1167+
} // END convertGetEmployeesRequest()
1168+
1169+
//----------------------------------------------------------------------------
1170+
1171+
public function convertGetShiftsRequest($financialDate, $branchNumbers, $employeeNumbers)
1172+
{
1173+
if ( ! isset($financialDate) or is_null($financialDate) or empty($financialDate)) {
1174+
$financialDate = time();
1175+
}
1176+
$financialDate = $this->convertMplusDate($financialDate);
1177+
if ( ! is_array($branchNumbers)) {
1178+
$branchNumbers = array($branchNumbers);
1179+
}
1180+
if ( ! is_array($employeeNumbers)) {
1181+
$employeeNumbers = array($employeeNumbers);
1182+
}
1183+
$object = arrayToObject(array('request'=>array(
1184+
'financialDate'=>$financialDate,
1185+
'branchNumbers'=>empty($branchNumbers)?null:array_values($branchNumbers),
1186+
'employeeNumbers'=>empty($employeeNumbers)?null:array_values($employeeNumbers),
1187+
)));
1188+
return $object;
1189+
} // END convertGetShiftsRequest()
1190+
1191+
//----------------------------------------------------------------------------
1192+
10881193
public function convertPluNumbers($pluNumbers)
10891194
{
10901195
$text = array();
@@ -1472,18 +1577,53 @@ public function convertOrderLineList($lineList, $is_preparationList=false)
14721577

14731578
public function convertMplusDateTime($timestamp)
14741579
{
1475-
return $timestamp;
1580+
return array(
1581+
'day' => date('j', $timestamp),
1582+
'mon' => date('n', $timestamp),
1583+
'year' => date('Y', $timestamp),
1584+
);
14761585
} // END convertMplusDateTime()
14771586

14781587
//----------------------------------------------------------------------------
14791588

1589+
public function parseMplusDateTime($mplus_date_time)
1590+
{
1591+
if ($mplus_date_time['day'] == 0 || $mplus_date_time['mon'] == 0 || $mplus_date_time['year'] == 0) {
1592+
return null;
1593+
} else {
1594+
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']);
1595+
}
1596+
} // END parseMplusDateTime()
1597+
1598+
//----------------------------------------------------------------------------
1599+
14801600
public function convertMplusDate($timestamp)
14811601
{
1482-
return $timestamp;
1602+
return array(
1603+
'day' => date('j', $timestamp),
1604+
'mon' => date('n', $timestamp),
1605+
'year' => date('Y', $timestamp),
1606+
'hour' => date('H', $timestamp),
1607+
'min' => date('i', $timestamp),
1608+
'sec' => date('s', $timestamp),
1609+
'isdst' => false,
1610+
'timezone' => 0,
1611+
);
14831612
} // END convertMplusDate()
14841613

14851614
//----------------------------------------------------------------------------
14861615

1616+
public function parseMplusDate($mplus_date)
1617+
{
1618+
if ($mplus_date['day'] == 0 || $mplus_date['mon'] == 0 || $mplus_date['year'] == 0) {
1619+
return null;
1620+
} else {
1621+
return mktime(0, 0, 0, $mplus_date['mon'], $mplus_date['day'], $mplus_date['year']);
1622+
}
1623+
} // END parseMplusDate()
1624+
1625+
//----------------------------------------------------------------------------
1626+
14871627
public function convertYearNumber($year_number)
14881628
{
14891629
return $year_number;
@@ -1602,16 +1742,27 @@ function objectToArray($d) {
16021742

16031743
//------------------------------------------------------------------------------
16041744

1605-
function arrayToObject($d) {
1745+
$global_leave_as_array = null;
1746+
function arrayToObject($d, $leave_as_array=null) {
1747+
global $global_leave_as_array;
1748+
if ( ! is_null($leave_as_array)) {
1749+
$global_leave_as_array = $leave_as_array;
1750+
}
16061751
if (is_array($d)) {
16071752
/*
16081753
* Return array converted to object
16091754
* Using __FUNCTION__ (Magic constant)
16101755
* for recursive call
16111756
*/
16121757
if (isset($d['articleNumbers']) or isset($d['groupNumbers'])) {
1758+
if ( ! is_null($leave_as_array)) {
1759+
$global_leave_as_array = null;
1760+
}
16131761
return (object) $d;
16141762
}
1763+
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])) {
1764+
return array_map(__FUNCTION__, $d);
1765+
}
16151766
elseif (is_array($d) and isset($d[0]) and is_array($d[0]) and isset($d[0]['text'])) {
16161767
return array_map(__FUNCTION__, $d);
16171768
}
@@ -1633,6 +1784,9 @@ function arrayToObject($d) {
16331784
}
16341785
else {
16351786
// Return object
1787+
if ( ! is_null($leave_as_array)) {
1788+
$global_leave_as_array = null;
1789+
}
16361790
return $d;
16371791
}
16381792
} // END arrayToObject()

0 commit comments

Comments
 (0)