Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
freebsd
GitHub Repository: freebsd/phabricator
Path: blob/master/src/applications/people/view/PhabricatorUserCardView.php
12256 views
1
<?php
2
3
final class PhabricatorUserCardView extends AphrontTagView {
4
5
private $profile;
6
private $viewer;
7
private $tag;
8
private $isExiled;
9
10
public function setProfile(PhabricatorUser $profile) {
11
$this->profile = $profile;
12
return $this;
13
}
14
15
public function setViewer(PhabricatorUser $viewer) {
16
$this->viewer = $viewer;
17
return $this;
18
}
19
20
public function setTag($tag) {
21
$this->tag = $tag;
22
return $this;
23
}
24
25
protected function getTagName() {
26
if ($this->tag) {
27
return $this->tag;
28
}
29
return 'div';
30
}
31
32
protected function getTagAttributes() {
33
$classes = array();
34
$classes[] = 'project-card-view';
35
$classes[] = 'people-card-view';
36
37
if ($this->profile->getIsDisabled()) {
38
$classes[] = 'project-card-disabled';
39
}
40
41
return array(
42
'class' => implode(' ', $classes),
43
);
44
}
45
46
public function setIsExiled($is_exiled) {
47
$this->isExiled = $is_exiled;
48
return $this;
49
}
50
51
public function getIsExiled() {
52
return $this->isExiled;
53
}
54
55
protected function getTagContent() {
56
57
$user = $this->profile;
58
$profile = $user->loadUserProfile();
59
$picture = $user->getProfileImageURI();
60
$viewer = $this->viewer;
61
62
require_celerity_resource('project-card-view-css');
63
64
// We don't have a ton of room on the hovercard, so we're trying to show
65
// the most important tag. Users can click through to the profile to get
66
// more details.
67
68
$classes = array();
69
if ($user->getIsDisabled()) {
70
$tag_icon = 'fa-ban';
71
$tag_title = pht('Disabled');
72
$tag_shade = PHUITagView::COLOR_RED;
73
$classes[] = 'phui-image-disabled';
74
} else if (!$user->getIsApproved()) {
75
$tag_icon = 'fa-ban';
76
$tag_title = pht('Unapproved Account');
77
$tag_shade = PHUITagView::COLOR_RED;
78
} else if (!$user->getIsEmailVerified()) {
79
$tag_icon = 'fa-envelope';
80
$tag_title = pht('Email Not Verified');
81
$tag_shade = PHUITagView::COLOR_VIOLET;
82
} else if ($user->getIsAdmin()) {
83
$tag_icon = 'fa-star';
84
$tag_title = pht('Administrator');
85
$tag_shade = PHUITagView::COLOR_INDIGO;
86
} else {
87
$tag_icon = PhabricatorPeopleIconSet::getIconIcon($profile->getIcon());
88
$tag_title = $profile->getDisplayTitle();
89
$tag_shade = null;
90
}
91
92
$tag = id(new PHUITagView())
93
->setIcon($tag_icon)
94
->setName($tag_title)
95
->setType(PHUITagView::TYPE_SHADE);
96
97
if ($tag_shade !== null) {
98
$tag->setColor($tag_shade);
99
}
100
101
$body = array();
102
103
/* TODO: Replace with Conpherence Availability if we ship it */
104
$body[] = $this->addItem(
105
'fa-user-plus',
106
phabricator_date($user->getDateCreated(), $viewer));
107
108
$has_calendar = PhabricatorApplication::isClassInstalledForViewer(
109
'PhabricatorCalendarApplication',
110
$viewer);
111
if ($has_calendar) {
112
if (!$user->getIsDisabled()) {
113
$body[] = $this->addItem(
114
'fa-calendar-o',
115
id(new PHUIUserAvailabilityView())
116
->setViewer($viewer)
117
->setAvailableUser($user));
118
}
119
}
120
121
if ($this->getIsExiled()) {
122
$body[] = $this->addItem(
123
'fa-eye-slash red',
124
pht('This user can not see this object.'),
125
array(
126
'project-card-item-exiled',
127
));
128
}
129
130
$classes[] = 'project-card-image';
131
$image = phutil_tag(
132
'img',
133
array(
134
'src' => $picture,
135
'class' => implode(' ', $classes),
136
));
137
138
$href = urisprintf(
139
'/p/%s/',
140
$user->getUsername());
141
142
$image = phutil_tag(
143
'a',
144
array(
145
'href' => $href,
146
'class' => 'project-card-image-href',
147
),
148
$image);
149
150
$name = phutil_tag_div('project-card-name',
151
$user->getRealname());
152
$username = phutil_tag_div('project-card-username',
153
'@'.$user->getUsername());
154
$tag = phutil_tag_div('phui-header-subheader',
155
$tag);
156
157
$header = phutil_tag(
158
'div',
159
array(
160
'class' => 'project-card-header',
161
),
162
array(
163
$name,
164
$username,
165
$tag,
166
$body,
167
));
168
169
$card = phutil_tag(
170
'div',
171
array(
172
'class' => 'project-card-inner',
173
),
174
array(
175
$header,
176
$image,
177
));
178
179
return $card;
180
}
181
182
private function addItem($icon, $value, $classes = array()) {
183
$classes[] = 'project-card-item';
184
185
$icon = id(new PHUIIconView())
186
->addClass('project-card-item-icon')
187
->setIcon($icon);
188
189
$text = phutil_tag(
190
'span',
191
array(
192
'class' => 'project-card-item-text',
193
),
194
$value);
195
196
return phutil_tag(
197
'div',
198
array(
199
'class' => implode(' ', $classes),
200
),
201
array($icon, $text));
202
}
203
204
}
205
206