From b18bc644404e02b57635bfcc8258e85abb141146 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sat, 13 Apr 2024 13:44:46 +0200 Subject: Adding upstream version 1.1.1. Signed-off-by: Daniel Baumann --- library/Icingadb/Widget/Detail/CommentDetail.php | 140 +++++++++++++++++++++++ 1 file changed, 140 insertions(+) create mode 100644 library/Icingadb/Widget/Detail/CommentDetail.php (limited to 'library/Icingadb/Widget/Detail/CommentDetail.php') diff --git a/library/Icingadb/Widget/Detail/CommentDetail.php b/library/Icingadb/Widget/Detail/CommentDetail.php new file mode 100644 index 0000000..5b0923e --- /dev/null +++ b/library/Icingadb/Widget/Detail/CommentDetail.php @@ -0,0 +1,140 @@ + ['object-detail', 'comment-detail']]; + + protected $tag = 'div'; + + public function __construct(Comment $comment) + { + $this->comment = $comment; + } + + protected function createComment(): array + { + return [ + Html::tag('h2', t('Comment')), + new MarkdownText($this->createTicketLinks($this->comment->text)) + ]; + } + + protected function createDetails(): array + { + $details = []; + + if (getenv('ICINGAWEB_EXPORT_FORMAT') === 'pdf') { + if ($this->comment->object_type === 'host') { + $details[] = new HorizontalKeyValue(t('Host'), [ + $this->comment->host->name, + ' ', + new StateBall($this->comment->host->state->getStateText()) + ]); + } else { + $details[] = new HorizontalKeyValue(t('Service'), Html::sprintf( + t('%s on %s', ' on '), + [$this->comment->service->name, ' ', new StateBall($this->comment->service->state->getStateText())], + $this->comment->host->name + )); + } + + $details[] = new HorizontalKeyValue(t('Author'), $this->comment->author); + $details[] = new HorizontalKeyValue( + t('Acknowledgement'), + $this->comment->entry_type === 'ack' ? t('Yes') : t('No') + ); + $details[] = new HorizontalKeyValue( + t('Persistent'), + $this->comment->is_persistent ? t('Yes') : t('No') + ); + $details[] = new HorizontalKeyValue( + t('Created'), + DateFormatter::formatDateTime($this->comment->entry_time->getTimestamp()) + ); + $details[] = new HorizontalKeyValue(t('Expires'), $this->comment->expire_time !== null + ? DateFormatter::formatDateTime($this->comment->expire_time->getTimestamp()) + : t('Never')); + } else { + if ($this->comment->expire_time !== null) { + $details[] = Html::tag( + 'p', + Html::sprintf( + $this->comment->entry_type === 'ack' + ? t('This acknowledgement expires %s.', '..') + : t('This comment expires %s.', '..'), + new TimeUntil($this->comment->expire_time->getTimestamp()) + ) + ); + } + + if ($this->comment->is_sticky) { + $details[] = Html::tag('p', t('This acknowledgement is sticky.')); + } + } + + if (! empty($details)) { + array_unshift($details, Html::tag('h2', t('Details'))); + } + + return $details; + } + + protected function createRemoveCommentForm() + { + if (getenv('ICINGAWEB_EXPORT_FORMAT') === 'pdf') { + return null; + } + + $action = Links::commentsDelete(); + $action->setFilter(Filter::equal('name', $this->comment->name)); + + return (new DeleteCommentForm()) + ->setObjects([$this->comment]) + ->populate(['redirect' => '__BACK__']) + ->setAction($action->getAbsoluteUrl()); + } + + protected function assemble() + { + $this->add($this->createComment()); + + $details = $this->createDetails(); + + if (! empty($details)) { + $this->add($details); + } + + if ( + $this->isGrantedOn( + 'icingadb/command/comment/delete', + $this->comment->{$this->comment->object_type} + ) + ) { + $this->add($this->createRemoveCommentForm()); + } + } +} -- cgit v1.2.3