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;
|
2025-03-21 03:52:50 -04:00
|
|
|
use Icinga\Application\Hook\TicketHook;
|
2022-08-29 04:50:28 -04:00
|
|
|
|
|
|
|
|
trait TicketLinks
|
|
|
|
|
{
|
2025-03-26 11:15:43 -04:00
|
|
|
/** @var bool Whether the ticket link is disabled */
|
|
|
|
|
protected $ticketLinkDisabled = false;
|
2022-08-29 04:50:28 -04:00
|
|
|
|
|
|
|
|
/**
|
2025-03-26 11:15:43 -04:00
|
|
|
* Set whether the ticket link is disabled
|
2022-08-29 04:50:28 -04:00
|
|
|
*
|
|
|
|
|
* @param bool $state
|
|
|
|
|
*
|
|
|
|
|
* @return $this
|
|
|
|
|
*/
|
2025-03-26 11:15:43 -04:00
|
|
|
public function setTicketLinkDisabled(bool $state = true): self
|
2022-08-29 04:50:28 -04:00
|
|
|
{
|
2025-03-26 11:15:43 -04:00
|
|
|
$this->ticketLinkDisabled = $state;
|
2022-08-29 04:50:28 -04:00
|
|
|
|
|
|
|
|
return $this;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2025-03-26 11:15:43 -04:00
|
|
|
* Get whether the ticket link is disabled
|
2022-08-29 04:50:28 -04:00
|
|
|
*
|
|
|
|
|
* @return bool
|
|
|
|
|
*/
|
2025-03-26 11:15:43 -04:00
|
|
|
public function isTicketLinkDisabled(): bool
|
2022-08-29 04:50:28 -04:00
|
|
|
{
|
2025-03-26 11:15:43 -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
|
|
|
|
|
{
|
2025-03-26 11:15:43 -04:00
|
|
|
if ($this->isTicketLinkDisabled() || ! Hook::has('ticket')) {
|
|
|
|
|
return $text ?? '';
|
2022-08-29 04:50:28 -04:00
|
|
|
}
|
|
|
|
|
|
2025-03-26 11:15:43 -04:00
|
|
|
/** @var TicketHook $tickets */
|
|
|
|
|
$tickets = Hook::first('ticket');
|
|
|
|
|
|
|
|
|
|
return $tickets->createLinks($text);
|
2022-08-29 04:50:28 -04:00
|
|
|
}
|
|
|
|
|
}
|