Page MenuHomePhabricator

D21847.id52071.diff
No OneTemporary

D21847.id52071.diff

diff --git a/src/__phutil_library_map__.php b/src/__phutil_library_map__.php
--- a/src/__phutil_library_map__.php
+++ b/src/__phutil_library_map__.php
@@ -5874,6 +5874,7 @@
'SlowvoteEmbedView' => 'applications/slowvote/view/SlowvoteEmbedView.php',
'SlowvoteInfoConduitAPIMethod' => 'applications/slowvote/conduit/SlowvoteInfoConduitAPIMethod.php',
'SlowvotePollResponseVisibility' => 'applications/slowvote/constants/SlowvotePollResponseVisibility.php',
+ 'SlowvotePollStatus' => 'applications/slowvote/constants/SlowvotePollStatus.php',
'SlowvotePollVotingMethod' => 'applications/slowvote/constants/SlowvotePollVotingMethod.php',
'SlowvoteRemarkupRule' => 'applications/slowvote/remarkup/SlowvoteRemarkupRule.php',
'SlowvoteSearchConduitAPIMethod' => 'applications/slowvote/conduit/SlowvoteSearchConduitAPIMethod.php',
@@ -12778,6 +12779,7 @@
'SlowvoteEmbedView' => 'AphrontView',
'SlowvoteInfoConduitAPIMethod' => 'SlowvoteConduitAPIMethod',
'SlowvotePollResponseVisibility' => 'Phobject',
+ 'SlowvotePollStatus' => 'Phobject',
'SlowvotePollVotingMethod' => 'Phobject',
'SlowvoteRemarkupRule' => 'PhabricatorObjectRemarkupRule',
'SlowvoteSearchConduitAPIMethod' => 'PhabricatorSearchEngineAPIMethod',
diff --git a/src/applications/slowvote/constants/SlowvotePollStatus.php b/src/applications/slowvote/constants/SlowvotePollStatus.php
new file mode 100644
--- /dev/null
+++ b/src/applications/slowvote/constants/SlowvotePollStatus.php
@@ -0,0 +1,70 @@
+<?php
+
+final class SlowvotePollStatus
+ extends Phobject {
+
+ const STATUS_OPEN = 0;
+ const STATUS_CLOSED = 1;
+
+ private $key;
+
+ public static function newStatusObject($key) {
+ $object = new self();
+ $object->key = $key;
+ return $object;
+ }
+
+ public function getKey() {
+ return $this->key;
+ }
+
+ public static function getAll() {
+ $map = self::getMap();
+
+ $result = array();
+ foreach ($map as $key => $spec) {
+ $result[$key] = self::newStatusObject($key);
+ }
+
+ return $result;
+ }
+
+ public function getName() {
+ $name = $this->getProperty('name');
+
+ if ($name === null) {
+ $name = pht('Unknown ("%s")', $this->getKey());
+ }
+
+ return $name;
+ }
+
+ public function getHeaderTagIcon() {
+ return $this->getProperty('header.tag.icon');
+ }
+
+ public function getHeaderTagColor() {
+ return $this->getProperty('header.tag.color');
+ }
+
+ private function getProperty($key, $default = null) {
+ $spec = idx(self::getMap(), $this->getKey(), array());
+ return idx($spec, $key, $default);
+ }
+
+ private static function getMap() {
+ return array(
+ self::STATUS_OPEN => array(
+ 'name' => pht('Open'),
+ 'header.tag.icon' => 'fa-square-o',
+ 'header.tag.color' => 'bluegrey',
+ ),
+ self::STATUS_CLOSED => array(
+ 'name' => pht('Closed'),
+ 'header.tag.icon' => 'fa-ban',
+ 'header.tag.color' => 'indigo',
+ ),
+ );
+ }
+
+}
diff --git a/src/applications/slowvote/controller/PhabricatorSlowvoteCloseController.php b/src/applications/slowvote/controller/PhabricatorSlowvoteCloseController.php
--- a/src/applications/slowvote/controller/PhabricatorSlowvoteCloseController.php
+++ b/src/applications/slowvote/controller/PhabricatorSlowvoteCloseController.php
@@ -23,10 +23,10 @@
$close_uri = '/V'.$poll->getID();
if ($request->isFormPost()) {
- if ($poll->getIsClosed()) {
- $new_status = 0;
+ if ($poll->isClosed()) {
+ $new_status = SlowvotePollStatus::STATUS_OPEN;
} else {
- $new_status = 1;
+ $new_status = SlowvotePollStatus::STATUS_CLOSED;
}
$xactions = array();
@@ -46,7 +46,7 @@
return id(new AphrontRedirectResponse())->setURI($close_uri);
}
- if ($poll->getIsClosed()) {
+ if ($poll->isClosed()) {
$title = pht('Reopen Poll');
$content = pht('Are you sure you want to reopen the poll?');
$submit = pht('Reopen');
diff --git a/src/applications/slowvote/controller/PhabricatorSlowvotePollController.php b/src/applications/slowvote/controller/PhabricatorSlowvotePollController.php
--- a/src/applications/slowvote/controller/PhabricatorSlowvotePollController.php
+++ b/src/applications/slowvote/controller/PhabricatorSlowvotePollController.php
@@ -35,9 +35,11 @@
));
}
- $header_icon = $poll->getIsClosed() ? 'fa-ban' : 'fa-square-o';
- $header_name = $poll->getIsClosed() ? pht('Closed') : pht('Open');
- $header_color = $poll->getIsClosed() ? 'indigo' : 'bluegrey';
+ $status = $poll->getStatusObject();
+
+ $header_icon = $status->getHeaderTagIcon();
+ $header_color = $status->getHeaderTagColor();
+ $header_name = $status->getName();
$header = id(new PHUIHeaderView())
->setHeader($poll->getQuestion())
@@ -50,7 +52,7 @@
$subheader = $this->buildSubheaderView($poll);
$crumbs = $this->buildApplicationCrumbs();
- $crumbs->addTextCrumb('V'.$poll->getID());
+ $crumbs->addTextCrumb($poll->getMonogram());
$crumbs->setBorder(true);
$timeline = $this->buildTransactionTimeline(
@@ -71,7 +73,11 @@
->setMainColumn($poll_content);
return $this->newPage()
- ->setTitle('V'.$poll->getID().' '.$poll->getQuestion())
+ ->setTitle(
+ pht(
+ '%s %s',
+ $poll->getMonogram(),
+ $poll->getQuestion()))
->setCrumbs($crumbs)
->setPageObjectPHIDs(array($poll->getPHID()))
->appendChild($view);
@@ -87,7 +93,7 @@
$curtain = $this->newCurtainView($poll);
- $is_closed = $poll->getIsClosed();
+ $is_closed = $poll->isClosed();
$close_poll_text = $is_closed ? pht('Reopen Poll') : pht('Close Poll');
$close_poll_icon = $is_closed ? 'fa-check' : 'fa-ban';
diff --git a/src/applications/slowvote/controller/PhabricatorSlowvoteVoteController.php b/src/applications/slowvote/controller/PhabricatorSlowvoteVoteController.php
--- a/src/applications/slowvote/controller/PhabricatorSlowvoteVoteController.php
+++ b/src/applications/slowvote/controller/PhabricatorSlowvoteVoteController.php
@@ -21,7 +21,7 @@
return new Aphront404Response();
}
- if ($poll->getIsClosed()) {
+ if ($poll->isClosed()) {
return new Aphront400Response();
}
diff --git a/src/applications/slowvote/query/PhabricatorSlowvoteSearchEngine.php b/src/applications/slowvote/query/PhabricatorSlowvoteSearchEngine.php
--- a/src/applications/slowvote/query/PhabricatorSlowvoteSearchEngine.php
+++ b/src/applications/slowvote/query/PhabricatorSlowvoteSearchEngine.php
@@ -142,7 +142,7 @@
->setHref('/V'.$poll->getID())
->addIcon('none', $date_created);
- if ($poll->getIsClosed()) {
+ if ($poll->isClosed()) {
$item->setStatusIcon('fa-ban grey');
$item->setDisabled(true);
} else {
diff --git a/src/applications/slowvote/storage/PhabricatorSlowvotePoll.php b/src/applications/slowvote/storage/PhabricatorSlowvotePoll.php
--- a/src/applications/slowvote/storage/PhabricatorSlowvotePoll.php
+++ b/src/applications/slowvote/storage/PhabricatorSlowvotePoll.php
@@ -20,7 +20,7 @@
protected $shuffle = 0;
protected $method;
protected $viewPolicy;
- protected $isClosed = 0;
+ protected $isClosed;
protected $spacePHID;
private $options = self::ATTACHABLE;
@@ -43,6 +43,7 @@
->setAuthorPHID($actor->getPHID())
->setViewPolicy($view_policy)
->setSpacePHID($actor->getDefaultSpacePHID())
+ ->setIsClosed(SlowvotePollStatus::STATUS_OPEN)
->setMethod($default_method)
->setResponseVisibility($default_responses);
}
@@ -67,6 +68,14 @@
return PhabricatorSlowvotePollPHIDType::TYPECONST;
}
+ public function getStatusObject() {
+ return SlowvotePollStatus::newStatusObject($this->getIsClosed());
+ }
+
+ public function isClosed() {
+ return ($this->getIsClosed() == SlowvotePollStatus::STATUS_CLOSED);
+ }
+
public function getOptions() {
return $this->assertAttached($this->options);
}
diff --git a/src/applications/slowvote/view/SlowvoteEmbedView.php b/src/applications/slowvote/view/SlowvoteEmbedView.php
--- a/src/applications/slowvote/view/SlowvoteEmbedView.php
+++ b/src/applications/slowvote/view/SlowvoteEmbedView.php
@@ -95,7 +95,7 @@
),
$quip);
- if ($poll->getIsClosed()) {
+ if ($poll->isClosed()) {
$submit = null;
} else {
$submit = phutil_tag(
@@ -228,7 +228,7 @@
SlowvotePollVotingMethod::METHOD_APPROVAL => 'checkbox',
);
- $closed = $this->getPoll()->getIsClosed();
+ $closed = $this->getPoll()->isClosed();
return phutil_tag(
'input',

File Metadata

Mime Type
text/plain
Expires
Sun, Mar 16, 9:27 AM (4 d, 18 h ago)
Storage Engine
blob
Storage Format
Encrypted (AES-256-CBC)
Storage Handle
7651946
Default Alt Text
D21847.id52071.diff (8 KB)

Event Timeline