2011-07-08 11:13:11 -07:00
|
|
|
<?php
|
|
|
|
|
2011-09-14 08:02:31 -07:00
|
|
|
/**
|
|
|
|
* @group slowvote
|
|
|
|
*/
|
2013-07-13 10:41:30 -07:00
|
|
|
final class PhabricatorSlowvotePoll extends PhabricatorSlowvoteDAO
|
2013-07-15 05:21:36 -07:00
|
|
|
implements
|
|
|
|
PhabricatorPolicyInterface,
|
2013-07-15 06:19:50 -07:00
|
|
|
PhabricatorSubscribableInterface,
|
|
|
|
PhabricatorTokenReceiverInterface {
|
2011-07-08 11:13:11 -07:00
|
|
|
|
|
|
|
const RESPONSES_VISIBLE = 0;
|
|
|
|
const RESPONSES_VOTERS = 1;
|
|
|
|
const RESPONSES_OWNER = 2;
|
|
|
|
|
|
|
|
const METHOD_PLURALITY = 0;
|
|
|
|
const METHOD_APPROVAL = 1;
|
|
|
|
|
|
|
|
protected $question;
|
2013-07-14 16:02:04 -07:00
|
|
|
protected $description;
|
2011-07-08 11:13:11 -07:00
|
|
|
protected $authorPHID;
|
|
|
|
protected $responseVisibility;
|
|
|
|
protected $shuffle;
|
|
|
|
protected $method;
|
2013-07-14 16:02:04 -07:00
|
|
|
protected $viewPolicy;
|
2011-07-08 11:13:11 -07:00
|
|
|
|
2013-09-03 06:02:14 -07:00
|
|
|
private $options = self::ATTACHABLE;
|
|
|
|
private $choices = self::ATTACHABLE;
|
|
|
|
private $viewerChoices = self::ATTACHABLE;
|
2013-07-15 06:09:37 -07:00
|
|
|
|
2013-10-16 10:36:00 -07:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2011-07-08 11:13:11 -07:00
|
|
|
public function getConfiguration() {
|
|
|
|
return array(
|
|
|
|
self::CONFIG_AUX_PHID => true,
|
|
|
|
) + parent::getConfiguration();
|
|
|
|
}
|
|
|
|
|
|
|
|
public function generatePHID() {
|
|
|
|
return PhabricatorPHID::generateNewPHID(
|
2013-07-21 06:34:21 -07:00
|
|
|
PhabricatorSlowvotePHIDTypePoll::TYPECONST);
|
2011-07-08 11:13:11 -07:00
|
|
|
}
|
|
|
|
|
2013-07-15 06:09:37 -07:00
|
|
|
public function getOptions() {
|
2013-09-03 06:02:14 -07:00
|
|
|
return $this->assertAttached($this->options);
|
2013-07-15 06:09:37 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
public function attachOptions(array $options) {
|
|
|
|
assert_instances_of($options, 'PhabricatorSlowvoteOption');
|
|
|
|
$this->options = $options;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getChoices() {
|
2013-09-03 06:02:14 -07:00
|
|
|
return $this->assertAttached($this->choices);
|
2013-07-15 06:09:37 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
public function attachChoices(array $choices) {
|
|
|
|
assert_instances_of($choices, 'PhabricatorSlowvoteChoice');
|
|
|
|
$this->choices = $choices;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getViewerChoices(PhabricatorUser $viewer) {
|
2013-09-03 06:02:14 -07:00
|
|
|
return $this->assertAttachedKey($this->viewerChoices, $viewer->getPHID());
|
2013-07-15 06:09:37 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
public function attachViewerChoices(PhabricatorUser $viewer, array $choices) {
|
2013-09-03 06:02:14 -07:00
|
|
|
if ($this->viewerChoices === self::ATTACHABLE) {
|
|
|
|
$this->viewerChoices = array();
|
|
|
|
}
|
2013-07-15 13:18:50 -07:00
|
|
|
assert_instances_of($choices, 'PhabricatorSlowvoteChoice');
|
2013-07-15 06:09:37 -07:00
|
|
|
$this->viewerChoices[$viewer->getPHID()] = $choices;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
2013-07-13 10:41:30 -07:00
|
|
|
|
|
|
|
/* -( PhabricatorPolicyInterface )----------------------------------------- */
|
|
|
|
|
|
|
|
|
|
|
|
public function getCapabilities() {
|
|
|
|
return array(
|
|
|
|
PhabricatorPolicyCapability::CAN_VIEW,
|
|
|
|
PhabricatorPolicyCapability::CAN_EDIT,
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getPolicy($capability) {
|
2013-07-14 16:02:04 -07:00
|
|
|
switch ($capability) {
|
|
|
|
case PhabricatorPolicyCapability::CAN_VIEW:
|
|
|
|
return $this->viewPolicy;
|
|
|
|
case PhabricatorPolicyCapability::CAN_EDIT:
|
|
|
|
return PhabricatorPolicies::POLICY_NOONE;
|
|
|
|
}
|
2013-07-13 10:41:30 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
public function hasAutomaticCapability($capability, PhabricatorUser $viewer) {
|
|
|
|
return ($viewer->getPHID() == $this->getAuthorPHID());
|
|
|
|
}
|
|
|
|
|
2013-09-27 08:43:41 -07:00
|
|
|
public function describeAutomaticCapability($capability) {
|
|
|
|
return pht(
|
|
|
|
'The author of a poll can always view and edit it.');
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-07-15 05:21:36 -07:00
|
|
|
|
|
|
|
/* -( PhabricatorSubscribableInterface )----------------------------------- */
|
|
|
|
|
|
|
|
|
|
|
|
public function isAutomaticallySubscribed($phid) {
|
|
|
|
return ($phid == $this->getAuthorPHID());
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-07-15 06:19:50 -07:00
|
|
|
/* -( PhabricatorTokenReceiverInterface )---------------------------------- */
|
|
|
|
|
|
|
|
|
|
|
|
public function getUsersToNotifyOfTokenGiven() {
|
|
|
|
return array($this->getAuthorPHID());
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-07-08 11:13:11 -07:00
|
|
|
}
|