@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 SlowvotePollVotingMethod
4 extends Phobject {
5
6 const METHOD_PLURALITY = 'plurality';
7 const METHOD_APPROVAL = 'approval';
8
9 private $key;
10
11 public static function newVotingMethodObject($key) {
12 $object = new self();
13 $object->key = $key;
14 return $object;
15 }
16
17 public function getKey() {
18 return $this->key;
19 }
20
21 public static function getAll() {
22 $map = self::getMap();
23
24 $result = array();
25 foreach ($map as $key => $spec) {
26 $result[$key] = self::newVotingMethodObject($key);
27 }
28
29 return $result;
30 }
31
32 public function getName() {
33 $name = $this->getProperty('name');
34
35 if ($name === null) {
36 $name = pht('Unknown ("%s")', $this->getKey());
37 }
38
39 return $name;
40 }
41
42 public function getNameForEdit() {
43 $name = $this->getProperty('name.edit');
44
45 if ($name === null) {
46 $name = pht('Unknown ("%s")', $this->getKey());
47 }
48
49 return $name;
50 }
51
52 private function getProperty($key, $default = null) {
53 $spec = idx(self::getMap(), $this->getKey(), array());
54 return idx($spec, $key, $default);
55 }
56
57 private static function getMap() {
58 return array(
59 self::METHOD_PLURALITY => array(
60 'name' => pht('Plurality'),
61 'name.edit' => pht('Plurality (Single Choice)'),
62 ),
63 self::METHOD_APPROVAL => array(
64 'name' => pht('Approval'),
65 'name.edit' => pht('Approval (Multiple Choice)'),
66 ),
67 );
68 }
69
70}