Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
freebsd
GitHub Repository: freebsd/phabricator
Path: blob/master/src/applications/almanac/constants/AlmanacDeviceStatus.php
12256 views
1
<?php
2
3
final class AlmanacDeviceStatus
4
extends Phobject {
5
6
const ACTIVE = 'active';
7
const DISABLED = 'disabled';
8
9
private $value;
10
11
public static function newStatusFromValue($value) {
12
$status = new self();
13
$status->value = $value;
14
return $status;
15
}
16
17
public function getValue() {
18
return $this->value;
19
}
20
21
public function getName() {
22
$name = $this->getDeviceStatusProperty('name');
23
24
if ($name === null) {
25
$name = pht('Unknown Almanac Device Status ("%s")', $this->getValue());
26
}
27
28
return $name;
29
}
30
31
public function getIconIcon() {
32
return $this->getDeviceStatusProperty('icon.icon');
33
}
34
35
public function getIconColor() {
36
return $this->getDeviceStatusProperty('icon.color');
37
}
38
39
public function isDisabled() {
40
return ($this->getValue() === self::DISABLED);
41
}
42
43
public function hasStatusTag() {
44
return ($this->getStatusTagIcon() !== null);
45
}
46
47
public function getStatusTagIcon() {
48
return $this->getDeviceStatusProperty('status-tag.icon');
49
}
50
51
public function getStatusTagColor() {
52
return $this->getDeviceStatusProperty('status-tag.color');
53
}
54
55
public static function getStatusMap() {
56
$result = array();
57
58
foreach (self::newDeviceStatusMap() as $status_value => $ignored) {
59
$result[$status_value] = self::newStatusFromValue($status_value);
60
}
61
62
return $result;
63
}
64
65
public static function getActiveStatusList() {
66
$results = array();
67
foreach (self::newDeviceStatusMap() as $status_value => $status) {
68
if (empty($status['disabled'])) {
69
$results[] = $status_value;
70
}
71
}
72
return $results;
73
}
74
75
public static function getDisabledStatusList() {
76
$results = array();
77
foreach (self::newDeviceStatusMap() as $status_value => $status) {
78
if (!empty($status['disabled'])) {
79
$results[] = $status_value;
80
}
81
}
82
return $results;
83
}
84
85
private function getDeviceStatusProperty($key, $default = null) {
86
$map = self::newDeviceStatusMap();
87
$properties = idx($map, $this->getValue(), array());
88
return idx($properties, $key, $default);
89
}
90
91
private static function newDeviceStatusMap() {
92
return array(
93
self::ACTIVE => array(
94
'name' => pht('Active'),
95
'icon.icon' => 'fa-server',
96
'icon.color' => 'green',
97
),
98
self::DISABLED => array(
99
'name' => pht('Disabled'),
100
'icon.icon' => 'fa-times',
101
'icon.color' => 'grey',
102
'status-tag.icon' => 'fa-times',
103
'status-tag.color' => 'indigo',
104
'disabled' => true,
105
),
106
);
107
}
108
109
110
}
111
112