Files
PVM/public_html/classes/IMSApi.Response.class.php
2021-10-20 16:32:11 +02:00

129 lines
4.0 KiB
PHP

<?php
namespace IMSApi;
class Response extends \IMSApi {
private $esito = null;
private $execDate = null;
private $execTime = null;
private $profileDB = null;
private $operationType = null;
private $errorMessage = null;
private $errorType = null;
private $report = null;
private $xml = null;
private $lastTransactionIdImport = null;
private $syncActive = false;
private $entity = null;
private $jsonObject = null;
private $listResponse = false;
public function __construct($returnData = null) {
if (!is_null($returnData)) {
$this->parse($returnData);
}
}
// <editor-fold desc="GET/SET/CHECK SEMPLICI" defaultstate="collapsed">
public function is_OK() {
return $this->esito == 1;
}
public function is_KO() {
return !$this->is_OK();
}
private function set_OK() {
$this->esito = 1;
return $this;
}
private function set_KO() {
$this->esito = -1;
return $this;
}
public function get_errorMessage() {
return $this->errorMessage;
}
private function set_errorMessage($v) {
$this->errorMessage = $v;
return $this;
}
public function get_jsonObject() {
return $this->jsonObject;
}
private function set_jsonObject($v) {
$this->jsonObject = $v;
return $this;
}
private function is_list() {
return $this->listResponse !== false && is_array($this->listResponse);
}
// </editor-fold>
public function get_item($i) {
if ($this->is_list() && array_key_exists($i, $this->listResponse)) {
return $this->listResponse[$i];
}
return null;
}
private function parse($returnData) {
if (isset($returnData[0])) { // LISTA
$this->set_OK();
$this->listResponse = array();
foreach ($returnData as $retDataItem) {
$Response = new Response($retDataItem);
if ($Response->is_KO()) {
$this->set_KO()->set_errorMessage($Response->get_errorMessage());
}
$this->listResponse[] = $Response;
}
} else { // SINGOLO
if (array_key_exists("esito", $returnData)) {
$this->esito = $returnData["esito"];
}
if (array_key_exists("execDate", $returnData)) {
$this->execDate = $returnData["execDate"];
$this->execTime = \Utility\Date::strtotime($this->execDate, \Format::strtotimeYMDHMS);
}
if (array_key_exists("profileDB", $returnData)) {
$this->profileDB = $returnData["profileDB"];
}
if (array_key_exists("operationType", $returnData)) {
$this->operationType = $returnData["operationType"];
}
if (array_key_exists("errorMessage", $returnData)) {
$this->errorMessage = $returnData["errorMessage"];
}
if (array_key_exists("errorType", $returnData)) {
$this->errorType = $returnData["errorType"];
}
if (array_key_exists("report", $returnData)) {
$this->report = $returnData["report"];
}
if (array_key_exists("xml", $returnData)) {
$this->xml = $returnData["xml"];
}
if (array_key_exists("lastTransactionIdImport", $returnData)) {
$this->lastTransactionIdImport = $returnData["lastTransactionIdImport"];
}
if (array_key_exists("syncActive", $returnData)) {
$this->syncActive = $returnData["syncActive"];
}
if (array_key_exists("entity", $returnData)) {
$this->entity = $returnData["entity"];
}
if (array_key_exists("dto", $returnData)) {
$this->jsonObject = $returnData["dto"];
}
}
return $this;
}
}