@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
fork

Configure Feed

Select the types of activity you want to include in your feed.

Separate Slowvote poll status onto a dedicated object

Summary: Ref T13682. Prepares for use of API-friendly string constants rather than opaque integers.

Test Plan: Created and edited polls, opening and closing them. Grepped for affected methods.

Maniphest Tasks: T13682

Differential Revision: https://secure.phabricator.com/D21847

+102 -15
+2
src/__phutil_library_map__.php
··· 5874 5874 'SlowvoteEmbedView' => 'applications/slowvote/view/SlowvoteEmbedView.php', 5875 5875 'SlowvoteInfoConduitAPIMethod' => 'applications/slowvote/conduit/SlowvoteInfoConduitAPIMethod.php', 5876 5876 'SlowvotePollResponseVisibility' => 'applications/slowvote/constants/SlowvotePollResponseVisibility.php', 5877 + 'SlowvotePollStatus' => 'applications/slowvote/constants/SlowvotePollStatus.php', 5877 5878 'SlowvotePollVotingMethod' => 'applications/slowvote/constants/SlowvotePollVotingMethod.php', 5878 5879 'SlowvoteRemarkupRule' => 'applications/slowvote/remarkup/SlowvoteRemarkupRule.php', 5879 5880 'SlowvoteSearchConduitAPIMethod' => 'applications/slowvote/conduit/SlowvoteSearchConduitAPIMethod.php', ··· 12778 12779 'SlowvoteEmbedView' => 'AphrontView', 12779 12780 'SlowvoteInfoConduitAPIMethod' => 'SlowvoteConduitAPIMethod', 12780 12781 'SlowvotePollResponseVisibility' => 'Phobject', 12782 + 'SlowvotePollStatus' => 'Phobject', 12781 12783 'SlowvotePollVotingMethod' => 'Phobject', 12782 12784 'SlowvoteRemarkupRule' => 'PhabricatorObjectRemarkupRule', 12783 12785 'SlowvoteSearchConduitAPIMethod' => 'PhabricatorSearchEngineAPIMethod',
+70
src/applications/slowvote/constants/SlowvotePollStatus.php
··· 1 + <?php 2 + 3 + final class SlowvotePollStatus 4 + extends Phobject { 5 + 6 + const STATUS_OPEN = 0; 7 + const STATUS_CLOSED = 1; 8 + 9 + private $key; 10 + 11 + public static function newStatusObject($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::newStatusObject($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 getHeaderTagIcon() { 43 + return $this->getProperty('header.tag.icon'); 44 + } 45 + 46 + public function getHeaderTagColor() { 47 + return $this->getProperty('header.tag.color'); 48 + } 49 + 50 + private function getProperty($key, $default = null) { 51 + $spec = idx(self::getMap(), $this->getKey(), array()); 52 + return idx($spec, $key, $default); 53 + } 54 + 55 + private static function getMap() { 56 + return array( 57 + self::STATUS_OPEN => array( 58 + 'name' => pht('Open'), 59 + 'header.tag.icon' => 'fa-square-o', 60 + 'header.tag.color' => 'bluegrey', 61 + ), 62 + self::STATUS_CLOSED => array( 63 + 'name' => pht('Closed'), 64 + 'header.tag.icon' => 'fa-ban', 65 + 'header.tag.color' => 'indigo', 66 + ), 67 + ); 68 + } 69 + 70 + }
+4 -4
src/applications/slowvote/controller/PhabricatorSlowvoteCloseController.php
··· 23 23 $close_uri = '/V'.$poll->getID(); 24 24 25 25 if ($request->isFormPost()) { 26 - if ($poll->getIsClosed()) { 27 - $new_status = 0; 26 + if ($poll->isClosed()) { 27 + $new_status = SlowvotePollStatus::STATUS_OPEN; 28 28 } else { 29 - $new_status = 1; 29 + $new_status = SlowvotePollStatus::STATUS_CLOSED; 30 30 } 31 31 32 32 $xactions = array(); ··· 46 46 return id(new AphrontRedirectResponse())->setURI($close_uri); 47 47 } 48 48 49 - if ($poll->getIsClosed()) { 49 + if ($poll->isClosed()) { 50 50 $title = pht('Reopen Poll'); 51 51 $content = pht('Are you sure you want to reopen the poll?'); 52 52 $submit = pht('Reopen');
+12 -6
src/applications/slowvote/controller/PhabricatorSlowvotePollController.php
··· 35 35 )); 36 36 } 37 37 38 - $header_icon = $poll->getIsClosed() ? 'fa-ban' : 'fa-square-o'; 39 - $header_name = $poll->getIsClosed() ? pht('Closed') : pht('Open'); 40 - $header_color = $poll->getIsClosed() ? 'indigo' : 'bluegrey'; 38 + $status = $poll->getStatusObject(); 39 + 40 + $header_icon = $status->getHeaderTagIcon(); 41 + $header_color = $status->getHeaderTagColor(); 42 + $header_name = $status->getName(); 41 43 42 44 $header = id(new PHUIHeaderView()) 43 45 ->setHeader($poll->getQuestion()) ··· 50 52 $subheader = $this->buildSubheaderView($poll); 51 53 52 54 $crumbs = $this->buildApplicationCrumbs(); 53 - $crumbs->addTextCrumb('V'.$poll->getID()); 55 + $crumbs->addTextCrumb($poll->getMonogram()); 54 56 $crumbs->setBorder(true); 55 57 56 58 $timeline = $this->buildTransactionTimeline( ··· 71 73 ->setMainColumn($poll_content); 72 74 73 75 return $this->newPage() 74 - ->setTitle('V'.$poll->getID().' '.$poll->getQuestion()) 76 + ->setTitle( 77 + pht( 78 + '%s %s', 79 + $poll->getMonogram(), 80 + $poll->getQuestion())) 75 81 ->setCrumbs($crumbs) 76 82 ->setPageObjectPHIDs(array($poll->getPHID())) 77 83 ->appendChild($view); ··· 87 93 88 94 $curtain = $this->newCurtainView($poll); 89 95 90 - $is_closed = $poll->getIsClosed(); 96 + $is_closed = $poll->isClosed(); 91 97 $close_poll_text = $is_closed ? pht('Reopen Poll') : pht('Close Poll'); 92 98 $close_poll_icon = $is_closed ? 'fa-check' : 'fa-ban'; 93 99
+1 -1
src/applications/slowvote/controller/PhabricatorSlowvoteVoteController.php
··· 21 21 return new Aphront404Response(); 22 22 } 23 23 24 - if ($poll->getIsClosed()) { 24 + if ($poll->isClosed()) { 25 25 return new Aphront400Response(); 26 26 } 27 27
+1 -1
src/applications/slowvote/query/PhabricatorSlowvoteSearchEngine.php
··· 142 142 ->setHref('/V'.$poll->getID()) 143 143 ->addIcon('none', $date_created); 144 144 145 - if ($poll->getIsClosed()) { 145 + if ($poll->isClosed()) { 146 146 $item->setStatusIcon('fa-ban grey'); 147 147 $item->setDisabled(true); 148 148 } else {
+10 -1
src/applications/slowvote/storage/PhabricatorSlowvotePoll.php
··· 20 20 protected $shuffle = 0; 21 21 protected $method; 22 22 protected $viewPolicy; 23 - protected $isClosed = 0; 23 + protected $isClosed; 24 24 protected $spacePHID; 25 25 26 26 private $options = self::ATTACHABLE; ··· 43 43 ->setAuthorPHID($actor->getPHID()) 44 44 ->setViewPolicy($view_policy) 45 45 ->setSpacePHID($actor->getDefaultSpacePHID()) 46 + ->setIsClosed(SlowvotePollStatus::STATUS_OPEN) 46 47 ->setMethod($default_method) 47 48 ->setResponseVisibility($default_responses); 48 49 } ··· 65 66 66 67 public function getPHIDType() { 67 68 return PhabricatorSlowvotePollPHIDType::TYPECONST; 69 + } 70 + 71 + public function getStatusObject() { 72 + return SlowvotePollStatus::newStatusObject($this->getIsClosed()); 73 + } 74 + 75 + public function isClosed() { 76 + return ($this->getIsClosed() == SlowvotePollStatus::STATUS_CLOSED); 68 77 } 69 78 70 79 public function getOptions() {
+2 -2
src/applications/slowvote/view/SlowvoteEmbedView.php
··· 95 95 ), 96 96 $quip); 97 97 98 - if ($poll->getIsClosed()) { 98 + if ($poll->isClosed()) { 99 99 $submit = null; 100 100 } else { 101 101 $submit = phutil_tag( ··· 228 228 SlowvotePollVotingMethod::METHOD_APPROVAL => 'checkbox', 229 229 ); 230 230 231 - $closed = $this->getPoll()->getIsClosed(); 231 + $closed = $this->getPoll()->isClosed(); 232 232 233 233 return phutil_tag( 234 234 'input',