Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
freebsd
GitHub Repository: freebsd/phabricator
Path: blob/master/src/applications/conpherence/view/ConpherenceTransactionView.php
12256 views
1
<?php
2
3
final class ConpherenceTransactionView extends AphrontView {
4
5
private $conpherenceThread;
6
private $conpherenceTransaction;
7
private $handles;
8
private $markupEngine;
9
private $classes = array();
10
private $searchResult;
11
private $timeOnly;
12
13
public function setConpherenceThread(ConpherenceThread $t) {
14
$this->conpherenceThread = $t;
15
return $this;
16
}
17
18
private function getConpherenceThread() {
19
return $this->conpherenceThread;
20
}
21
22
public function setConpherenceTransaction(ConpherenceTransaction $tx) {
23
$this->conpherenceTransaction = $tx;
24
return $this;
25
}
26
27
private function getConpherenceTransaction() {
28
return $this->conpherenceTransaction;
29
}
30
31
public function setHandles(array $handles) {
32
assert_instances_of($handles, 'PhabricatorObjectHandle');
33
$this->handles = $handles;
34
return $this;
35
}
36
37
public function getHandles() {
38
return $this->handles;
39
}
40
41
public function setMarkupEngine(PhabricatorMarkupEngine $markup_engine) {
42
$this->markupEngine = $markup_engine;
43
return $this;
44
}
45
46
private function getMarkupEngine() {
47
return $this->markupEngine;
48
}
49
50
public function addClass($class) {
51
$this->classes[] = $class;
52
return $this;
53
}
54
55
public function setSearchResult($result) {
56
$this->searchResult = $result;
57
return $this;
58
}
59
60
public function render() {
61
$viewer = $this->getUser();
62
if (!$viewer) {
63
throw new PhutilInvalidStateException('setUser');
64
}
65
66
require_celerity_resource('conpherence-transaction-css');
67
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,
78
),
79
),
80
array(
81
phutil_tag(
82
'span',
83
array(
84
'class' => 'date',
85
),
86
phabricator_format_local_time(
87
$transaction->getDateCreated(),
88
$viewer,
89
'M jS, Y')),
90
));
91
break;
92
}
93
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();
100
101
$header = phutil_tag_div(
102
'conpherence-transaction-header grouped',
103
array($actions, $info));
104
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(),
113
),
114
),
115
array(
116
$image,
117
phutil_tag_div('conpherence-transaction-detail grouped',
118
array($header, $content)),
119
));
120
}
121
122
private function renderTransactionInfo() {
123
$viewer = $this->getUser();
124
$thread = $this->getConpherenceThread();
125
$transaction = $this->getConpherenceTransaction();
126
$info = array();
127
128
Javelin::initBehavior('phabricator-tooltips');
129
$tip = phabricator_datetime($transaction->getDateCreated(), $viewer);
130
$label = phabricator_time($transaction->getDateCreated(), $viewer);
131
$width = 360;
132
133
Javelin::initBehavior('phabricator-watch-anchor');
134
$anchor = id(new PhabricatorAnchorView())
135
->setAnchorName($transaction->getID())
136
->render();
137
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',
148
),
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,
163
),
164
),
165
$label));
166
}
167
168
return phutil_tag(
169
'span',
170
array(
171
'class' => 'conpherence-transaction-info',
172
),
173
$info);
174
}
175
176
private function renderTransactionActions() {
177
$transaction = $this->getConpherenceTransaction();
178
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;
188
}
189
190
return $actions;
191
}
192
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.');',
206
));
207
break;
208
}
209
return $image;
210
}
211
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;
232
}
233
234
$view = phutil_tag(
235
'div',
236
array(
237
'class' => $content_class,
238
),
239
$content);
240
241
return phutil_tag_div('conpherence-transaction-content', $view);
242
}
243
244
}
245
246