summaryrefslogtreecommitdiffstats
path: root/modules-available/eventlog/pages/log.inc.php
blob: 66826b08916558d00ae606846b7350986d95d459 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
<?php

class SubPage
{

	public static function doPreprocess()
	{
		User::assertPermission('view');
		User::setLastSeenEvent(Property::getLastWarningId());
	}

	public static function doRender()
	{
		$lines = array();
		$paginate = new Paginate("SELECT logid, dateline, logtypeid, description, extra FROM eventlog ORDER BY logid DESC", 50);
		$res = $paginate->exec();
		foreach ($res as $row) {
			$row['date'] = Util::prettyTime($row['dateline']);
			$row['icon'] = self::typeToIcon($row['logtypeid']);
			$row['color'] = self::typeToColor($row['logtypeid']);
			$lines[] = $row;
		}

		$paginate->render('_page', array(
			'list' => $lines
		));
	}

	private static function typeToIcon(string $type): string
	{
		switch ($type) {
		case 'info':
			return 'ok';
		case 'warning':
			return 'exclamation-sign';
		case 'failure':
			return 'remove';
		default:
			return 'question-sign';
		}
	}

	private static function typeToColor(string $type): string
	{
		switch ($type) {
		case 'warning':
			return 'orange';
		case 'failure':
			return 'red';
		case 'info':
		default:
			return '';
		}
	}

}