Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
freebsd
GitHub Repository: freebsd/phabricator
Path: blob/master/src/applications/calendar/storage/PhabricatorCalendarEventInvitee.php
12253 views
1
<?php
2
3
final class PhabricatorCalendarEventInvitee extends PhabricatorCalendarDAO
4
implements PhabricatorPolicyInterface {
5
6
protected $eventPHID;
7
protected $inviteePHID;
8
protected $inviterPHID;
9
protected $status;
10
protected $availability = self::AVAILABILITY_DEFAULT;
11
12
const STATUS_INVITED = 'invited';
13
const STATUS_ATTENDING = 'attending';
14
const STATUS_DECLINED = 'declined';
15
const STATUS_UNINVITED = 'uninvited';
16
17
const AVAILABILITY_DEFAULT = 'default';
18
const AVAILABILITY_AVAILABLE = 'available';
19
const AVAILABILITY_BUSY = 'busy';
20
const AVAILABILITY_AWAY = 'away';
21
22
public static function initializeNewCalendarEventInvitee(
23
PhabricatorUser $actor, $event) {
24
return id(new PhabricatorCalendarEventInvitee())
25
->setInviterPHID($actor->getPHID())
26
->setStatus(self::STATUS_INVITED)
27
->setEventPHID($event->getPHID());
28
}
29
30
protected function getConfiguration() {
31
return array(
32
self::CONFIG_COLUMN_SCHEMA => array(
33
'status' => 'text64',
34
'availability' => 'text64',
35
),
36
self::CONFIG_KEY_SCHEMA => array(
37
'key_event' => array(
38
'columns' => array('eventPHID', 'inviteePHID'),
39
'unique' => true,
40
),
41
'key_invitee' => array(
42
'columns' => array('inviteePHID'),
43
),
44
),
45
) + parent::getConfiguration();
46
}
47
48
public function isAttending() {
49
return ($this->getStatus() == self::STATUS_ATTENDING);
50
}
51
52
public function isUninvited() {
53
if ($this->getStatus() == self::STATUS_UNINVITED) {
54
return true;
55
} else {
56
return false;
57
}
58
}
59
60
public function getDisplayAvailability(PhabricatorCalendarEvent $event) {
61
switch ($this->getAvailability()) {
62
case self::AVAILABILITY_DEFAULT:
63
case self::AVAILABILITY_BUSY:
64
return self::AVAILABILITY_BUSY;
65
case self::AVAILABILITY_AWAY:
66
return self::AVAILABILITY_AWAY;
67
default:
68
return null;
69
}
70
}
71
72
public static function getAvailabilityMap() {
73
return array(
74
self::AVAILABILITY_AVAILABLE => array(
75
'color' => 'green',
76
'name' => pht('Available'),
77
),
78
self::AVAILABILITY_BUSY => array(
79
'color' => 'orange',
80
'name' => pht('Busy'),
81
),
82
self::AVAILABILITY_AWAY => array(
83
'color' => 'red',
84
'name' => pht('Away'),
85
),
86
);
87
}
88
89
public static function getAvailabilitySpec($const) {
90
return idx(self::getAvailabilityMap(), $const, array());
91
}
92
93
public static function getAvailabilityName($const) {
94
$spec = self::getAvailabilitySpec($const);
95
return idx($spec, 'name', $const);
96
}
97
98
public static function getAvailabilityColor($const) {
99
$spec = self::getAvailabilitySpec($const);
100
return idx($spec, 'color', 'indigo');
101
}
102
103
104
/* -( PhabricatorPolicyInterface )----------------------------------------- */
105
106
107
public function getCapabilities() {
108
return array(
109
PhabricatorPolicyCapability::CAN_VIEW,
110
);
111
}
112
113
public function getPolicy($capability) {
114
switch ($capability) {
115
case PhabricatorPolicyCapability::CAN_VIEW:
116
return PhabricatorPolicies::getMostOpenPolicy();
117
}
118
}
119
120
public function hasAutomaticCapability($capability, PhabricatorUser $viewer) {
121
return false;
122
}
123
124
}
125
126