3 final class PhabricatorSlowvotePoll
4 extends PhabricatorSlowvoteDAO
6 PhabricatorApplicationTransactionInterface
,
7 PhabricatorPolicyInterface
,
8 PhabricatorSubscribableInterface
,
9 PhabricatorFlaggableInterface
,
10 PhabricatorTokenReceiverInterface
,
11 PhabricatorProjectInterface
,
12 PhabricatorDestructibleInterface
,
13 PhabricatorSpacesInterface
,
14 PhabricatorConduitResultInterface
{
17 protected $description;
18 protected $authorPHID;
19 protected $responseVisibility;
20 protected $shuffle = 0;
22 protected $viewPolicy;
26 private $options = self
::ATTACHABLE
;
27 private $choices = self
::ATTACHABLE
;
28 private $viewerChoices = self
::ATTACHABLE
;
30 public static function initializeNewPoll(PhabricatorUser
$actor) {
31 $app = id(new PhabricatorApplicationQuery())
33 ->withClasses(array('PhabricatorSlowvoteApplication'))
36 $view_policy = $app->getPolicy(
37 PhabricatorSlowvoteDefaultViewCapability
::CAPABILITY
);
39 $default_responses = SlowvotePollResponseVisibility
::RESPONSES_VISIBLE
;
40 $default_method = SlowvotePollVotingMethod
::METHOD_PLURALITY
;
42 return id(new PhabricatorSlowvotePoll())
43 ->setAuthorPHID($actor->getPHID())
44 ->setViewPolicy($view_policy)
45 ->setSpacePHID($actor->getDefaultSpacePHID())
46 ->setStatus(SlowvotePollStatus
::STATUS_OPEN
)
47 ->setMethod($default_method)
48 ->setResponseVisibility($default_responses);
51 protected function getConfiguration() {
53 self
::CONFIG_AUX_PHID
=> true,
54 self
::CONFIG_COLUMN_SCHEMA
=> array(
55 'question' => 'text255',
56 'responseVisibility' => 'text32',
59 'description' => 'text',
62 self
::CONFIG_KEY_SCHEMA
=> array(
64 ) + parent
::getConfiguration();
67 public function getPHIDType() {
68 return PhabricatorSlowvotePollPHIDType
::TYPECONST
;
71 public function getStatusObject() {
72 return SlowvotePollStatus
::newStatusObject($this->getStatus());
75 public function isClosed() {
76 return ($this->getStatus() == SlowvotePollStatus
::STATUS_CLOSED
);
79 public function getOptions() {
80 return $this->assertAttached($this->options
);
83 public function attachOptions(array $options) {
84 assert_instances_of($options, 'PhabricatorSlowvoteOption');
85 $this->options
= $options;
89 public function getChoices() {
90 return $this->assertAttached($this->choices
);
93 public function attachChoices(array $choices) {
94 assert_instances_of($choices, 'PhabricatorSlowvoteChoice');
95 $this->choices
= $choices;
99 public function getViewerChoices(PhabricatorUser
$viewer) {
100 return $this->assertAttachedKey($this->viewerChoices
, $viewer->getPHID());
103 public function attachViewerChoices(PhabricatorUser
$viewer, array $choices) {
104 if ($this->viewerChoices
=== self
::ATTACHABLE
) {
105 $this->viewerChoices
= array();
107 assert_instances_of($choices, 'PhabricatorSlowvoteChoice');
108 $this->viewerChoices
[$viewer->getPHID()] = $choices;
112 public function getMonogram() {
113 return 'V'.$this->getID();
116 public function getURI() {
117 return '/'.$this->getMonogram();
121 /* -( PhabricatorApplicationTransactionInterface )------------------------- */
124 public function getApplicationTransactionEditor() {
125 return new PhabricatorSlowvoteEditor();
128 public function getApplicationTransactionTemplate() {
129 return new PhabricatorSlowvoteTransaction();
133 /* -( PhabricatorPolicyInterface )----------------------------------------- */
136 public function getCapabilities() {
138 PhabricatorPolicyCapability
::CAN_VIEW
,
139 PhabricatorPolicyCapability
::CAN_EDIT
,
143 public function getPolicy($capability) {
144 switch ($capability) {
145 case PhabricatorPolicyCapability
::CAN_VIEW
:
146 return $this->viewPolicy
;
147 case PhabricatorPolicyCapability
::CAN_EDIT
:
148 return PhabricatorPolicies
::POLICY_NOONE
;
152 public function hasAutomaticCapability($capability, PhabricatorUser
$viewer) {
153 return ($viewer->getPHID() == $this->getAuthorPHID());
156 public function describeAutomaticCapability($capability) {
157 return pht('The author of a poll can always view and edit it.');
162 /* -( PhabricatorSubscribableInterface )----------------------------------- */
165 public function isAutomaticallySubscribed($phid) {
166 return ($phid == $this->getAuthorPHID());
170 /* -( PhabricatorTokenReceiverInterface )---------------------------------- */
173 public function getUsersToNotifyOfTokenGiven() {
174 return array($this->getAuthorPHID());
177 /* -( PhabricatorDestructibleInterface )----------------------------------- */
179 public function destroyObjectPermanently(
180 PhabricatorDestructionEngine
$engine) {
182 $this->openTransaction();
183 $choices = id(new PhabricatorSlowvoteChoice())->loadAllWhere(
186 foreach ($choices as $choice) {
189 $options = id(new PhabricatorSlowvoteOption())->loadAllWhere(
192 foreach ($options as $option) {
196 $this->saveTransaction();
199 /* -( PhabricatorSpacesInterface )----------------------------------------- */
201 public function getSpacePHID() {
202 return $this->spacePHID
;
205 /* -( PhabricatorConduitResultInterface )---------------------------------- */
207 public function getFieldSpecificationsForConduit() {
209 id(new PhabricatorConduitSearchFieldSpecification())
212 ->setDescription(pht('The name of the poll.')),
213 id(new PhabricatorConduitSearchFieldSpecification())
214 ->setKey('authorPHID')
216 ->setDescription(pht('The author of the poll.')),
220 public function getFieldValuesForConduit() {
222 'name' => $this->getQuestion(),
223 'authorPHID' => $this->getAuthorPHID(),
227 public function getConduitSearchAttachments() {