forked from phacility/phabricator
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPhabricatorProjectTriggerPlaySoundRule.php
123 lines (98 loc) · 2.73 KB
/
PhabricatorProjectTriggerPlaySoundRule.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
<?php
final class PhabricatorProjectTriggerPlaySoundRule
extends PhabricatorProjectTriggerRule {
const TRIGGERTYPE = 'sound';
public function getSelectControlName() {
return pht('Play sound');
}
protected function assertValidRuleRecordFormat($value) {
if (!is_string($value)) {
throw new Exception(
pht(
'Status rule value should be a string, but is not (value is "%s").',
phutil_describe_type($value)));
}
}
protected function assertValidRuleRecordValue($value) {
$map = self::getSoundMap();
if (!isset($map[$value])) {
throw new Exception(
pht(
'Sound ("%s") is not a valid sound.',
$value));
}
}
protected function newDropTransactions($object, $value) {
return array();
}
protected function newDropEffects($value) {
$sound_icon = 'fa-volume-up';
$sound_color = 'blue';
$sound_name = self::getSoundName($value);
$content = pht(
'Play sound %s.',
phutil_tag('strong', array(), $sound_name));
return array(
$this->newEffect()
->setIcon($sound_icon)
->setColor($sound_color)
->setContent($content),
);
}
protected function getDefaultValue() {
return head_key(self::getSoundMap());
}
protected function getPHUIXControlType() {
return 'select';
}
protected function getPHUIXControlSpecification() {
$map = self::getSoundMap();
$map = ipull($map, 'name');
return array(
'options' => $map,
'order' => array_keys($map),
);
}
public function getRuleViewLabel() {
return pht('Play Sound');
}
public function getRuleViewDescription($value) {
$sound_name = self::getSoundName($value);
return pht(
'Play sound %s.',
phutil_tag('strong', array(), $sound_name));
}
public function getRuleViewIcon($value) {
$sound_icon = 'fa-volume-up';
$sound_color = 'blue';
return id(new PHUIIconView())
->setIcon($sound_icon, $sound_color);
}
private static function getSoundName($value) {
$map = self::getSoundMap();
$spec = idx($map, $value, array());
return idx($spec, 'name', $value);
}
private static function getSoundMap() {
return array(
'bing' => array(
'name' => pht('Bing'),
'uri' => celerity_get_resource_uri('/rsrc/audio/basic/bing.mp3'),
),
'glass' => array(
'name' => pht('Glass'),
'uri' => celerity_get_resource_uri('/rsrc/audio/basic/ting.mp3'),
),
);
}
public function getSoundEffects() {
$value = $this->getValue();
$map = self::getSoundMap();
$spec = idx($map, $value, array());
$uris = array();
if (isset($spec['uri'])) {
$uris[] = $spec['uri'];
}
return $uris;
}
}