@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
1<?php
2
3final class SlowvotePollResponseVisibility
4 extends Phobject {
5
6 const RESPONSES_VISIBLE = 'visible';
7 const RESPONSES_VOTERS = 'voters';
8 const RESPONSES_OWNER = 'owner';
9
10 private $key;
11
12 public static function newResponseVisibilityObject($key) {
13 $object = new self();
14 $object->key = $key;
15 return $object;
16 }
17
18 public function getKey() {
19 return $this->key;
20 }
21
22 public static function getAll() {
23 $map = self::getMap();
24
25 $result = array();
26 foreach ($map as $key => $spec) {
27 $result[$key] = self::newResponseVisibilityObject($key);
28 }
29
30 return $result;
31 }
32
33 public function getName() {
34 $name = $this->getProperty('name');
35
36 if ($name === null) {
37 $name = pht('Unknown ("%s")', $this->getKey());
38 }
39
40 return $name;
41 }
42
43 public function getNameForEdit() {
44 $name = $this->getProperty('name.edit');
45
46 if ($name === null) {
47 $name = pht('Unknown ("%s")', $this->getKey());
48 }
49
50 return $name;
51 }
52
53 private function getProperty($key, $default = null) {
54 $spec = idx(self::getMap(), $this->getKey(), array());
55 return idx($spec, $key, $default);
56 }
57
58 private static function getMap() {
59 return array(
60 self::RESPONSES_VISIBLE => array(
61 'name' => pht('Always Visible'),
62 'name.edit' => pht('Anyone can see the responses'),
63 ),
64 self::RESPONSES_VOTERS => array(
65 'name' => pht('Voters'),
66 'name.edit' => pht('Require a vote to see the responses'),
67 ),
68 self::RESPONSES_OWNER => array(
69 'name' => pht('Author'),
70 'name.edit' => pht('Only the poll author can see the responses'),
71 ),
72 );
73 }
74
75}