52 lines
1.8 KiB
PHP
52 lines
1.8 KiB
PHP
<?php
|
|
|
|
namespace objects;
|
|
|
|
use classes\db;
|
|
use classes\object_property;
|
|
use traits\db_object_t;
|
|
|
|
class logs_o extends db
|
|
{
|
|
use db_object_t;
|
|
public object_property $module;
|
|
public object_property $department;
|
|
public object_property $type;
|
|
public object_property $user_id;
|
|
public object_property $action;
|
|
public object_property $message;
|
|
|
|
public function structure(): void
|
|
{
|
|
$this->setTable('logs');
|
|
}
|
|
|
|
public function getObjectProperties(): void
|
|
{
|
|
$this->module = new object_property($this->table, $this->id, 'module', 'string', true);
|
|
$this->department = new object_property($this->table, $this->id, 'department', 'string', false);
|
|
$this->type = new object_property($this->table, $this->id, 'type', 'int', true);
|
|
$this->user_id = new object_property($this->table, $this->id, 'user_id', 'int', false);
|
|
$this->action = new object_property($this->table, $this->id, 'action', 'string', true);
|
|
$this->message = new object_property($this->table, $this->id, 'message', 'string', false);
|
|
}
|
|
|
|
public function add(string $module, string $department, int $type, int $user_id, string $action, string $message): void
|
|
{
|
|
global $db;
|
|
// Avoid SQL injection
|
|
$module = $db->escape_string($module);
|
|
$department = $db->escape_string($department);
|
|
$action = $db->escape_string($action);
|
|
$message = $db->escape_string($message);
|
|
// Create a new record in the database
|
|
$sql = "INSERT INTO $this->table (module, department, type, user_id, action, message) VALUES ('$module', '$department', $type, $user_id, '$action', '$message')";
|
|
$db->query($sql);
|
|
|
|
// Get the id of the new record
|
|
$this->id = $db->insert_id();
|
|
|
|
// Set the values of the object properties
|
|
$this->getObjectProperties();
|
|
}
|
|
} |