Page MenuHomestyx hydra

No OneTemporary

diff --git a/resources/sql/autopatches/20220525.slowvote.03.response-type.sql b/resources/sql/autopatches/20220525.slowvote.03.response-type.sql
new file mode 100644
index 0000000000..8cefc4d578
--- /dev/null
+++ b/resources/sql/autopatches/20220525.slowvote.03.response-type.sql
@@ -0,0 +1,3 @@
+ALTER TABLE {$NAMESPACE}_slowvote.slowvote_poll
+ CHANGE responseVisibility
+ responseVisibility VARCHAR(32) NOT NULL COLLATE {$COLLATE_TEXT};
diff --git a/resources/sql/autopatches/20220525.slowvote.04.response-value.sql b/resources/sql/autopatches/20220525.slowvote.04.response-value.sql
new file mode 100644
index 0000000000..b76bcdb784
--- /dev/null
+++ b/resources/sql/autopatches/20220525.slowvote.04.response-value.sql
@@ -0,0 +1,8 @@
+UPDATE {$NAMESPACE}_slowvote.slowvote_poll
+ SET responseVisibility = 'visible' WHERE responseVisibility = '0';
+
+UPDATE {$NAMESPACE}_slowvote.slowvote_poll
+ SET responseVisibility = 'voters' WHERE responseVisibility = '1';
+
+UPDATE {$NAMESPACE}_slowvote.slowvote_poll
+ SET responseVisibility = 'owner' WHERE responseVisibility = '2';
diff --git a/resources/sql/autopatches/20220525.slowvote.05.response-xactions.sql b/resources/sql/autopatches/20220525.slowvote.05.response-xactions.sql
new file mode 100644
index 0000000000..7e819d5893
--- /dev/null
+++ b/resources/sql/autopatches/20220525.slowvote.05.response-xactions.sql
@@ -0,0 +1,23 @@
+UPDATE {$NAMESPACE}_slowvote.slowvote_transaction
+ SET oldValue = '"visible"' WHERE
+ transactionType = 'vote:responses' AND oldValue IN ('0', '"0"');
+
+UPDATE {$NAMESPACE}_slowvote.slowvote_transaction
+ SET newValue = '"visible"' WHERE
+ transactionType = 'vote:responses' AND newValue IN ('0', '"0"');
+
+UPDATE {$NAMESPACE}_slowvote.slowvote_transaction
+ SET oldValue = '"voters"' WHERE
+ transactionType = 'vote:responses' AND oldValue IN ('1', '"1"');
+
+UPDATE {$NAMESPACE}_slowvote.slowvote_transaction
+ SET newValue = '"voters"' WHERE
+ transactionType = 'vote:responses' AND newValue IN ('1', '"1"');
+
+UPDATE {$NAMESPACE}_slowvote.slowvote_transaction
+ SET oldValue = '"owner"' WHERE
+ transactionType = 'vote:responses' AND oldValue IN ('2', '"2"');
+
+UPDATE {$NAMESPACE}_slowvote.slowvote_transaction
+ SET newValue = '"owner"' WHERE
+ transactionType = 'vote:responses' AND newValue IN ('2', '"2"');
diff --git a/src/applications/slowvote/constants/SlowvotePollResponseVisibility.php b/src/applications/slowvote/constants/SlowvotePollResponseVisibility.php
index 94d35794fc..1daf237e72 100644
--- a/src/applications/slowvote/constants/SlowvotePollResponseVisibility.php
+++ b/src/applications/slowvote/constants/SlowvotePollResponseVisibility.php
@@ -1,75 +1,75 @@
<?php
final class SlowvotePollResponseVisibility
extends Phobject {
- const RESPONSES_VISIBLE = 0;
- const RESPONSES_VOTERS = 1;
- const RESPONSES_OWNER = 2;
+ const RESPONSES_VISIBLE = 'visible';
+ const RESPONSES_VOTERS = 'voters';
+ const RESPONSES_OWNER = 'owner';
private $key;
public static function newResponseVisibilityObject($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::newResponseVisibilityObject($key);
}
return $result;
}
public function getName() {
$name = $this->getProperty('name');
if ($name === null) {
$name = pht('Unknown ("%s")', $this->getKey());
}
return $name;
}
public function getNameForEdit() {
$name = $this->getProperty('name.edit');
if ($name === null) {
$name = pht('Unknown ("%s")', $this->getKey());
}
return $name;
}
private function getProperty($key, $default = null) {
- $spec = idx(self::getMap(), $this->getKey());
+ $spec = idx(self::getMap(), $this->getKey(), array());
return idx($spec, $key, $default);
}
private static function getMap() {
return array(
self::RESPONSES_VISIBLE => array(
'name' => pht('Always Visible'),
'name.edit' => pht('Anyone can see the responses'),
),
self::RESPONSES_VOTERS => array(
'name' => pht('Voters'),
'name.edit' => pht('Require a vote to see the responses'),
),
self::RESPONSES_OWNER => array(
'name' => pht('Owner'),
'name.edit' => pht('Only the poll owner can see the responses'),
),
);
}
}
diff --git a/src/applications/slowvote/controller/PhabricatorSlowvoteEditController.php b/src/applications/slowvote/controller/PhabricatorSlowvoteEditController.php
index d54cf884d3..599f3c83bd 100644
--- a/src/applications/slowvote/controller/PhabricatorSlowvoteEditController.php
+++ b/src/applications/slowvote/controller/PhabricatorSlowvoteEditController.php
@@ -1,283 +1,294 @@
<?php
final class PhabricatorSlowvoteEditController
extends PhabricatorSlowvoteController {
public function handleRequest(AphrontRequest $request) {
$viewer = $request->getViewer();
$id = $request->getURIData('id');
if ($id) {
$poll = id(new PhabricatorSlowvoteQuery())
->setViewer($viewer)
->withIDs(array($id))
->requireCapabilities(
array(
PhabricatorPolicyCapability::CAN_VIEW,
PhabricatorPolicyCapability::CAN_EDIT,
))
->executeOne();
if (!$poll) {
return new Aphront404Response();
}
$is_new = false;
} else {
$poll = PhabricatorSlowvotePoll::initializeNewPoll($viewer);
$is_new = true;
}
if ($is_new) {
$v_projects = array();
} else {
$v_projects = PhabricatorEdgeQuery::loadDestinationPHIDs(
$poll->getPHID(),
PhabricatorProjectObjectHasProjectEdgeType::EDGECONST);
$v_projects = array_reverse($v_projects);
}
$e_question = true;
$e_response = true;
$errors = array();
$v_question = $poll->getQuestion();
$v_description = $poll->getDescription();
$v_responses = $poll->getResponseVisibility();
$v_shuffle = $poll->getShuffle();
$v_space = $poll->getSpacePHID();
$responses = $request->getArr('response');
if ($request->isFormPost()) {
$v_question = $request->getStr('question');
$v_description = $request->getStr('description');
$v_responses = $request->getStr('responses');
$v_shuffle = (int)$request->getBool('shuffle');
$v_view_policy = $request->getStr('viewPolicy');
$v_projects = $request->getArr('projects');
$v_space = $request->getStr('spacePHID');
if ($is_new) {
$poll->setMethod($request->getInt('method'));
}
if (!strlen($v_question)) {
$e_question = pht('Required');
$errors[] = pht('You must ask a poll question.');
} else {
$e_question = null;
}
if ($is_new) {
// NOTE: Make sure common and useful response "0" is preserved.
foreach ($responses as $key => $response) {
if (!strlen($response)) {
unset($responses[$key]);
}
}
if (empty($responses)) {
$errors[] = pht('You must offer at least one response.');
$e_response = pht('Required');
} else {
$e_response = null;
}
}
$template = id(new PhabricatorSlowvoteTransaction());
$xactions = array();
if ($is_new) {
$xactions[] = id(new PhabricatorSlowvoteTransaction())
->setTransactionType(PhabricatorTransactions::TYPE_CREATE);
}
$xactions[] = id(clone $template)
->setTransactionType(
PhabricatorSlowvoteQuestionTransaction::TRANSACTIONTYPE)
->setNewValue($v_question);
$xactions[] = id(clone $template)
->setTransactionType(
PhabricatorSlowvoteDescriptionTransaction::TRANSACTIONTYPE)
->setNewValue($v_description);
$xactions[] = id(clone $template)
->setTransactionType(
PhabricatorSlowvoteResponsesTransaction::TRANSACTIONTYPE)
->setNewValue($v_responses);
$xactions[] = id(clone $template)
->setTransactionType(
PhabricatorSlowvoteShuffleTransaction::TRANSACTIONTYPE)
->setNewValue($v_shuffle);
$xactions[] = id(clone $template)
->setTransactionType(PhabricatorTransactions::TYPE_VIEW_POLICY)
->setNewValue($v_view_policy);
$xactions[] = id(clone $template)
->setTransactionType(PhabricatorTransactions::TYPE_SPACE)
->setNewValue($v_space);
if (empty($errors)) {
$proj_edge_type = PhabricatorProjectObjectHasProjectEdgeType::EDGECONST;
$xactions[] = id(new PhabricatorSlowvoteTransaction())
->setTransactionType(PhabricatorTransactions::TYPE_EDGE)
->setMetadataValue('edge:type', $proj_edge_type)
->setNewValue(array('=' => array_fuse($v_projects)));
$editor = id(new PhabricatorSlowvoteEditor())
->setActor($viewer)
->setContinueOnNoEffect(true)
->setContentSourceFromRequest($request);
$xactions = $editor->applyTransactions($poll, $xactions);
if ($is_new) {
$poll->save();
foreach ($responses as $response) {
$option = new PhabricatorSlowvoteOption();
$option->setName($response);
$option->setPollID($poll->getID());
$option->save();
}
}
return id(new AphrontRedirectResponse())
->setURI($poll->getURI());
} else {
$poll->setViewPolicy($v_view_policy);
}
}
$form = id(new AphrontFormView())
->setAction($request->getrequestURI())
->setUser($viewer)
->appendChild(
id(new AphrontFormTextControl())
->setLabel(pht('Question'))
->setName('question')
->setValue($v_question)
->setError($e_question))
->appendChild(
id(new PhabricatorRemarkupControl())
->setUser($viewer)
->setLabel(pht('Description'))
->setName('description')
->setValue($v_description))
->appendControl(
id(new AphrontFormTokenizerControl())
->setLabel(pht('Tags'))
->setName('projects')
->setValue($v_projects)
->setDatasource(new PhabricatorProjectDatasource()));
if ($is_new) {
for ($ii = 0; $ii < 10; $ii++) {
$n = ($ii + 1);
$response = id(new AphrontFormTextControl())
->setLabel(pht('Response %d', $n))
->setName('response[]')
->setValue(idx($responses, $ii, ''));
if ($ii == 0) {
$response->setError($e_response);
}
$form->appendChild($response);
}
}
$poll_type_options = array(
PhabricatorSlowvotePoll::METHOD_PLURALITY =>
pht('Plurality (Single Choice)'),
PhabricatorSlowvotePoll::METHOD_APPROVAL =>
pht('Approval (Multiple Choice)'),
);
$response_type_map = SlowvotePollResponseVisibility::getAll();
$response_type_options = mpull($response_type_map, 'getNameForEdit');
+ $visibility = $poll->getResponseVisibility();
+ if (!isset($response_type_options[$visibility])) {
+ $visibility_object =
+ SlowvotePollResponseVisibility::newResponseVisibilityObject(
+ $visibility);
+
+ $response_type_options = array(
+ $visibility => $visibility_object->getNameForEdit(),
+ ) + $response_type_options;
+ }
+
if ($is_new) {
$form->appendChild(
id(new AphrontFormSelectControl())
->setLabel(pht('Vote Type'))
->setName('method')
->setValue($poll->getMethod())
->setOptions($poll_type_options));
} else {
$form->appendChild(
id(new AphrontFormStaticControl())
->setLabel(pht('Vote Type'))
->setValue(idx($poll_type_options, $poll->getMethod())));
}
if ($is_new) {
$title = pht('Create Slowvote');
$button = pht('Create');
$cancel_uri = $this->getApplicationURI();
$header_icon = 'fa-plus-square';
} else {
$title = pht('Edit Poll: %s', $poll->getQuestion());
$button = pht('Save Changes');
$cancel_uri = '/V'.$poll->getID();
$header_icon = 'fa-pencil';
}
$policies = id(new PhabricatorPolicyQuery())
->setViewer($viewer)
->setObject($poll)
->execute();
$form
->appendChild(
id(new AphrontFormSelectControl())
->setLabel(pht('Responses'))
->setName('responses')
->setValue($v_responses)
->setOptions($response_type_options))
->appendChild(
id(new AphrontFormCheckboxControl())
->setLabel(pht('Shuffle'))
->addCheckbox(
'shuffle',
1,
pht('Show choices in random order.'),
$v_shuffle))
->appendChild(
id(new AphrontFormPolicyControl())
->setUser($viewer)
->setName('viewPolicy')
->setPolicyObject($poll)
->setPolicies($policies)
->setCapability(PhabricatorPolicyCapability::CAN_VIEW)
->setSpacePHID($v_space))
->appendChild(
id(new AphrontFormSubmitControl())
->setValue($button)
->addCancelButton($cancel_uri));
$crumbs = $this->buildApplicationCrumbs();
$crumbs->addTextCrumb($title);
$crumbs->setBorder(true);
$form_box = id(new PHUIObjectBoxView())
->setHeaderText($title)
->setFormErrors($errors)
->setBackground(PHUIObjectBoxView::WHITE_CONFIG)
->setForm($form);
$view = id(new PHUITwoColumnView())
->setFooter($form_box);
return $this->newPage()
->setTitle($title)
->setCrumbs($crumbs)
->appendChild(
array(
$view,
));
}
}
diff --git a/src/applications/slowvote/storage/PhabricatorSlowvotePoll.php b/src/applications/slowvote/storage/PhabricatorSlowvotePoll.php
index 166c461a86..1e57181cf5 100644
--- a/src/applications/slowvote/storage/PhabricatorSlowvotePoll.php
+++ b/src/applications/slowvote/storage/PhabricatorSlowvotePoll.php
@@ -1,223 +1,223 @@
<?php
final class PhabricatorSlowvotePoll
extends PhabricatorSlowvoteDAO
implements
PhabricatorApplicationTransactionInterface,
PhabricatorPolicyInterface,
PhabricatorSubscribableInterface,
PhabricatorFlaggableInterface,
PhabricatorTokenReceiverInterface,
PhabricatorProjectInterface,
PhabricatorDestructibleInterface,
PhabricatorSpacesInterface,
PhabricatorConduitResultInterface {
const METHOD_PLURALITY = 0;
const METHOD_APPROVAL = 1;
protected $question;
protected $description;
protected $authorPHID;
protected $responseVisibility;
protected $shuffle = 0;
protected $method;
protected $viewPolicy;
protected $isClosed = 0;
protected $spacePHID;
private $options = self::ATTACHABLE;
private $choices = self::ATTACHABLE;
private $viewerChoices = self::ATTACHABLE;
public static function initializeNewPoll(PhabricatorUser $actor) {
$app = id(new PhabricatorApplicationQuery())
->setViewer($actor)
->withClasses(array('PhabricatorSlowvoteApplication'))
->executeOne();
$view_policy = $app->getPolicy(
PhabricatorSlowvoteDefaultViewCapability::CAPABILITY);
$default_responses = SlowvotePollResponseVisibility::RESPONSES_VISIBLE;
return id(new PhabricatorSlowvotePoll())
->setAuthorPHID($actor->getPHID())
->setViewPolicy($view_policy)
->setSpacePHID($actor->getDefaultSpacePHID())
->setResponseVisibility($default_responses);
}
protected function getConfiguration() {
return array(
self::CONFIG_AUX_PHID => true,
self::CONFIG_COLUMN_SCHEMA => array(
'question' => 'text255',
- 'responseVisibility' => 'uint32',
+ 'responseVisibility' => 'text32',
'shuffle' => 'bool',
'method' => 'uint32',
'description' => 'text',
'isClosed' => 'bool',
),
self::CONFIG_KEY_SCHEMA => array(
),
) + parent::getConfiguration();
}
public function getPHIDType() {
return PhabricatorSlowvotePollPHIDType::TYPECONST;
}
public function getOptions() {
return $this->assertAttached($this->options);
}
public function attachOptions(array $options) {
assert_instances_of($options, 'PhabricatorSlowvoteOption');
$this->options = $options;
return $this;
}
public function getChoices() {
return $this->assertAttached($this->choices);
}
public function attachChoices(array $choices) {
assert_instances_of($choices, 'PhabricatorSlowvoteChoice');
$this->choices = $choices;
return $this;
}
public function getViewerChoices(PhabricatorUser $viewer) {
return $this->assertAttachedKey($this->viewerChoices, $viewer->getPHID());
}
public function attachViewerChoices(PhabricatorUser $viewer, array $choices) {
if ($this->viewerChoices === self::ATTACHABLE) {
$this->viewerChoices = array();
}
assert_instances_of($choices, 'PhabricatorSlowvoteChoice');
$this->viewerChoices[$viewer->getPHID()] = $choices;
return $this;
}
public function getMonogram() {
return 'V'.$this->getID();
}
public function getURI() {
return '/'.$this->getMonogram();
}
/* -( PhabricatorApplicationTransactionInterface )------------------------- */
public function getApplicationTransactionEditor() {
return new PhabricatorSlowvoteEditor();
}
public function getApplicationTransactionTemplate() {
return new PhabricatorSlowvoteTransaction();
}
/* -( PhabricatorPolicyInterface )----------------------------------------- */
public function getCapabilities() {
return array(
PhabricatorPolicyCapability::CAN_VIEW,
PhabricatorPolicyCapability::CAN_EDIT,
);
}
public function getPolicy($capability) {
switch ($capability) {
case PhabricatorPolicyCapability::CAN_VIEW:
return $this->viewPolicy;
case PhabricatorPolicyCapability::CAN_EDIT:
return PhabricatorPolicies::POLICY_NOONE;
}
}
public function hasAutomaticCapability($capability, PhabricatorUser $viewer) {
return ($viewer->getPHID() == $this->getAuthorPHID());
}
public function describeAutomaticCapability($capability) {
return pht('The author of a poll can always view and edit it.');
}
/* -( PhabricatorSubscribableInterface )----------------------------------- */
public function isAutomaticallySubscribed($phid) {
return ($phid == $this->getAuthorPHID());
}
/* -( PhabricatorTokenReceiverInterface )---------------------------------- */
public function getUsersToNotifyOfTokenGiven() {
return array($this->getAuthorPHID());
}
/* -( PhabricatorDestructibleInterface )----------------------------------- */
public function destroyObjectPermanently(
PhabricatorDestructionEngine $engine) {
$this->openTransaction();
$choices = id(new PhabricatorSlowvoteChoice())->loadAllWhere(
'pollID = %d',
$this->getID());
foreach ($choices as $choice) {
$choice->delete();
}
$options = id(new PhabricatorSlowvoteOption())->loadAllWhere(
'pollID = %d',
$this->getID());
foreach ($options as $option) {
$option->delete();
}
$this->delete();
$this->saveTransaction();
}
/* -( PhabricatorSpacesInterface )----------------------------------------- */
public function getSpacePHID() {
return $this->spacePHID;
}
/* -( PhabricatorConduitResultInterface )---------------------------------- */
public function getFieldSpecificationsForConduit() {
return array(
id(new PhabricatorConduitSearchFieldSpecification())
->setKey('name')
->setType('string')
->setDescription(pht('The name of the poll.')),
id(new PhabricatorConduitSearchFieldSpecification())
->setKey('authorPHID')
->setType('string')
->setDescription(pht('The author of the poll.')),
);
}
public function getFieldValuesForConduit() {
return array(
'name' => $this->getQuestion(),
'authorPHID' => $this->getAuthorPHID(),
);
}
public function getConduitSearchAttachments() {
return array();
}
}
diff --git a/src/applications/slowvote/view/SlowvoteEmbedView.php b/src/applications/slowvote/view/SlowvoteEmbedView.php
index 240bfed2d4..6164024148 100644
--- a/src/applications/slowvote/view/SlowvoteEmbedView.php
+++ b/src/applications/slowvote/view/SlowvoteEmbedView.php
@@ -1,339 +1,339 @@
<?php
final class SlowvoteEmbedView extends AphrontView {
private $poll;
private $handles;
public function setPoll(PhabricatorSlowvotePoll $poll) {
$this->poll = $poll;
return $this;
}
public function getPoll() {
return $this->poll;
}
public function render() {
if (!$this->poll) {
throw new PhutilInvalidStateException('setPoll');
}
$poll = $this->poll;
$phids = array();
foreach ($poll->getChoices() as $choice) {
$phids[] = $choice->getAuthorPHID();
}
$phids[] = $poll->getAuthorPHID();
$this->handles = id(new PhabricatorHandleQuery())
->setViewer($this->getUser())
->withPHIDs($phids)
->execute();
$options = $poll->getOptions();
if ($poll->getShuffle()) {
shuffle($options);
}
require_celerity_resource('phabricator-slowvote-css');
$user_choices = $poll->getViewerChoices($this->getUser());
$user_choices = mpull($user_choices, 'getOptionID', 'getOptionID');
$out = array();
foreach ($options as $option) {
$is_selected = isset($user_choices[$option->getID()]);
$out[] = $this->renderLabel($option, $is_selected);
}
$link_to_slowvote = phutil_tag(
'a',
array(
'href' => '/V'.$poll->getID(),
),
$poll->getQuestion());
$header = id(new PHUIHeaderView())
->setHeader($link_to_slowvote);
$description = $poll->getDescription();
if (strlen($description)) {
$description = new PHUIRemarkupView($this->getUser(), $description);
$description = phutil_tag(
'div',
array(
'class' => 'slowvote-description',
),
$description);
}
$header = array(
$header,
$description,
);
+ $quip = pht('Voting improves cardiovascular endurance.');
+
$vis = $poll->getResponseVisibility();
if ($this->areResultsVisible()) {
if ($vis == SlowvotePollResponseVisibility::RESPONSES_OWNER) {
$quip = pht('Only you can see the results.');
- } else {
- $quip = pht('Voting improves cardiovascular endurance.');
}
} else if ($vis == SlowvotePollResponseVisibility::RESPONSES_VOTERS) {
$quip = pht('You must vote to see the results.');
} else if ($vis == SlowvotePollResponseVisibility::RESPONSES_OWNER) {
$quip = pht('Only the author can see the results.');
}
$hint = phutil_tag(
'span',
array(
'class' => 'slowvote-hint',
),
$quip);
if ($poll->getIsClosed()) {
$submit = null;
} else {
$submit = phutil_tag(
'div',
array(
'class' => 'slowvote-footer',
),
phutil_tag(
'div',
array(
'class' => 'slowvote-footer-content',
),
array(
$hint,
phutil_tag(
'button',
array(
),
pht('Engage in Deliberations')),
)));
}
$body = phabricator_form(
$this->getUser(),
array(
'action' => '/vote/'.$poll->getID().'/',
'method' => 'POST',
'class' => 'slowvote-body',
),
array(
phutil_tag(
'div',
array(
'class' => 'slowvote-body-content',
),
$out),
$submit,
));
$embed = javelin_tag(
'div',
array(
'class' => 'slowvote-embed',
'sigil' => 'slowvote-embed',
'meta' => array(
'pollID' => $poll->getID(),
),
),
array($body));
return id(new PHUIObjectBoxView())
->setBackground(PHUIObjectBoxView::BLUE_PROPERTY)
->setHeader($header)
->appendChild($embed)
->addClass('slowvote-poll-view');
}
private function renderLabel(PhabricatorSlowvoteOption $option, $selected) {
$classes = array();
$classes[] = 'slowvote-option-label';
$status = $this->renderStatus($option);
$voters = $this->renderVoters($option);
return phutil_tag(
'div',
array(
'class' => 'slowvote-option-label-group',
),
array(
phutil_tag(
'label',
array(
'class' => implode(' ', $classes),
),
array(
phutil_tag(
'div',
array(
'class' => 'slowvote-control-offset',
),
$option->getName()),
$this->renderBar($option),
phutil_tag(
'div',
array(
'class' => 'slowvote-above-the-bar',
),
array(
$this->renderControl($option, $selected),
$status,
)),
)),
$voters,
));
}
private function renderBar(PhabricatorSlowvoteOption $option) {
if (!$this->areResultsVisible()) {
return null;
}
$poll = $this->getPoll();
$choices = mgroup($poll->getChoices(), 'getOptionID');
$choices = count(idx($choices, $option->getID(), array()));
$count = count(mgroup($poll->getChoices(), 'getAuthorPHID'));
return phutil_tag(
'div',
array(
'class' => 'slowvote-bar',
'style' => sprintf(
'width: %.1f%%;',
$count ? 100 * ($choices / $count) : 0),
),
array(
phutil_tag(
'div',
array(
'class' => 'slowvote-control-offset',
),
$option->getName()),
));
}
private function renderControl(PhabricatorSlowvoteOption $option, $selected) {
$types = array(
PhabricatorSlowvotePoll::METHOD_PLURALITY => 'radio',
PhabricatorSlowvotePoll::METHOD_APPROVAL => 'checkbox',
);
$closed = $this->getPoll()->getIsClosed();
return phutil_tag(
'input',
array(
'type' => idx($types, $this->getPoll()->getMethod()),
'name' => 'vote[]',
'value' => $option->getID(),
'checked' => ($selected ? 'checked' : null),
'disabled' => ($closed ? 'disabled' : null),
));
}
private function renderVoters(PhabricatorSlowvoteOption $option) {
if (!$this->areResultsVisible()) {
return null;
}
$poll = $this->getPoll();
$choices = mgroup($poll->getChoices(), 'getOptionID');
$choices = idx($choices, $option->getID(), array());
if (!$choices) {
return null;
}
$handles = $this->handles;
$authors = mpull($choices, 'getAuthorPHID', 'getAuthorPHID');
$viewer_phid = $this->getUser()->getPHID();
// Put the viewer first if they've voted for this option.
$authors = array_select_keys($authors, array($viewer_phid))
+ $authors;
$voters = array();
foreach ($authors as $author_phid) {
$handle = $handles[$author_phid];
$voters[] = javelin_tag(
'div',
array(
'class' => 'slowvote-voter',
'style' => 'background-image: url('.$handle->getImageURI().')',
'sigil' => 'has-tooltip',
'meta' => array(
'tip' => $handle->getName(),
),
));
}
return phutil_tag(
'div',
array(
'class' => 'slowvote-voters',
),
$voters);
}
private function renderStatus(PhabricatorSlowvoteOption $option) {
if (!$this->areResultsVisible()) {
return null;
}
$poll = $this->getPoll();
$choices = mgroup($poll->getChoices(), 'getOptionID');
$choices = count(idx($choices, $option->getID(), array()));
$count = count(mgroup($poll->getChoices(), 'getAuthorPHID'));
$percent = sprintf('%d%%', $count ? 100 * $choices / $count : 0);
switch ($poll->getMethod()) {
case PhabricatorSlowvotePoll::METHOD_PLURALITY:
$status = pht('%s (%d / %d)', $percent, $choices, $count);
break;
case PhabricatorSlowvotePoll::METHOD_APPROVAL:
$status = pht('%s Approval (%d / %d)', $percent, $choices, $count);
break;
}
return phutil_tag(
'div',
array(
'class' => 'slowvote-status',
),
$status);
}
private function areResultsVisible() {
$poll = $this->getPoll();
$visibility = $poll->getResponseVisibility();
if ($visibility == SlowvotePollResponseVisibility::RESPONSES_VISIBLE) {
return true;
}
$viewer = $this->getViewer();
if ($visibility == SlowvotePollResponseVisibility::RESPONSES_OWNER) {
return ($poll->getAuthorPHID() === $viewer->getPHID());
}
$choices = mgroup($poll->getChoices(), 'getAuthorPHID');
return (bool)idx($choices, $viewer->getPHID());
}
}
diff --git a/src/applications/slowvote/xaction/PhabricatorSlowvoteResponsesTransaction.php b/src/applications/slowvote/xaction/PhabricatorSlowvoteResponsesTransaction.php
index e23f6e7bed..ad18d1055e 100644
--- a/src/applications/slowvote/xaction/PhabricatorSlowvoteResponsesTransaction.php
+++ b/src/applications/slowvote/xaction/PhabricatorSlowvoteResponsesTransaction.php
@@ -1,51 +1,55 @@
<?php
final class PhabricatorSlowvoteResponsesTransaction
extends PhabricatorSlowvoteTransactionType {
const TRANSACTIONTYPE = 'vote:responses';
public function generateOldValue($object) {
- return $object->getResponseVisibility();
+ return (string)$object->getResponseVisibility();
+ }
+
+ public function generateNewValue($object, $value) {
+ return (string)$value;
}
public function applyInternalEffects($object, $value) {
$object->setResponseVisibility($value);
}
public function getTitle() {
$old_name = $this->getOldResponseVisibilityObject()->getName();
$new_name = $this->getNewResponseVisibilityObject()->getName();
return pht(
'%s changed who can see the responses from %s to %s.',
$this->renderAuthor(),
$this->renderValue($old_name),
$this->renderValue($new_name));
}
public function getTitleForFeed() {
$old_name = $this->getOldResponseVisibilityObject()->getName();
$new_name = $this->getNewResponseVisibilityObject()->getName();
return pht(
'%s changed who can see the responses of %s from %s to %s.',
$this->renderAuthor(),
$this->renderObject(),
$this->renderValue($old_name),
$this->renderValue($new_name));
}
private function getOldResponseVisibilityObject() {
return $this->newResponseVisibilityObject($this->getOldValue());
}
private function getNewResponseVisibilityObject() {
return $this->newResponseVisibilityObject($this->getNewValue());
}
private function newResponseVisibilityObject($value) {
return SlowvotePollResponseVisibility::newResponseVisibilityObject($value);
}
}

File Metadata

Mime Type
text/x-diff
Expires
Sun, Nov 24, 2:47 PM (1 d, 14 h)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
1034
Default Alt Text
(31 KB)

Event Timeline