icingadb-web/library/Icingadb/Common/TicketLinks.php

56 lines
1.2 KiB
PHP
Raw Permalink Normal View History

2022-08-29 04:50:28 -04:00
<?php
/* Icinga DB Web | (c) 2022 Icinga GmbH | GPLv2 */
namespace Icinga\Module\Icingadb\Common;
use Icinga\Application\Hook;
use Icinga\Application\Hook\TicketHook;
2022-08-29 04:50:28 -04:00
trait TicketLinks
{
/** @var bool Whether the ticket link is disabled */
protected $ticketLinkDisabled = false;
2022-08-29 04:50:28 -04:00
/**
* Set whether the ticket link is disabled
2022-08-29 04:50:28 -04:00
*
* @param bool $state
*
* @return $this
*/
public function setTicketLinkDisabled(bool $state = true): self
2022-08-29 04:50:28 -04:00
{
$this->ticketLinkDisabled = $state;
2022-08-29 04:50:28 -04:00
return $this;
}
/**
* Get whether the ticket link is disabled
2022-08-29 04:50:28 -04:00
*
* @return bool
*/
public function isTicketLinkDisabled(): bool
2022-08-29 04:50:28 -04:00
{
return $this->ticketLinkDisabled;
2022-08-29 04:50:28 -04:00
}
/**
* Get whether list items should render host and service links
*
* @return string
*/
public function createTicketLinks($text): string
{
if ($this->isTicketLinkDisabled() || ! Hook::has('ticket')) {
return $text ?? '';
2022-08-29 04:50:28 -04:00
}
/** @var TicketHook $tickets */
$tickets = Hook::first('ticket');
return $tickets->createLinks($text);
2022-08-29 04:50:28 -04:00
}
}