You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

63 lines
2.2 KiB
PHP

<?php
class Machine {
private $machineid = "";
private $machine = [];
private $history = [];
private $components = [];
public function __construct($machineid) {
global $database;
if ($database->has('machines', ['machineid' => $machineid])) {
$this->machineid = $machineid;
$this->machine = $database->get('machines', ['machineid', 'notes', 'model', 'condition', 'price'], ['machineid' => $machineid]);
$this->history = $database->select('history', ['[>]event_types' => 'eventid'], ['historyid', 'date', 'eventname', 'notes'], ['machineid' => $machineid]);
$this->components = $database->select('components', ['[>]component_types' => 'typeid'], ['compid', 'serial', 'typename', 'tested', 'notes', 'capacity', 'model'], ['machineid' => $machineid]);
} else {
throw new Exception("No machine with that ID number could be found.");
}
}
public function getHistory() {
return $this->history;
}
public function getMachineInfo() {
$info = [];
$info['machineid'] = $this->machineid;
if (!empty($this->machine['model'])) {
$info['model'] = $this->machine['model'];
}
if (!empty($this->machine['condition'])) {
$info['condition'] = $this->machine['condition'];
}
if (!empty($this->machine['price'])) {
$info['price'] = $this->machine['price'];
}
$info['notes'] = $this->machine['notes'];
return $info;
}
public function getComponents() {
$info = [];
foreach ($this->components as $c) {
$info[$c['compid']] = [
'serial' => $c['serial'],
'type' => $c['typename'],
'notes' => $c['notes']
];
if (!empty($c['tested'])) {
$info[$c['compid']]['tested'] = $c['tested'];
}
if (!empty($c['capacity'])) {
$info[$c['compid']]['capacity'] = $c['capacity'];
}
if (!empty($c['model'])) {
$info[$c['compid']]['model'] = $c['model'];
}
}
return $info;
}
}