1<?php
2$addLink = false;
3if ($this->hasPermission('monitoring/command/comment/add')) {
4    /** @var \Icinga\Module\Monitoring\Object\MonitoredObject $object */
5    if ($object->getType() === $object::TYPE_HOST) {
6        $addLink = $this->qlink(
7            $this->translate('Add comment'),
8            'monitoring/host/add-comment',
9            array('host' => $object->getName()),
10            array(
11                'class'             => 'action-link',
12                'data-base-target'  => '_self',
13                'icon'              => 'comment-empty',
14                'title'             => $this->translate('Add a new comment to this host')
15            )
16        );
17    } else {
18        $addLink = $this->qlink(
19            $this->translate('Add comment'),
20            'monitoring/service/add-comment',
21            array('host' => $object->getHost()->getName(), 'service' => $object->getName()),
22            array(
23                'class'             => 'action-link',
24                'data-base-target'  => '_self',
25                'icon'              => 'comment-empty',
26                'title'             => $this->translate('Add a new comment to this service')
27            )
28        );
29    }
30}
31if (empty($object->comments) && ! $addLink) {
32    return;
33}
34?>
35<tr>
36    <th><?php
37    echo $this->translate('Comments');
38    if (! empty($object->comments) && $addLink) {
39        echo '<br>' . $addLink;
40    }
41    ?></th>
42    <td data-base-target="_self">
43    <?php if (empty($object->comments)):
44        echo $addLink;
45    else: ?>
46        <dl class="comment-list">
47        <?php foreach ($object->comments as $comment): ?>
48            <dt>
49                <?= $this->escape($comment->author) ?>
50                <span class="comment-time">
51                    <?= $this->translate('commented') ?>
52                    <?= $this->timeAgo($comment->timestamp) ?>
53                </span>
54                <?= $comment->persistent ? $this->icon('attach', 'This comment is persistent.') : '' ?>
55                <?php if (isset($delCommentForm)) {
56                    // Form is unset if the current user lacks the respective permission
57                    $deleteButton = clone($delCommentForm);
58                    /** @var \Icinga\Module\Monitoring\Forms\Command\Object\DeleteCommentCommandForm $deleteButton */
59                    $deleteButton->setAttrib('class', $deleteButton->getAttrib('class') . ' remove-action');
60                    $deleteButton->populate(
61                        array(
62                            'comment_id'            => $comment->id,
63                            'comment_is_service'    => isset($comment->service_description),
64                            'comment_name'          => $comment->name
65                        )
66                    );
67                    echo $deleteButton;
68                } ?>
69            </dt>
70            <dd>
71                <?= $this->nl2br($this->createTicketLinks($this->markdown($comment->comment))) ?>
72            </dd>
73        <?php endforeach ?>
74        </dl>
75    <?php endif ?>
76    </td>
77</tr>
78