engelsystem/includes/model/LogEntries_model.php

63 lines
1.1 KiB
PHP
Raw Normal View History

2012-12-26 14:02:27 +01:00
<?php
use Engelsystem\Database\DB;
2012-12-26 14:02:27 +01:00
/**
* Creates a log entry.
2013-10-13 00:52:44 +02:00
*
* @param string $logLevel Log level
* @param string $message Log Message
* @return bool
2012-12-26 14:02:27 +01:00
*/
function LogEntry_create($logLevel, $message)
2017-01-02 03:57:23 +01:00
{
return DB::insert('
INSERT INTO `LogEntries` (`timestamp`, `level`, `message`)
VALUES(?, ?, ?)
', [time(), $logLevel, $message]);
2012-12-26 14:02:27 +01:00
}
2012-12-27 02:18:56 +01:00
/**
2015-06-07 20:42:01 +02:00
* Returns log entries with maximum count of 10000.
2017-01-03 03:22:48 +01:00
*
* @return array
2012-12-27 02:18:56 +01:00
*/
2017-01-02 03:57:23 +01:00
function LogEntries()
{
return DB::select('SELECT * FROM `LogEntries` ORDER BY `timestamp` DESC LIMIT 10000');
2012-12-26 20:36:31 +01:00
}
2014-12-15 21:23:57 +01:00
/**
* Returns log entries filtered by a keyword
2017-01-03 03:22:48 +01:00
*
* @param string $keyword
* @return array
2014-12-15 21:23:57 +01:00
*/
2017-01-02 03:57:23 +01:00
function LogEntries_filter($keyword)
{
2017-01-03 14:12:17 +01:00
if ($keyword == '') {
2017-01-02 03:57:23 +01:00
return LogEntries();
}
$keyword = '%' . $keyword . '%';
return DB::select('
SELECT *
FROM `LogEntries`
WHERE `level` LIKE ?
OR `message` LIKE ?
ORDER BY `timestamp` DESC
',
[$keyword, $keyword]
);
2014-12-15 21:23:57 +01:00
}
2015-06-07 20:12:18 +02:00
/**
* Delete all log entries.
2017-01-03 03:22:48 +01:00
*
* @return bool
2015-06-07 20:12:18 +02:00
*/
2017-01-02 03:57:23 +01:00
function LogEntries_clear_all()
{
return DB::statement('TRUNCATE `LogEntries`');
2015-06-07 20:12:18 +02:00
}