Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
freebsd
GitHub Repository: freebsd/phabricator
Path: blob/master/src/applications/calendar/view/PHUIUserAvailabilityView.php
12256 views
1
<?php
2
3
final class PHUIUserAvailabilityView
4
extends AphrontTagView {
5
6
private $user;
7
8
public function setAvailableUser(PhabricatorUser $user) {
9
$this->user = $user;
10
return $this;
11
}
12
13
public function getAvailableUser() {
14
return $this->user;
15
}
16
17
protected function getTagContent() {
18
$viewer = $this->getViewer();
19
$user = $this->getAvailableUser();
20
21
$until = $user->getAwayUntil();
22
if (!$until) {
23
return pht('Available');
24
}
25
26
$const = $user->getDisplayAvailability();
27
$name = PhabricatorCalendarEventInvitee::getAvailabilityName($const);
28
$color = PhabricatorCalendarEventInvitee::getAvailabilityColor($const);
29
30
$away_tag = id(new PHUITagView())
31
->setType(PHUITagView::TYPE_SHADE)
32
->setColor($color)
33
->setName($name)
34
->setDotColor($color);
35
36
$now = PhabricatorTime::getNow();
37
38
// Try to load the event handle. If it's invalid or the user can't see it,
39
// we'll just render a generic message.
40
$object_phid = $user->getAvailabilityEventPHID();
41
$handle = null;
42
if ($object_phid) {
43
$handles = $viewer->loadHandles(array($object_phid));
44
$handle = $handles[$object_phid];
45
if (!$handle->isComplete() || $handle->getPolicyFiltered()) {
46
$handle = null;
47
}
48
}
49
50
switch ($const) {
51
case PhabricatorCalendarEventInvitee::AVAILABILITY_AWAY:
52
if ($handle) {
53
$description = pht(
54
'Away at %s until %s.',
55
$handle->renderLink(),
56
$viewer->formatShortDateTime($until, $now));
57
} else {
58
$description = pht(
59
'Away until %s.',
60
$viewer->formatShortDateTime($until, $now));
61
}
62
break;
63
case PhabricatorCalendarEventInvitee::AVAILABILITY_BUSY:
64
default:
65
if ($handle) {
66
$description = pht(
67
'Busy at %s until %s.',
68
$handle->renderLink(),
69
$viewer->formatShortDateTime($until, $now));
70
} else {
71
$description = pht(
72
'Busy until %s.',
73
$viewer->formatShortDateTime($until, $now));
74
}
75
break;
76
}
77
78
return array(
79
$away_tag,
80
' ',
81
$description,
82
);
83
}
84
85
}
86
87