File: RequirementsRenderer.php

package info (click to toggle)
icingaweb2 2.12.6-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 15,124 kB
  • sloc: php: 73,980; javascript: 5,009; sql: 333; xml: 75; sh: 72; makefile: 5
file content (67 lines) | stat: -rw-r--r-- 2,052 bytes parent folder | download | duplicates (2)
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
65
66
67
<?php
/* Icinga Web 2 | (c) 2015 Icinga Development Team | GPLv2+ */

namespace Icinga\Module\Setup;

use RecursiveIteratorIterator;

class RequirementsRenderer extends RecursiveIteratorIterator
{
    protected $tags;

    public function beginIteration(): void
    {
        $this->tags[] = '<ul class="requirements">';
    }

    public function endIteration(): void
    {
        $this->tags[] = '</ul>';
    }

    public function beginChildren(): void
    {
        $this->tags[] = '<li>';
        /** @var RequirementSet $currentSet */
        $currentSet = $this->getSubIterator();
        $state = $currentSet->getState() ? 'fulfilled' : ($currentSet->isOptional() ? 'not-available' : 'missing');
        $this->tags[] = '<ul class="set-state ' . $state . '">';
    }

    public function endChildren(): void
    {
        $this->tags[] = '</ul>';
        $this->tags[] = '</li>';
    }

    public function render()
    {
        foreach ($this as $requirement) {
            $this->tags[] = '<li class="clearfix">';
            $this->tags[] = '<div class="title"><h2>' . $requirement->getTitle() . '</h2></div>';
            $this->tags[] = '<div class="description">';
            $descriptions = $requirement->getDescriptions();
            if (count($descriptions) > 1) {
                $this->tags[] = '<ul>';
                foreach ($descriptions as $d) {
                    $this->tags[] = '<li>' . $d . '</li>';
                }
                $this->tags[] = '</ul>';
            } elseif (! empty($descriptions)) {
                $this->tags[] = $descriptions[0];
            }
            $this->tags[] = '</div>';
            $this->tags[] = '<div class="state ' . ($requirement->getState() ? 'fulfilled' : (
                $requirement->isOptional() ? 'not-available' : 'missing'
            )) . '">' . $requirement->getStateText() . '</div>';
            $this->tags[] = '</li>';
        }

        return implode("\n", $this->tags);
    }

    public function __toString()
    {
        return $this->render();
    }
}