Page MenuHomestyx hydra

No OneTemporary

diff --git a/src/applications/slowvote/controller/PhabricatorSlowvoteEditController.php b/src/applications/slowvote/controller/PhabricatorSlowvoteEditController.php
index 9b41276874..a5353f174b 100644
--- a/src/applications/slowvote/controller/PhabricatorSlowvoteEditController.php
+++ b/src/applications/slowvote/controller/PhabricatorSlowvoteEditController.php
@@ -1,257 +1,285 @@
<?php
/**
* @group slowvote
*/
final class PhabricatorSlowvoteEditController
extends PhabricatorSlowvoteController {
private $id;
public function willProcessRequest(array $data) {
$this->id = idx($data, 'id');
}
public function processRequest() {
$request = $this->getRequest();
$user = $request->getUser();
if ($this->id) {
$poll = id(new PhabricatorSlowvoteQuery())
->setViewer($user)
->withIDs(array($this->id))
->requireCapabilities(
array(
PhabricatorPolicyCapability::CAN_VIEW,
PhabricatorPolicyCapability::CAN_EDIT,
))
->executeOne();
if (!$poll) {
return new Aphront404Response();
}
$is_new = false;
} else {
$poll = PhabricatorSlowvotePoll::initializeNewPoll($user);
$is_new = true;
}
+ if ($is_new) {
+ $v_projects = array();
+ } else {
+ $v_projects = PhabricatorEdgeQuery::loadDestinationPHIDs(
+ $poll->getPHID(),
+ PhabricatorEdgeConfig::TYPE_OBJECT_HAS_PROJECT);
+ $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();
$responses = $request->getArr('response');
if ($request->isFormPost()) {
$v_question = $request->getStr('question');
$v_description = $request->getStr('description');
$v_responses = (int)$request->getInt('responses');
$v_shuffle = (int)$request->getBool('shuffle');
$v_view_policy = $request->getStr('viewPolicy');
+ $v_projects = $request->getArr('projects');
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) {
$responses = array_filter($responses);
if (empty($responses)) {
$errors[] = pht('You must offer at least one response.');
$e_response = pht('Required');
} else {
$e_response = null;
}
}
$xactions = array();
$template = id(new PhabricatorSlowvoteTransaction());
$xactions[] = id(clone $template)
->setTransactionType(PhabricatorSlowvoteTransaction::TYPE_QUESTION)
->setNewValue($v_question);
$xactions[] = id(clone $template)
->setTransactionType(PhabricatorSlowvoteTransaction::TYPE_DESCRIPTION)
->setNewValue($v_description);
$xactions[] = id(clone $template)
->setTransactionType(PhabricatorSlowvoteTransaction::TYPE_RESPONSES)
->setNewValue($v_responses);
$xactions[] = id(clone $template)
->setTransactionType(PhabricatorSlowvoteTransaction::TYPE_SHUFFLE)
->setNewValue($v_shuffle);
$xactions[] = id(clone $template)
->setTransactionType(PhabricatorTransactions::TYPE_VIEW_POLICY)
->setNewValue($v_view_policy);
if (empty($errors)) {
+ $proj_edge_type = PhabricatorEdgeConfig::TYPE_OBJECT_HAS_PROJECT;
+ $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($user)
->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('/V'.$poll->getID());
} else {
$poll->setViewPolicy($v_view_policy);
}
}
$instructions =
phutil_tag(
'p',
array(
'class' => 'aphront-form-instructions',
),
pht('Resolve issues and build consensus through '.
'protracted deliberation.'));
+ if ($v_projects) {
+ $project_handles = $this->loadViewerHandles($v_projects);
+ } else {
+ $project_handles = array();
+ }
+
$form = id(new AphrontFormView())
->setUser($user)
->appendChild($instructions)
->appendChild(
id(new AphrontFormTextAreaControl())
->setHeight(AphrontFormTextAreaControl::HEIGHT_VERY_SHORT)
->setLabel(pht('Question'))
->setName('question')
->setValue($v_question)
->setError($e_question))
->appendChild(
id(new PhabricatorRemarkupControl())
->setLabel(pht('Description'))
->setName('description')
- ->setValue($v_description));
+ ->setValue($v_description))
+ ->appendChild(
+ id(new AphrontFormTokenizerControl())
+ ->setLabel(pht('Projects'))
+ ->setName('projects')
+ ->setValue($project_handles)
+ ->setDatasource('/typeahead/common/projects/'));
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_options = array(
PhabricatorSlowvotePoll::RESPONSES_VISIBLE
=> pht('Allow anyone to see the responses'),
PhabricatorSlowvotePoll::RESPONSES_VOTERS
=> pht('Require a vote to see the responses'),
PhabricatorSlowvotePoll::RESPONSES_OWNER
=> pht('Only I can see the responses'),
);
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();
} else {
$title = pht('Edit %s', 'V'.$poll->getID());
$button = pht('Save Changes');
$cancel_uri = '/V'.$poll->getID();
}
$policies = id(new PhabricatorPolicyQuery())
->setViewer($user)
->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($user)
->setName('viewPolicy')
->setPolicyObject($poll)
->setPolicies($policies)
->setCapability(PhabricatorPolicyCapability::CAN_VIEW))
->appendChild(
id(new AphrontFormSubmitControl())
->setValue($button)
->addCancelButton($cancel_uri));
$crumbs = $this->buildApplicationCrumbs($this->buildSideNavView());
$crumbs->addTextCrumb($title);
$form_box = id(new PHUIObjectBoxView())
->setHeaderText($title)
->setFormErrors($errors)
->setForm($form);
return $this->buildApplicationPage(
array(
$crumbs,
$form_box,
),
array(
'title' => $title,
));
}
}
diff --git a/src/applications/slowvote/editor/PhabricatorSlowvoteEditor.php b/src/applications/slowvote/editor/PhabricatorSlowvoteEditor.php
index 9d85cfe949..bef46d517a 100644
--- a/src/applications/slowvote/editor/PhabricatorSlowvoteEditor.php
+++ b/src/applications/slowvote/editor/PhabricatorSlowvoteEditor.php
@@ -1,106 +1,108 @@
<?php
final class PhabricatorSlowvoteEditor
extends PhabricatorApplicationTransactionEditor {
public function getTransactionTypes() {
$types = parent::getTransactionTypes();
$types[] = PhabricatorTransactions::TYPE_COMMENT;
$types[] = PhabricatorTransactions::TYPE_VIEW_POLICY;
$types[] = PhabricatorSlowvoteTransaction::TYPE_QUESTION;
$types[] = PhabricatorSlowvoteTransaction::TYPE_DESCRIPTION;
$types[] = PhabricatorSlowvoteTransaction::TYPE_RESPONSES;
$types[] = PhabricatorSlowvoteTransaction::TYPE_SHUFFLE;
$types[] = PhabricatorSlowvoteTransaction::TYPE_CLOSE;
return $types;
}
protected function transactionHasEffect(
PhabricatorLiskDAO $object,
PhabricatorApplicationTransaction $xaction) {
$old = $xaction->getOldValue();
$new = $xaction->getNewValue();
switch ($xaction->getTransactionType()) {
case PhabricatorSlowvoteTransaction::TYPE_RESPONSES:
if ($old === null) {
return true;
}
return ((int)$old !== (int)$new);
case PhabricatorSlowvoteTransaction::TYPE_SHUFFLE:
if ($old === null) {
return true;
}
return ((bool)$old !== (bool)$new);
}
return parent::transactionHasEffect($object, $xaction);
}
protected function getCustomTransactionOldValue(
PhabricatorLiskDAO $object,
PhabricatorApplicationTransaction $xaction) {
switch ($xaction->getTransactionType()) {
case PhabricatorSlowvoteTransaction::TYPE_QUESTION:
return $object->getQuestion();
case PhabricatorSlowvoteTransaction::TYPE_DESCRIPTION:
return $object->getDescription();
case PhabricatorSlowvoteTransaction::TYPE_RESPONSES:
return $object->getResponseVisibility();
case PhabricatorSlowvoteTransaction::TYPE_SHUFFLE:
return $object->getShuffle();
case PhabricatorSlowvoteTransaction::TYPE_CLOSE:
return $object->getIsClosed();
}
}
protected function getCustomTransactionNewValue(
PhabricatorLiskDAO $object,
PhabricatorApplicationTransaction $xaction) {
switch ($xaction->getTransactionType()) {
case PhabricatorSlowvoteTransaction::TYPE_QUESTION:
case PhabricatorSlowvoteTransaction::TYPE_DESCRIPTION:
case PhabricatorSlowvoteTransaction::TYPE_RESPONSES:
case PhabricatorSlowvoteTransaction::TYPE_SHUFFLE:
case PhabricatorSlowvoteTransaction::TYPE_CLOSE:
return $xaction->getNewValue();
}
}
protected function applyCustomInternalTransaction(
PhabricatorLiskDAO $object,
PhabricatorApplicationTransaction $xaction) {
switch ($xaction->getTransactionType()) {
case PhabricatorSlowvoteTransaction::TYPE_QUESTION:
$object->setQuestion($xaction->getNewValue());
break;
case PhabricatorSlowvoteTransaction::TYPE_DESCRIPTION:
$object->setDescription($xaction->getNewValue());
break;
case PhabricatorSlowvoteTransaction::TYPE_RESPONSES:
$object->setResponseVisibility($xaction->getNewValue());
break;
case PhabricatorSlowvoteTransaction::TYPE_SHUFFLE:
$object->setShuffle($xaction->getNewValue());
break;
case PhabricatorSlowvoteTransaction::TYPE_CLOSE:
$object->setIsClosed((int)$xaction->getNewValue());
break;
+ case PhabricatorTransactions::TYPE_EDGE:
+ return;
}
}
protected function applyCustomExternalTransaction(
PhabricatorLiskDAO $object,
PhabricatorApplicationTransaction $xaction) {
return;
}
}
diff --git a/src/applications/slowvote/storage/PhabricatorSlowvotePoll.php b/src/applications/slowvote/storage/PhabricatorSlowvotePoll.php
index ee01088246..9de418f937 100644
--- a/src/applications/slowvote/storage/PhabricatorSlowvotePoll.php
+++ b/src/applications/slowvote/storage/PhabricatorSlowvotePoll.php
@@ -1,146 +1,147 @@
<?php
/**
* @group slowvote
*/
final class PhabricatorSlowvotePoll extends PhabricatorSlowvoteDAO
implements
PhabricatorPolicyInterface,
PhabricatorSubscribableInterface,
PhabricatorFlaggableInterface,
- PhabricatorTokenReceiverInterface {
+ PhabricatorTokenReceiverInterface,
+ PhabricatorProjectInterface {
const RESPONSES_VISIBLE = 0;
const RESPONSES_VOTERS = 1;
const RESPONSES_OWNER = 2;
const METHOD_PLURALITY = 0;
const METHOD_APPROVAL = 1;
protected $question;
protected $description;
protected $authorPHID;
protected $responseVisibility;
protected $shuffle;
protected $method;
protected $viewPolicy;
protected $isClosed = 0;
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('PhabricatorApplicationSlowvote'))
->executeOne();
$view_policy = $app->getPolicy(
PhabricatorSlowvoteCapabilityDefaultView::CAPABILITY);
return id(new PhabricatorSlowvotePoll())
->setAuthorPHID($actor->getPHID())
->setViewPolicy($view_policy);
}
public function getConfiguration() {
return array(
self::CONFIG_AUX_PHID => true,
) + parent::getConfiguration();
}
public function generatePHID() {
return PhabricatorPHID::generateNewPHID(
PhabricatorSlowvotePHIDTypePoll::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;
}
/* -( 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());
}
public function shouldShowSubscribersProperty() {
return true;
}
public function shouldAllowSubscription($phid) {
return true;
}
/* -( PhabricatorTokenReceiverInterface )---------------------------------- */
public function getUsersToNotifyOfTokenGiven() {
return array($this->getAuthorPHID());
}
}

File Metadata

Mime Type
text/x-diff
Expires
Mon, Dec 1, 4:15 PM (1 d, 12 h)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
426089
Default Alt Text
(17 KB)

Event Timeline