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.
engelsystem/includes/model/LogEntries_model.php

63 lines
1.2 KiB
PHTML

12 years ago
<?php
use Engelsystem\Database\DB;
12 years ago
/**
* Creates a log entry.
11 years ago
*
* @param string $logLevel Log level
* @param string $message Log Message
* @return bool
12 years ago
*/
function LogEntry_create($logLevel, $message)
8 years ago
{
return DB::insert('
INSERT INTO `LogEntries` (`timestamp`, `level`, `message`)
VALUES(?, ?, ?)
', [time(), $logLevel, $message]);
12 years ago
}
12 years ago
/**
* Returns log entries with maximum count of 10000.
*
* @return array
12 years ago
*/
8 years ago
function LogEntries()
{
return DB::select('SELECT * FROM `LogEntries` ORDER BY `timestamp` DESC LIMIT 10000');
}
/**
* Returns log entries filtered by a keyword
*
* @param string $keyword
* @return array
*/
8 years ago
function LogEntries_filter($keyword)
{
if ($keyword == '') {
8 years ago
return LogEntries();
}
$keyword = '%' . $keyword . '%';
return DB::select('
SELECT *
FROM `LogEntries`
WHERE `level` LIKE ?
OR `message` LIKE ?
ORDER BY `timestamp` DESC
',
[$keyword, $keyword]
);
}
/**
* Delete all log entries.
*
* @return bool
*/
8 years ago
function LogEntries_clear_all()
{
return DB::connection()->statement('TRUNCATE `LogEntries`');
}