From bcf91412f9d8ad466f282b57ab8f2a7d942f6211 Mon Sep 17 00:00:00 2001 From: Skylar Ittner Date: Sun, 19 Jul 2020 19:34:38 -0600 Subject: [PATCH] Enhance toArray() with client info --- lib/Machine.lib.php | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/lib/Machine.lib.php b/lib/Machine.lib.php index 7ab5fcc..ca88349 100644 --- a/lib/Machine.lib.php +++ b/lib/Machine.lib.php @@ -39,6 +39,21 @@ class Machine implements JsonSerializable { public function toArray() { global $Strings; if ($this->exists) { + $info = $this->machine; + // only show deleted if true + if (!$this->isDeleted()) { + unset($info["deleted"]); + } + $clientinfo = []; + if (!empty($this->getClientID())) { + $client = Clients::getClient($this->getClientID()); + $clientinfo = [ + "name" => $client->getName(), + "phone" => $client->getPhone(), + "billingaddress" => $client->getBillingAddress(), + "mailingaddress" => $client->getMailingAddress() + ]; + } return [ "status" => "OK", "id" => $this->machineid, @@ -47,7 +62,8 @@ class Machine implements JsonSerializable { "id" => $this->typeid, "label" => $this->typelabel ], - "info" => $this->machine, + "clientinfo" => $clientinfo, + "info" => $info, "events" => $this->events, "components" => $this->components, "formdata" => [ @@ -65,8 +81,7 @@ class Machine implements JsonSerializable { "clientid" => "select", "privatenotes" => "textarea", "publicnotes" => "textarea", - "type" => "select", - "deleted" => "hidden" + "type" => "select" ], "labels" => [ "model" => $Strings->get("Model", false),