Remove all "FileHasObject" edge reads and writes
[phabricator.git] / src / applications / conpherence / view / ConpherenceTransactionView.php
blobd976fb604faa600a7c429eed666f28d9465e6c48
1 <?php
3 final class ConpherenceTransactionView extends AphrontView {
5 private $conpherenceThread;
6 private $conpherenceTransaction;
7 private $handles;
8 private $markupEngine;
9 private $classes = array();
10 private $searchResult;
11 private $timeOnly;
13 public function setConpherenceThread(ConpherenceThread $t) {
14 $this->conpherenceThread = $t;
15 return $this;
18 private function getConpherenceThread() {
19 return $this->conpherenceThread;
22 public function setConpherenceTransaction(ConpherenceTransaction $tx) {
23 $this->conpherenceTransaction = $tx;
24 return $this;
27 private function getConpherenceTransaction() {
28 return $this->conpherenceTransaction;
31 public function setHandles(array $handles) {
32 assert_instances_of($handles, 'PhabricatorObjectHandle');
33 $this->handles = $handles;
34 return $this;
37 public function getHandles() {
38 return $this->handles;
41 public function setMarkupEngine(PhabricatorMarkupEngine $markup_engine) {
42 $this->markupEngine = $markup_engine;
43 return $this;
46 private function getMarkupEngine() {
47 return $this->markupEngine;
50 public function addClass($class) {
51 $this->classes[] = $class;
52 return $this;
55 public function setSearchResult($result) {
56 $this->searchResult = $result;
57 return $this;
60 public function render() {
61 $viewer = $this->getUser();
62 if (!$viewer) {
63 throw new PhutilInvalidStateException('setUser');
66 require_celerity_resource('conpherence-transaction-css');
68 $transaction = $this->getConpherenceTransaction();
69 switch ($transaction->getTransactionType()) {
70 case ConpherenceThreadDateMarkerTransaction::TRANSACTIONTYPE:
71 return javelin_tag(
72 'div',
73 array(
74 'class' => 'conpherence-transaction-view date-marker',
75 'sigil' => 'conpherence-transaction-view',
76 'meta' => array(
77 'id' => $transaction->getID() + 0.5,
80 array(
81 phutil_tag(
82 'span',
83 array(
84 'class' => 'date',
86 phabricator_format_local_time(
87 $transaction->getDateCreated(),
88 $viewer,
89 'M jS, Y')),
90 ));
91 break;
94 $info = $this->renderTransactionInfo();
95 $actions = $this->renderTransactionActions();
96 $image = $this->renderTransactionImage();
97 $content = $this->renderTransactionContent();
98 $classes = implode(' ', $this->classes);
99 $transaction_dom_id = 'anchor-'.$transaction->getID();
101 $header = phutil_tag_div(
102 'conpherence-transaction-header grouped',
103 array($actions, $info));
105 return javelin_tag(
106 'div',
107 array(
108 'class' => 'conpherence-transaction-view '.$classes,
109 'id' => $transaction_dom_id,
110 'sigil' => 'conpherence-transaction-view',
111 'meta' => array(
112 'id' => $transaction->getID(),
115 array(
116 $image,
117 phutil_tag_div('conpherence-transaction-detail grouped',
118 array($header, $content)),
122 private function renderTransactionInfo() {
123 $viewer = $this->getUser();
124 $thread = $this->getConpherenceThread();
125 $transaction = $this->getConpherenceTransaction();
126 $info = array();
128 Javelin::initBehavior('phabricator-tooltips');
129 $tip = phabricator_datetime($transaction->getDateCreated(), $viewer);
130 $label = phabricator_time($transaction->getDateCreated(), $viewer);
131 $width = 360;
133 Javelin::initBehavior('phabricator-watch-anchor');
134 $anchor = id(new PhabricatorAnchorView())
135 ->setAnchorName($transaction->getID())
136 ->render();
138 if ($this->searchResult) {
139 $uri = $thread->getMonogram();
140 $info[] = hsprintf(
141 '%s',
142 javelin_tag(
143 'a',
144 array(
145 'href' => '/'.$uri.'#'.$transaction->getID(),
146 'class' => 'transaction-date',
147 'sigil' => 'conpherence-search-result-jump',
149 $tip));
150 } else {
151 $info[] = hsprintf(
152 '%s%s',
153 $anchor,
154 javelin_tag(
155 'a',
156 array(
157 'href' => '#'.$transaction->getID(),
158 'class' => 'transaction-date anchor-link',
159 'sigil' => 'has-tooltip',
160 'meta' => array(
161 'tip' => $tip,
162 'size' => $width,
165 $label));
168 return phutil_tag(
169 'span',
170 array(
171 'class' => 'conpherence-transaction-info',
173 $info);
176 private function renderTransactionActions() {
177 $transaction = $this->getConpherenceTransaction();
179 switch ($transaction->getTransactionType()) {
180 case PhabricatorTransactions::TYPE_COMMENT:
181 $handles = $this->getHandles();
182 $author = $handles[$transaction->getAuthorPHID()];
183 $actions = array($author->renderLink());
184 break;
185 default:
186 $actions = null;
187 break;
190 return $actions;
193 private function renderTransactionImage() {
194 $image = null;
195 $transaction = $this->getConpherenceTransaction();
196 switch ($transaction->getTransactionType()) {
197 case PhabricatorTransactions::TYPE_COMMENT:
198 $handles = $this->getHandles();
199 $author = $handles[$transaction->getAuthorPHID()];
200 $image_uri = $author->getImageURI();
201 $image = phutil_tag(
202 'span',
203 array(
204 'class' => 'conpherence-transaction-image',
205 'style' => 'background-image: url('.$image_uri.');',
207 break;
209 return $image;
212 private function renderTransactionContent() {
213 $transaction = $this->getConpherenceTransaction();
214 $content = null;
215 $content_class = null;
216 $content = null;
217 $handles = $this->getHandles();
218 switch ($transaction->getTransactionType()) {
219 case PhabricatorTransactions::TYPE_COMMENT:
220 $this->addClass('conpherence-comment');
221 $author = $handles[$transaction->getAuthorPHID()];
222 $comment = $transaction->getComment();
223 $content = $this->getMarkupEngine()->getOutput(
224 $comment,
225 PhabricatorApplicationTransactionComment::MARKUP_FIELD_COMMENT);
226 $content_class = 'conpherence-message';
227 break;
228 default:
229 $content = $transaction->getTitle();
230 $this->addClass('conpherence-edited');
231 break;
234 $view = phutil_tag(
235 'div',
236 array(
237 'class' => $content_class,
239 $content);
241 return phutil_tag_div('conpherence-transaction-content', $view);