@ -7,6 +7,9 @@
class Machine implements JsonSerializable {
private $machineid = "";
private $icon = "fas fa-desktop";
private $typeid = 14;
private $typelabel = "Machine";
private $machine = [];
private $events = [];
private $components = [];
@ -17,7 +20,11 @@ class Machine implements JsonSerializable {
$this->machineid = $machineid;
if (Machine::exists($machineid)) {
$this->exists = true;
$this->machine = $database->get('machines', ['model', 'condition', 'price', 'os', 'serial', 'manufacturer', 'clientid', 'privatenotes', 'publicnotes'], ['machineid' => $machineid]);
$this->machine = $database->get('machines', ['type', 'model', 'condition', 'price', 'os', 'serial', 'manufacturer', 'clientid', 'privatenotes', 'publicnotes'], ['machineid' => $machineid]);
$typeinfo = $database->get("machine_types", ["machinetypeid (id)", "typename (label)", "icon"], ["machinetypeid" => $this->machine["type"]]);
$this->icon = $typeinfo["icon"];
$this->typeid = $typeinfo["id"];
$this->typelabel = $typeinfo["label"];
$events = $database->select('events', 'historyid', ['machineid' => $machineid, "ORDER" => ["date" => "DESC"]]);
foreach ($events as $e) {
$this->events[] = new Event($e);
@ -35,6 +42,11 @@ class Machine implements JsonSerializable {
return [
"status" => "OK",
"id" => $this->machineid,
"icon" => $this->icon,
"type" => [
"id" => $this->typeid,
"label" => $this->typelabel
],
"info" => $this->machine,
"events" => $this->events,
"components" => $this->components,
@ -132,6 +144,18 @@ class Machine implements JsonSerializable {
return "";
}
public function getType(): int {
return $this->typeid;
}
public function getTypeLabel(): string {
return $this->typelabel;
}
public function getIcon(): string {
return $this->icon;
}
public function getModel(): string {
if (!empty($this->machine["model"])) {
return $this->machine["model"];
@ -196,6 +220,16 @@ class Machine implements JsonSerializable {
$this->machine["clientid"] = $id;
}
public function setType(int $typeid) {
global $database;
$this->typeid = $typeid;
$this->machine["type"] = $typeid;
$typeinfo = $database->get("machine_types", ["machinetypeid (id)", "typename (label)", "icon"], ["machinetypeid" => $typeid]);
$this->icon = $typeinfo["icon"];
$this->typelabel = $typeinfo["label"];
}
public function setModel(string $model) {
$this->machine["model"] = $model;
}