icingadb-web/library/Icingadb/Widget/CheckAttempt.php

56 lines
1.4 KiB
PHP
Raw Permalink Normal View History

2019-09-09 08:45:45 -04:00
<?php
2020-03-13 03:38:01 -04:00
/* Icinga DB Web | (c) 2020 Icinga GmbH | GPLv2 */
2019-11-04 19:07:30 -05:00
namespace Icinga\Module\Icingadb\Widget;
2019-09-09 08:45:45 -04:00
use ipl\Html\BaseHtmlElement;
use ipl\Html\FormattedString;
use ipl\Web\Widget\Ball;
2019-09-09 08:45:45 -04:00
/**
* Visually represents the check attempts taken out of max check attempts.
*/
class CheckAttempt extends BaseHtmlElement
{
protected $tag = 'div';
protected $defaultAttributes = ['class' => 'check-attempt'];
/** @var int Current attempt */
protected $attempt;
/** @var int Max check attempts */
protected $maxAttempts;
/**
* Create a new check attempt widget
*
* @param int $attempt Current check attempt
* @param int $maxAttempts Max check attempts
*/
public function __construct(int $attempt, int $maxAttempts)
2019-09-09 08:45:45 -04:00
{
$this->attempt = $attempt;
$this->maxAttempts = $maxAttempts;
}
protected function assemble()
{
if ($this->attempt == $this->maxAttempts) {
return;
}
2019-09-09 08:45:45 -04:00
if ($this->maxAttempts > 5) {
$this->add(FormattedString::create('%d/%d', $this->attempt, $this->maxAttempts));
2019-09-09 08:45:45 -04:00
} else {
for ($i = 0; $i < $this->attempt; ++$i) {
$this->add(new Ball(Ball::SIZE_SMALL));
2019-09-09 08:45:45 -04:00
}
for ($i = $this->attempt; $i < $this->maxAttempts; ++$i) {
$this->add(new Ball(Ball::SIZE_TINY));
2019-09-09 08:45:45 -04:00
}
}
}
}