Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
freebsd
GitHub Repository: freebsd/phabricator
Path: blob/master/src/view/phui/PHUICurtainObjectRefView.php
12249 views
1
<?php
2
3
final class PHUICurtainObjectRefView
4
extends AphrontTagView {
5
6
private $handle;
7
private $epoch;
8
private $highlighted;
9
private $exiled;
10
private $exileNote = false;
11
12
public function setHandle(PhabricatorObjectHandle $handle) {
13
$this->handle = $handle;
14
return $this;
15
}
16
17
public function setEpoch($epoch) {
18
$this->epoch = $epoch;
19
return $this;
20
}
21
22
public function setHighlighted($highlighted) {
23
$this->highlighted = $highlighted;
24
return $this;
25
}
26
27
public function setExiled($is_exiled, $note = false) {
28
$this->exiled = $is_exiled;
29
$this->exileNote = $note;
30
return $this;
31
}
32
33
protected function getTagAttributes() {
34
$classes = array();
35
$classes[] = 'phui-curtain-object-ref-view';
36
37
if ($this->highlighted) {
38
$classes[] = 'phui-curtain-object-ref-view-highlighted';
39
}
40
41
if ($this->exiled) {
42
$classes[] = 'phui-curtain-object-ref-view-exiled';
43
}
44
45
$classes = implode(' ', $classes);
46
47
return array(
48
'class' => $classes,
49
);
50
}
51
52
protected function getTagContent() {
53
require_celerity_resource('phui-curtain-object-ref-view-css');
54
55
$viewer = $this->getViewer();
56
$handle = $this->handle;
57
58
$more_rows = array();
59
60
$epoch = $this->epoch;
61
if ($epoch !== null) {
62
$epoch_view = phabricator_dual_datetime($epoch, $viewer);
63
64
$epoch_cells = array();
65
66
$epoch_cells[] = phutil_tag(
67
'td',
68
array(
69
'class' => 'phui-curtain-object-ref-view-epoch-cell',
70
),
71
$epoch_view);
72
73
$more_rows[] = phutil_tag('tr', array(), $epoch_cells);
74
}
75
76
if ($this->exiled) {
77
if ($this->exileNote !== false) {
78
$exile_note = $this->exileNote;
79
} else {
80
$exile_note = pht('No View Permission');
81
}
82
83
$exiled_view = array(
84
id(new PHUIIconView())->setIcon('fa-eye-slash red'),
85
' ',
86
$exile_note,
87
);
88
89
$exiled_cells = array();
90
$exiled_cells[] = phutil_tag(
91
'td',
92
array(
93
'class' => 'phui-curtain-object-ref-view-exiled-cell',
94
),
95
$exiled_view);
96
97
$more_rows[] = phutil_tag('tr', array(), $exiled_cells);
98
}
99
100
$header_cells = array();
101
102
$image_view = $this->newImage();
103
104
if ($more_rows) {
105
$row_count = 1 + count($more_rows);
106
} else {
107
$row_count = null;
108
}
109
110
$header_cells[] = phutil_tag(
111
'td',
112
array(
113
'rowspan' => $row_count,
114
'class' => 'phui-curtain-object-ref-view-image-cell',
115
),
116
$image_view);
117
118
$title_view = $this->newTitle();
119
120
$header_cells[] = phutil_tag(
121
'td',
122
array(
123
'class' => 'phui-curtain-object-ref-view-title-cell',
124
),
125
$title_view);
126
127
$rows = array();
128
129
if (!$more_rows) {
130
$title_row_class = 'phui-curtain-object-ref-view-without-content';
131
} else {
132
$title_row_class = 'phui-curtain-object-ref-view-with-content';
133
}
134
135
$rows[] = phutil_tag(
136
'tr',
137
array(
138
'class' => $title_row_class,
139
),
140
$header_cells);
141
142
$body = phutil_tag(
143
'tbody',
144
array(),
145
array(
146
$rows,
147
$more_rows,
148
));
149
150
return phutil_tag('table', array(), $body);
151
}
152
153
private function newTitle() {
154
$title_view = null;
155
$handle = $this->handle;
156
157
if ($handle) {
158
$title_view = $handle->renderLink();
159
}
160
161
return $title_view;
162
}
163
164
private function newImage() {
165
$image_uri = $this->getImageURI();
166
$target_uri = $this->getTargetURI();
167
168
$icon_view = null;
169
if ($image_uri == null) {
170
$icon_view = $this->newIconView();
171
}
172
173
if ($image_uri !== null) {
174
$image_view = javelin_tag(
175
'a',
176
array(
177
'style' => sprintf('background-image: url(%s)', $image_uri),
178
'href' => $target_uri,
179
'aural' => false,
180
));
181
} else if ($icon_view !== null) {
182
$image_view = javelin_tag(
183
'a',
184
array(
185
'href' => $target_uri,
186
'class' => 'phui-curtain-object-ref-view-icon-image',
187
'aural' => false,
188
),
189
$icon_view);
190
} else {
191
$image_view = null;
192
}
193
194
return $image_view;
195
}
196
197
private function getTargetURI() {
198
$target_uri = null;
199
$handle = $this->handle;
200
201
if ($handle) {
202
$target_uri = $handle->getURI();
203
}
204
205
return $target_uri;
206
}
207
208
private function getImageURI() {
209
$image_uri = null;
210
$handle = $this->handle;
211
212
if ($handle) {
213
$image_uri = $handle->getImageURI();
214
}
215
216
return $image_uri;
217
}
218
219
private function newIconView() {
220
$handle = $this->handle;
221
222
if ($handle) {
223
$icon_view = id(new PHUIIconView())
224
->setIcon($handle->getIcon());
225
}
226
227
return $icon_view;
228
}
229
230
231
}
232
233