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
|
|
|
|
2019-12-13 10:15:58 -05:00
|
|
|
use ipl\Html\BaseHtmlElement;
|
2019-11-03 09:20:34 -05:00
|
|
|
use ipl\Orm\ResultSet;
|
2021-08-02 10:02:05 -04:00
|
|
|
use ipl\Web\Common\BaseTarget;
|
2019-11-03 09:20:34 -05:00
|
|
|
use ipl\Web\Url;
|
|
|
|
|
use ipl\Web\Widget\ActionLink;
|
|
|
|
|
|
2019-12-13 10:15:58 -05:00
|
|
|
class ShowMore extends BaseHtmlElement
|
2019-11-03 09:20:34 -05:00
|
|
|
{
|
2021-08-02 10:02:05 -04:00
|
|
|
use BaseTarget;
|
|
|
|
|
|
2019-12-13 10:15:58 -05:00
|
|
|
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 */
|
2019-12-13 10:15:58 -05:00
|
|
|
protected $label;
|
|
|
|
|
|
2021-09-22 04:21:15 -04:00
|
|
|
public function __construct(ResultSet $resultSet, Url $url, string $label = null)
|
2019-11-03 09:20:34 -05:00
|
|
|
{
|
2020-01-10 03:28:08 -05:00
|
|
|
$this->label = $label;
|
2019-11-03 09:20:34 -05:00
|
|
|
$this->resultSet = $resultSet;
|
|
|
|
|
$this->url = $url;
|
|
|
|
|
}
|
|
|
|
|
|
2021-09-22 04:21:15 -04:00
|
|
|
public function setLabel(string $label): self
|
2019-11-03 09:20:34 -05:00
|
|
|
{
|
2019-12-13 10:15:58 -05:00
|
|
|
$this->label = $label;
|
|
|
|
|
|
|
|
|
|
return $this;
|
|
|
|
|
}
|
2019-11-03 09:20:34 -05:00
|
|
|
|
2021-09-22 04:21:15 -04:00
|
|
|
public function getLabel(): string
|
2019-12-13 10:15:58 -05:00
|
|
|
{
|
2020-04-17 12:41:33 -04:00
|
|
|
return $this->label ?: t('Show More');
|
2019-12-13 10:15:58 -05:00
|
|
|
}
|
|
|
|
|
|
2021-09-22 04:21:15 -04:00
|
|
|
public function renderUnwrapped(): string
|
2021-08-03 03:31:49 -04:00
|
|
|
{
|
|
|
|
|
if ($this->resultSet->hasMore()) {
|
|
|
|
|
return parent::renderUnwrapped();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return '';
|
|
|
|
|
}
|
|
|
|
|
|
2023-09-08 09:18:04 -04:00
|
|
|
protected function assemble(): void
|
2019-12-13 10:15:58 -05:00
|
|
|
{
|
|
|
|
|
if ($this->resultSet->hasMore()) {
|
2023-09-08 09:18:27 -04:00
|
|
|
$this->addHtml(new ActionLink($this->getLabel(), $this->url));
|
2019-12-13 10:15:58 -05:00
|
|
|
}
|
2019-11-03 09:20:34 -05:00
|
|
|
}
|
|
|
|
|
}
|