Correct Aphlict websocket URI construction after PHP8 compatibility changes
[phabricator.git] / src / applications / ponder / view / PonderAnswerView.php
blob474661381c39f4ed4378fcc4429adc640632b80b
1 <?php
3 final class PonderAnswerView extends AphrontTagView {
5 private $answer;
6 private $transactions;
7 private $timeline;
8 private $handle;
10 public function setAnswer($answer) {
11 $this->answer = $answer;
12 return $this;
15 public function setTransactions($transactions) {
16 $this->transactions = $transactions;
17 return $this;
20 public function setTimeline($timeline) {
21 $this->timeline = $timeline;
22 return $this;
25 public function setHandle($handle) {
26 $this->handle = $handle;
27 return $this;
30 protected function getTagAttributes() {
31 return array(
32 'class' => 'ponder-answer-view',
36 protected function getTagContent() {
37 require_celerity_resource('ponder-view-css');
38 $answer = $this->answer;
39 $viewer = $this->getUser();
40 $status = $answer->getStatus();
41 $author_phid = $answer->getAuthorPHID();
42 $actions = $this->buildAnswerActions();
43 $handle = $this->handle;
44 $id = $answer->getID();
46 if ($status == PonderAnswerStatus::ANSWER_STATUS_HIDDEN) {
47 $can_edit = PhabricatorPolicyFilter::hasCapability(
48 $viewer,
49 $answer,
50 PhabricatorPolicyCapability::CAN_EDIT);
52 $message = array();
53 $message[] = phutil_tag(
54 'em',
55 array(),
56 pht('This answer has been hidden.'));
58 if ($can_edit) {
59 $message[] = phutil_tag(
60 'a',
61 array(
62 'href' => "/ponder/answer/edit/{$id}/",
64 pht('Edit Answer'));
66 $message = phutil_implode_html(' ', $message);
68 return id(new PHUIInfoView())
69 ->setSeverity(PHUIInfoView::SEVERITY_NODATA)
70 ->appendChild($message);
73 $action_button = id(new PHUIButtonView())
74 ->setTag('a')
75 ->setText(pht('Actions'))
76 ->setHref('#')
77 ->setIcon('fa-bars')
78 ->setDropdownMenu($actions);
80 $header_name = phutil_tag(
81 'a',
82 array(
83 'href' => $handle->getURI(),
85 $handle->getName());
87 $header = id(new PHUIHeaderView())
88 ->setUser($viewer)
89 ->setEpoch($answer->getDateModified())
90 ->setHeader($header_name)
91 ->addActionLink($action_button)
92 ->setImage($handle->getImageURI())
93 ->setImageURL($handle->getURI());
95 $content = phutil_tag(
96 'div',
97 array(
98 'class' => 'phabricator-remarkup',
100 PhabricatorMarkupEngine::renderOneObject(
101 $answer,
102 $answer->getMarkupField(),
103 $viewer));
105 $anchor = id(new PhabricatorAnchorView())
106 ->setAnchorName("A$id");
108 $content_id = celerity_generate_unique_node_id();
109 $footer = id(new PonderFooterView())
110 ->setContentID($content_id)
111 ->setCount(count($this->transactions));
113 $content = phutil_tag_div(
114 'ponder-answer-content', array($anchor, $content, $footer));
116 $answer_view = id(new PHUIObjectBoxView())
117 ->setHeader($header)
118 ->setBackground(PHUIObjectBoxView::GREY)
119 ->addClass('ponder-answer')
120 ->appendChild($content);
122 $comment_view = id(new PhabricatorApplicationTransactionCommentView())
123 ->setUser($viewer)
124 ->setObjectPHID($answer->getPHID())
125 ->setShowPreview(false)
126 ->setHeaderText(pht('Answer Comment'))
127 ->setAction("/ponder/answer/comment/{$id}/")
128 ->setSubmitButtonName(pht('Comment'));
130 $hidden_view = phutil_tag(
131 'div',
132 array(
133 'id' => $content_id,
134 'style' => 'display: none;',
136 array(
137 $this->timeline,
138 $comment_view,
141 return array(
142 $answer_view,
143 $hidden_view,
147 private function buildAnswerActions() {
148 $viewer = $this->getUser();
149 $answer = $this->answer;
150 $id = $answer->getID();
152 $can_edit = PhabricatorPolicyFilter::hasCapability(
153 $viewer,
154 $answer,
155 PhabricatorPolicyCapability::CAN_EDIT);
157 $view = id(new PhabricatorActionListView())
158 ->setUser($viewer)
159 ->setObject($answer);
161 $view->addAction(
162 id(new PhabricatorActionView())
163 ->setIcon('fa-pencil')
164 ->setName(pht('Edit Answer'))
165 ->setHref("/ponder/answer/edit/{$id}/")
166 ->setDisabled(!$can_edit)
167 ->setWorkflow(!$can_edit));
169 $view->addAction(
170 id(new PhabricatorActionView())
171 ->setIcon('fa-list')
172 ->setName(pht('View History'))
173 ->setHref("/ponder/answer/history/{$id}/"));
175 return $view;