*/ class CommentRenderer implements ItemRenderer { use Translation; use TicketLinks; use HostLink; use ServiceLink; /** @var bool Whether the object link for th item should be omitted */ protected $noObjectLink = false; /** @var bool Whether item's subject should be a link */ protected $noSubjectLink = false; /** * Set whether the object link for th item should be omitted * * @param bool $state * * @return $this */ public function setNoObjectLink(bool $state = true): self { $this->noObjectLink = $state; return $this; } /** * Set whether item's subject should be a link * * @param bool $state * * @return $this */ public function setNoSubjectLink(bool $state = true): self { $this->noSubjectLink = $state; return $this; } public function assembleAttributes($item, Attributes $attributes, string $layout): void { $attributes->get('class')->addValue('comment'); } public function assembleVisual($item, HtmlDocument $visual, string $layout): void { $visual->addHtml( (new Ball($layout === 'minimal' ? Ball::SIZE_BIG : Ball::SIZE_LARGE)) ->addAttributes(['class' => 'user-ball']) ->addHtml(Text::create($item->author[0])) ); } public function assembleTitle($item, HtmlDocument $title, string $layout): void { $isAck = $item->entry_type === 'ack'; $expires = $item->expire_time; $subjectText = sprintf( $isAck ? $this->translate('%s acknowledged', '..') : $this->translate('%s commented', '..'), $item->author ); $headerParts = [ new Icon(Icons::USER), $layout === 'header' || $this->noSubjectLink ? new HtmlElement('span', Attributes::create(['class' => 'subject']), Text::create($subjectText)) : new Link($subjectText, Links::comment($item), ['class' => 'subject']) ]; if ($isAck) { $label = [Text::create('ack')]; if ($item->is_persistent) { array_unshift($label, new Icon(Icons::IS_PERSISTENT)); } $headerParts[] = Text::create(' '); $headerParts[] = new HtmlElement('span', Attributes::create(['class' => 'ack-badge badge']), ...$label); } if ($expires !== null) { $headerParts[] = Text::create(' '); $headerParts[] = new HtmlElement( 'span', Attributes::create(['class' => 'ack-badge badge']), Text::create($this->translate('EXPIRES')) ); } if ($this->noObjectLink) { // pass } elseif ($item->object_type === 'host') { $headerParts[] = $this->createHostLink($item->host, true); } else { $headerParts[] = $this->createServiceLink($item->service, $item->service->host, true); } $title->addHtml(...$headerParts); } public function assembleCaption($item, HtmlDocument $caption, string $layout): void { $markdownLine = new MarkdownLine($this->createTicketLinks($item->text)); $caption->getAttributes()->add($markdownLine->getAttributes()); $caption->addFrom($markdownLine); } public function assembleExtendedInfo($item, HtmlDocument $info, string $layout): void { if ($item->expire_time) { $info->addHtml( FormattedString::create( $this->translate("expires %s"), new TimeUntil($item->expire_time->getTimestamp()) ) ); } else { $info->addHtml( FormattedString::create( $this->translate("created %s"), new TimeAgo($item->entry_time->getTimestamp()) ) ); } } public function assembleFooter($item, HtmlDocument $footer, string $layout): void { } public function assemble($item, string $name, HtmlDocument $element, string $layout): bool { return false; // no custom sections } }