summaryrefslogtreecommitdiffstats
path: root/library/X509/Widget/Jobs.php
blob: 997e7efc550d55adc3f47020e3a081be1decc6bf (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
62
63
64
<?php

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

namespace Icinga\Module\X509\Widget;

use Icinga\Module\X509\Common\Links;
use Icinga\Module\X509\Model\X509Job;
use ipl\Html\Table;
use ipl\I18n\Translation;
use ipl\Orm\Query;
use ipl\Web\Widget\EmptyStateBar;
use ipl\Web\Widget\Link;

class Jobs extends Table
{
    use Translation;

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

    protected $defaultAttributes = [
        'class'            => 'common-table table-row-selectable',
        'data-base-target' => '_next'
    ];

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

    protected function assemble(): void
    {
        $jobs = $this->jobs->execute();
        if (! $jobs->hasResult()) {
            $this->setTag('div');
            $this->addHtml(new EmptyStateBar($this->translate('No jobs configured yet.')));

            return;
        }

        $headers = static::tr();
        $headers->addHtml(
            static::th($this->translate('Name')),
            static::th($this->translate('Author')),
            static::th($this->translate('Date Created')),
            static::th($this->translate('Date Modified'))
        );
        $this->getHeader()->addHtml($headers);

        /** @var X509Job $job */
        foreach ($jobs as $job) {
            $row = static::tr();
            $row->addHtml(
                static::td(new Link($job->name, Links::job($job))),
                static::td($job->author),
                static::td($job->ctime->format('Y-m-d H:i')),
                static::td($job->mtime->format('Y-m-d H:i'))
            );

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