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

65 lines
1.3 KiB
PHP
Raw Permalink Normal View History

2019-11-03 09:20:34 -05: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-11-03 09:20:34 -05:00
use ipl\Html\BaseHtmlElement;
2019-11-03 09:20:34 -05:00
use ipl\Orm\ResultSet;
use ipl\Web\Common\BaseTarget;
2019-11-03 09:20:34 -05:00
use ipl\Web\Url;
use ipl\Web\Widget\ActionLink;
class ShowMore extends BaseHtmlElement
2019-11-03 09:20:34 -05:00
{
use BaseTarget;
protected $defaultAttributes = ['class' => 'show-more'];
protected $tag = 'div';
2023-09-08 09:17:43 -04:00
/** @var ResultSet */
2019-11-03 09:20:34 -05:00
protected $resultSet;
2023-09-08 09:17:43 -04:00
/** @var Url */
2019-11-03 09:20:34 -05:00
protected $url;
2023-09-08 09:17:43 -04:00
/** @var ?string */
protected $label;
public function __construct(ResultSet $resultSet, Url $url, string $label = null)
2019-11-03 09:20:34 -05:00
{
$this->label = $label;
2019-11-03 09:20:34 -05:00
$this->resultSet = $resultSet;
$this->url = $url;
}
public function setLabel(string $label): self
2019-11-03 09:20:34 -05:00
{
$this->label = $label;
return $this;
}
2019-11-03 09:20:34 -05:00
public function getLabel(): string
{
return $this->label ?: t('Show More');
}
public function renderUnwrapped(): string
{
if ($this->resultSet->hasMore()) {
return parent::renderUnwrapped();
}
return '';
}
2023-09-08 09:18:04 -04:00
protected function assemble(): void
{
if ($this->resultSet->hasMore()) {
$this->addHtml(new ActionLink($this->getLabel(), $this->url));
}
2019-11-03 09:20:34 -05:00
}
}