diff options
Diffstat (limited to 'includes')
-rw-r--r-- | includes/includes.php | 1 | ||||
-rw-r--r-- | includes/model/LogEntries_model.php | 62 | ||||
-rw-r--r-- | includes/pages/admin_log.php | 20 |
3 files changed, 13 insertions, 70 deletions
diff --git a/includes/includes.php b/includes/includes.php index 7a68c3c9..628cf88e 100644 --- a/includes/includes.php +++ b/includes/includes.php @@ -13,7 +13,6 @@ $includeFiles = [ __DIR__ . '/../includes/model/AngelType_model.php', __DIR__ . '/../includes/model/EventConfig_model.php', - __DIR__ . '/../includes/model/LogEntries_model.php', __DIR__ . '/../includes/model/Message_model.php', __DIR__ . '/../includes/model/NeededAngelTypes_model.php', __DIR__ . '/../includes/model/Room_model.php', diff --git a/includes/model/LogEntries_model.php b/includes/model/LogEntries_model.php deleted file mode 100644 index b16c598c..00000000 --- a/includes/model/LogEntries_model.php +++ /dev/null @@ -1,62 +0,0 @@ -<?php - -use Engelsystem\Database\DB; - -/** - * Creates a log entry. - * - * @param string $logLevel Log level - * @param string $message Log Message - * @return bool - */ -function LogEntry_create($logLevel, $message) -{ - return DB::insert(' - INSERT INTO `LogEntries` (`timestamp`, `level`, `message`) - VALUES(?, ?, ?) - ', [time(), $logLevel, $message]); -} - -/** - * Returns log entries with maximum count of 10000. - * - * @return array - */ -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 - */ -function LogEntries_filter($keyword) -{ - if ($keyword == '') { - 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 - */ -function LogEntries_clear_all() -{ - return DB::connection()->statement('TRUNCATE `LogEntries`'); -} diff --git a/includes/pages/admin_log.php b/includes/pages/admin_log.php index f80f59d2..2a736aa5 100644 --- a/includes/pages/admin_log.php +++ b/includes/pages/admin_log.php @@ -1,5 +1,7 @@ <?php +use Engelsystem\Models\LogEntry; + /** * @return string */ @@ -17,10 +19,14 @@ function admin_log() if (request()->has('keyword')) { $filter = strip_request_item('keyword'); } - $log_entries = LogEntries_filter($filter); - foreach ($log_entries as &$log_entry) { - $log_entry['date'] = date('d.m.Y H:i', $log_entry['timestamp']); + $log_entries = LogEntry::filter($filter); + + $entries = []; + foreach ($log_entries as $entry) { + $data = $entry->toArray(); + $data['created_at'] = date_format($entry->created_at, 'd.m.Y H:i'); + $entries[] = $data; } return page_with_title(admin_log_title(), [ @@ -30,9 +36,9 @@ function admin_log() form_submit(__('Search'), 'Go') ]), table([ - 'date' => 'Time', - 'level' => 'Type', - 'message' => 'Log Entry' - ], $log_entries) + 'created_at' => 'Time', + 'level' => 'Type', + 'message' => 'Log Entry' + ], $entries) ]); } |