3 final class AlmanacDeviceStatus
6 const ACTIVE
= 'active';
7 const DISABLED
= 'disabled';
11 public static function newStatusFromValue($value) {
13 $status->value
= $value;
17 public function getValue() {
21 public function getName() {
22 $name = $this->getDeviceStatusProperty('name');
25 $name = pht('Unknown Almanac Device Status ("%s")', $this->getValue());
31 public function getIconIcon() {
32 return $this->getDeviceStatusProperty('icon.icon');
35 public function getIconColor() {
36 return $this->getDeviceStatusProperty('icon.color');
39 public function isDisabled() {
40 return ($this->getValue() === self
::DISABLED
);
43 public function hasStatusTag() {
44 return ($this->getStatusTagIcon() !== null);
47 public function getStatusTagIcon() {
48 return $this->getDeviceStatusProperty('status-tag.icon');
51 public function getStatusTagColor() {
52 return $this->getDeviceStatusProperty('status-tag.color');
55 public static function getStatusMap() {
58 foreach (self
::newDeviceStatusMap() as $status_value => $ignored) {
59 $result[$status_value] = self
::newStatusFromValue($status_value);
65 public static function getActiveStatusList() {
67 foreach (self
::newDeviceStatusMap() as $status_value => $status) {
68 if (empty($status['disabled'])) {
69 $results[] = $status_value;
75 public static function getDisabledStatusList() {
77 foreach (self
::newDeviceStatusMap() as $status_value => $status) {
78 if (!empty($status['disabled'])) {
79 $results[] = $status_value;
85 private function getDeviceStatusProperty($key, $default = null) {
86 $map = self
::newDeviceStatusMap();
87 $properties = idx($map, $this->getValue(), array());
88 return idx($properties, $key, $default);
91 private static function newDeviceStatusMap() {
93 self
::ACTIVE
=> array(
94 'name' => pht('Active'),
95 'icon.icon' => 'fa-server',
96 'icon.color' => 'green',
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',