id = $eventid;
if (\Event::exists($eventid)) {
$this->exists = true;
$this->event = $database->get('events', ['machineid', 'eventname', 'eventid', 'techuid', 'date', 'privatenotes', 'publicnotes'], ['historyid' => $eventid]);
}
}
public static function create(string $machineid = "", string $date = "", string $event = "", string $techuid = "", string $publicnotes = "", string $privatenotes = ""): Event {
if ($machineid == "" || $date == "" || empty($event)) {
return new Event("");
} else {
if (!Machine::exists($machineid)) {
throw new Exception("Invalid machine ID $machineid");
}
if (strtotime($date) === false) {
throw new Exception("Invalid date.");
}
$date = date("Y-m-d H:i:s", strtotime($date));
$evt = new Event("");
$evt->setMachineID($machineid);
$evt->setName($event);
$evt->setDate($date);
$evt->setTechUID($techuid);
$evt->setPrivateNotes($privatenotes);
$evt->setPublicNotes($publicnotes);
$evt->save();
return $evt;
}
}
public static function exists($id): bool {
global $database;
return $database->has('events', ['historyid' => $id]);
}
public static function getTypes() {
$list = json_decode(file_get_contents(__DIR__ . '/../custom/events.json'), true);
return $list;
}
public static function getFormDataArray() {
return [
"types" => $this->getTypes(),
"inputtypes" => [
"machineid" => "text",
"name" => "select",
"date" => "datetime",
"privatenotes" => "textarea",
"publicnotes" => "textarea"
],
"labels" => [
"machineid" => $Strings->get("Machine ID", false),
"name" => $Strings->get("Event", false),
"date" => $Strings->get("Date", false),
"privatenotes" => $Strings->get("Private Notes", false),
"publicnotes" => $Strings->get("Public Notes", false)
],
"icons" => []
];
}
public static function getTypesFormattedForForm() {
$eventtypes = Event::getTypes();
$eventselect = [];
foreach ($eventtypes as $key => $val) {
$optgroup = trim(str_replace("[]", "", $key));
$valprepend = strpos($key, " []") !== false ? "" : trim($key);
foreach ($val as $v) {
if (empty($valprepend)) {
$vpre = "";
} else if (empty($v)) {
$vpre = $valprepend;
} else {
$vpre = $valprepend . ": ";
}
if (empty($v)) {
$eventselect[$optgroup][$vpre] = "[$vpre Other]";
} else {
$eventselect[$optgroup][$vpre . $v] = $v;
}
}
}
return $eventselect;
}
public function toArray() {
global $Strings;
if ($this->exists) {
return [
"id" => $this->getID(),
"machineid" => $this->getMachineID(),
"name" => $this->getName(),
"date" => strtotime($this->getDate()),
"techuid" => $this->getTechUID(),
"publicnotes" => $this->getPublicNotes(),
"privatenotes" => $this->getPrivateNotes()
];
}
return [];
}
/**
* Render the events's info to HTML
* @param bool $public
*/
public function toHTML(bool $public = true): string {
global $Strings, $SETTINGS;
$html = $Strings->build("event html label", [
"name" => $this->getName(),
"date" => date($SETTINGS["datetime_format"], strtotime($this->getDate()))
], false);
$html .= "
\n";
if (!empty($this->getTechUID()) && $public == false) {
$html .= "" . $Strings->get("Technician", false) . ": " . htmlspecialchars((new User($this->getTechUID()))->getName()) . "
\n";
}
if (!empty($this->getPublicNotes())) {
$html .= "