Correct a parameter order swap in "diffusion.historyquery" for Mercurial
[phabricator.git] / src / applications / project / trigger / PhabricatorProjectTriggerPlaySoundRule.php
blob9e99eb070f64f817fa35d515002d7bc2877a61cf
1 <?php
3 final class PhabricatorProjectTriggerPlaySoundRule
4 extends PhabricatorProjectTriggerRule {
6 const TRIGGERTYPE = 'sound';
8 public function getSelectControlName() {
9 return pht('Play sound');
12 protected function assertValidRuleRecordFormat($value) {
13 if (!is_string($value)) {
14 throw new Exception(
15 pht(
16 'Status rule value should be a string, but is not (value is "%s").',
17 phutil_describe_type($value)));
21 protected function assertValidRuleRecordValue($value) {
22 $map = self::getSoundMap();
23 if (!isset($map[$value])) {
24 throw new Exception(
25 pht(
26 'Sound ("%s") is not a valid sound.',
27 $value));
31 protected function newDropTransactions($object, $value) {
32 return array();
35 protected function newDropEffects($value) {
36 $sound_icon = 'fa-volume-up';
37 $sound_color = 'blue';
38 $sound_name = self::getSoundName($value);
40 $content = pht(
41 'Play sound %s.',
42 phutil_tag('strong', array(), $sound_name));
44 return array(
45 $this->newEffect()
46 ->setIcon($sound_icon)
47 ->setColor($sound_color)
48 ->setContent($content),
52 protected function getDefaultValue() {
53 return head_key(self::getSoundMap());
56 protected function getPHUIXControlType() {
57 return 'select';
60 protected function getPHUIXControlSpecification() {
61 $map = self::getSoundMap();
62 $map = ipull($map, 'name');
64 return array(
65 'options' => $map,
66 'order' => array_keys($map),
70 public function getRuleViewLabel() {
71 return pht('Play Sound');
74 public function getRuleViewDescription($value) {
75 $sound_name = self::getSoundName($value);
77 return pht(
78 'Play sound %s.',
79 phutil_tag('strong', array(), $sound_name));
82 public function getRuleViewIcon($value) {
83 $sound_icon = 'fa-volume-up';
84 $sound_color = 'blue';
86 return id(new PHUIIconView())
87 ->setIcon($sound_icon, $sound_color);
90 private static function getSoundName($value) {
91 $map = self::getSoundMap();
92 $spec = idx($map, $value, array());
93 return idx($spec, 'name', $value);
96 private static function getSoundMap() {
97 return array(
98 'bing' => array(
99 'name' => pht('Bing'),
100 'uri' => celerity_get_resource_uri('/rsrc/audio/basic/bing.mp3'),
102 'glass' => array(
103 'name' => pht('Glass'),
104 'uri' => celerity_get_resource_uri('/rsrc/audio/basic/ting.mp3'),
109 public function getSoundEffects() {
110 $value = $this->getValue();
112 $map = self::getSoundMap();
113 $spec = idx($map, $value, array());
115 $uris = array();
116 if (isset($spec['uri'])) {
117 $uris[] = $spec['uri'];
120 return $uris;