componentid = $componentid;
if (Component::exists($componentid)) {
$this->exists = true;
$this->component = $database->get("components", ["machineid", "serial", "typeid [Int]", "tested", "capacity", "model", "price [Number]", "manufacturer", "publicnotes", "privatenotes"], ["compid" => $componentid]);
}
}
public static function create(): Component {
return new Component(Component::generateId());
}
public static function exists($id): bool {
global $database;
return $database->has('components', ['compid' => $id]);
}
public static function getTypes() {
global $database;
$types = $database->select("component_types", ["typeid (id)", "typename (name)"]);
$list = [];
foreach ($types as $t) {
$list[$t['id']] = $t['name'];
}
return $list;
}
public function toArray() {
global $Strings;
if ($this->exists) {
return [
"info" => [
"id" => $this->getID(),
"machineid" => $this->getMachineID(),
"serial" => $this->getSerial(),
"type" => $this->getTypeID(),
"tested" => $this->getTestedDate(),
"capacity" => $this->getCapacity(),
"model" => $this->getModel(),
"price" => $this->getPrice(),
"manufacturer" => $this->getManufacturer(),
"publicnotes" => $this->getPublicNotes(),
"privatenotes" => $this->getPrivateNotes()
],
"formdata" => [
"types" => $this->getTypes(),
"inputtypes" => [
"machineid" => "text",
"serial" => "text",
"type" => "number",
"tested" => "datetime",
"capacity" => "text",
"model" => "text",
"price" => "number",
"manufacturer" => "text",
"privatenotes" => "textarea",
"publicnotes" => "textarea"
],
"labels" => [
"machineid" => $Strings->get("Machine ID", false),
"serial" => $Strings->get("Serial", false),
"type" => $Strings->get("Type", false),
"tested" => $Strings->get("Tested", false),
"capacity" => $Strings->get("Capacity", false),
"model" => $Strings->get("Model", false),
"price" => $Strings->get("Price", false),
"manufacturer" => $Strings->get("Manufacturer", false),
"privatenotes" => $Strings->get("Private Notes", false),
"publicnotes" => $Strings->get("Public Notes", false)
],
"icons" => []
]
];
}
return [];
}
/**
* Render the component's info to HTML
* @param bool $public
*/
public function toHTML(bool $public = true): string {
global $Strings;
$func = function($param) {
return $param;
};
$line = function($type) use ($public): string {
global $Strings, $SETTINGS;
if ($type == "TestedDate") {
if (!empty($this->getTestedDate())) {
return "" . $Strings->get("Tested On", false) . ": " . date($SETTINGS["date_format"], strtotime($this->getTestedDate())) . "
";
}
return "";
}
if ($type == "Price") {
if (!empty($this->getPrice())) {
return "" . $Strings->get("Price", false) . ": $" . number_format($this->getPrice(), 2) . "
";
}
return "";
}
if ($type == "PublicNotes") {
if (!empty($this->getPublicNotes())) {
return "