summaryrefslogtreecommitdiffstats
path: root/library/X509/Widget/JobDetails.php
blob: c1e3843272e3a2731cb4490e3b1a337541f68df9 (plain)
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
57
58
59
60
61
<?php

/* Icinga Web 2 X.509 Module | (c) 2023 Icinga GmbH | GPLv2 */

namespace Icinga\Module\X509\Widget;

use Icinga\Module\X509\Model\X509JobRun;
use ipl\Html\Table;
use ipl\I18n\Translation;
use ipl\Orm\Query;
use ipl\Web\Widget\EmptyStateBar;

class JobDetails extends Table
{
    use Translation;

    protected $defaultAttributes = ['class' => 'common-table'];

    /** @var Query */
    protected $runs;

    public function __construct(Query $runs)
    {
        $this->runs = $runs;
    }

    protected function assemble(): void
    {
        /** @var X509JobRun $run */
        foreach ($this->runs as $run) {
            $row = static::tr();
            $row->addHtml(
                static::td($run->job->name),
                static::td($run->schedule->name ?: $this->translate('N/A')),
                static::td((string) $run->total_targets),
                static::td((string) $run->finished_targets),
                static::td($run->start_time->format('Y-m-d H:i')),
                static::td($run->end_time ? $run->end_time->format('Y-m-d H:i') : 'N/A')
            );

            $this->addHtml($row);
        }

        if ($this->isEmpty()) {
            $this->setTag('div');
            $this->addHtml(new EmptyStateBar($this->translate('Job never run.')));
        } else {
            $row = static::tr();
            $row->addHtml(
                static::th($this->translate('Name')),
                static::th($this->translate('Schedule Name')),
                static::th($this->translate('Total')),
                static::th($this->translate('Scanned')),
                static::th($this->translate('Started')),
                static::th($this->translate('Finished'))
            );

            $this->getHeader()->addHtml($row);
        }
    }
}