@recaptime-dev's working patches + fork for Phorge, a community fork of Phabricator. (Upstream dev and stable branches are at upstream/main and upstream/stable respectively.) hq.recaptime.dev/wiki/Phorge
phorge phabricator
at upstream/main 127 lines 2.9 kB view raw
1<?php 2 3final class PhabricatorProjectTriggerPlaySoundRule 4 extends PhabricatorProjectTriggerRule { 5 6 const TRIGGERTYPE = 'sound'; 7 8 public function getSelectControlName() { 9 return pht('Play sound'); 10 } 11 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))); 18 } 19 } 20 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)); 28 } 29 } 30 31 protected function newDropTransactions($object, $value) { 32 return array(); 33 } 34 35 protected function newDropEffects($value) { 36 $sound_icon = 'fa-volume-up'; 37 $sound_color = 'blue'; 38 $sound_name = self::getSoundName($value); 39 40 $content = pht( 41 'Play sound %s.', 42 phutil_tag('strong', array(), $sound_name)); 43 44 return array( 45 $this->newEffect() 46 ->setIcon($sound_icon) 47 ->setColor($sound_color) 48 ->setContent($content), 49 ); 50 } 51 52 protected function getDefaultValue() { 53 return head_key(self::getSoundMap()); 54 } 55 56 protected function getPHUIXControlType() { 57 return 'select'; 58 } 59 60 protected function getPHUIXControlSpecification() { 61 $map = self::getSoundMap(); 62 $map = ipull($map, 'name'); 63 64 return array( 65 'options' => $map, 66 'order' => array_keys($map), 67 ); 68 } 69 70 public function getRuleViewLabel() { 71 return pht('Play Sound'); 72 } 73 74 public function getRuleViewDescription($value) { 75 $sound_name = self::getSoundName($value); 76 77 return pht( 78 'Play sound %s.', 79 phutil_tag('strong', array(), $sound_name)); 80 } 81 82 public function getRuleViewIcon($value) { 83 $sound_icon = 'fa-volume-up'; 84 $sound_color = 'blue'; 85 86 return id(new PHUIIconView()) 87 ->setIcon($sound_icon, $sound_color); 88 } 89 90 private static function getSoundName($value) { 91 $map = self::getSoundMap(); 92 $spec = idx($map, $value, array()); 93 return idx($spec, 'name', $value); 94 } 95 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'), 101 ), 102 'coin' => array( 103 'name' => pht('Coin'), 104 'uri' => celerity_get_resource_uri('/rsrc/audio/basic/coin.mp3'), 105 ), 106 'glass' => array( 107 'name' => pht('Glass'), 108 'uri' => celerity_get_resource_uri('/rsrc/audio/basic/ting.mp3'), 109 ), 110 ); 111 } 112 113 public function getSoundEffects() { 114 $value = $this->getValue(); 115 116 $map = self::getSoundMap(); 117 $spec = idx($map, $value, array()); 118 119 $uris = array(); 120 if (isset($spec['uri'])) { 121 $uris[] = $spec['uri']; 122 } 123 124 return $uris; 125 } 126 127}