<?php
namespace SHServ\Entities;
use \SHServ\Entities\DeviceAuth;
class Device extends \SHServ\Middleware\Entity {
public static $table_name = "devices";
protected static $fields = [
"id", "alias", "name", "device_type", "device_name", "device_ip",
"device_mac", "device_hard_id", "firmware_version", "connection_state",
"state", "description", "last_contact", "create_at", "update_at"
];
protected $device_auth;
public function __construct(Int $id, Array $data = []){
parent::__construct(
self::$table_name,
$id,
$data
);
}
public function remove() {
$this -> state = "removed";
return $this -> update();
}
public function get_auth(): DeviceAuth | null {
if($this -> device_auth) {
return $this -> device_auth;
}
$result = app() -> thin_builder -> select(
DeviceAuth::$table_name,
DeviceAuth::get_fields(),
[ ["device_id", "=", $this -> id()] ]
);
if(!$result) {
return null;
}
$this -> device_auth = new DeviceAuth($result[0]["id"], $result[0]);
return $this -> device_auth ?? null;
}
}