From 038033df65fbb1b2565ec0fd1b5bb65e43098427 Mon Sep 17 00:00:00 2001 From: Skylar Ittner Date: Sun, 19 Jul 2020 19:04:51 -0600 Subject: [PATCH] Update jsonSerialize --- lib/Machine.lib.php | 31 ++++++++++++++++++++++++++++--- 1 file changed, 28 insertions(+), 3 deletions(-) diff --git a/lib/Machine.lib.php b/lib/Machine.lib.php index 0183c2b..7ab5fcc 100644 --- a/lib/Machine.lib.php +++ b/lib/Machine.lib.php @@ -52,7 +52,8 @@ class Machine implements JsonSerializable { "components" => $this->components, "formdata" => [ "options" => [ - "clientid" => Clients::getAllAsIDNameArray() + "clientid" => Clients::getAllAsIDNameArray(), + "type" => Machine::getTypeList() ], "inputtypes" => [ "model" => "text", @@ -63,7 +64,9 @@ class Machine implements JsonSerializable { "manufacturer" => "text", "clientid" => "select", "privatenotes" => "textarea", - "publicnotes" => "textarea" + "publicnotes" => "textarea", + "type" => "select", + "deleted" => "hidden" ], "labels" => [ "model" => $Strings->get("Model", false), @@ -74,7 +77,8 @@ class Machine implements JsonSerializable { "manufacturer" => $Strings->get("Manufacturer", false), "clientid" => $Strings->get("Client", false), "privatenotes" => $Strings->get("Private Notes", false), - "publicnotes" => $Strings->get("Public Notes", false) + "publicnotes" => $Strings->get("Public Notes", false), + "type" => $Strings->get("Type", false) ], "icons" => [] ] @@ -121,6 +125,27 @@ class Machine implements JsonSerializable { return false; } + public static function getTypeList(): array { + global $database; + $typelist = []; + foreach ($database->select("machine_types", ["machinetypeid (id)", "typename (name)"]) as $t) { + $typelist[$t["id"]] = $t["name"]; + } + return $typelist; + } + + public static function getTypeListWithIcons(): array { + global $database; + $typelist = []; + foreach ($database->select("machine_types", ["machinetypeid (id)", "typename (name)", "icon"]) as $t) { + $typelist[$t["id"]] = [ + "name" => $t["name"], + "icon" => $t["icon"] + ]; + } + return $typelist; + } + public function save() { global $database; if ($this->exists) {