mirror of
https://github.com/Icinga/icingaweb2.git
synced 2026-04-06 01:35:50 -04:00
Add SPDX license headers and mark source files as GPL-3.0-or-later to preserve the option to relicense under later GPL versions.
69 lines
2.1 KiB
PHP
69 lines
2.1 KiB
PHP
<?php
|
|
|
|
// SPDX-FileCopyrightText: 2018 Icinga GmbH <https://icinga.com>
|
|
// SPDX-License-Identifier: GPL-3.0-or-later
|
|
|
|
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();
|
|
}
|
|
}
|