[ Index ] |
PHP Cross Reference of Phabricator |
[Summary view] [Print] [Text view]
1 <?php 2 3 final class PonderAnswer extends PonderDAO 4 implements 5 PhabricatorMarkupInterface, 6 PonderVotableInterface, 7 PhabricatorPolicyInterface, 8 PhabricatorFlaggableInterface, 9 PhabricatorSubscribableInterface, 10 PhabricatorTokenReceiverInterface, 11 PhabricatorDestructibleInterface { 12 13 const MARKUP_FIELD_CONTENT = 'markup:content'; 14 15 protected $authorPHID; 16 protected $questionID; 17 18 protected $content; 19 protected $contentSource; 20 21 protected $voteCount; 22 private $vote; 23 private $question = self::ATTACHABLE; 24 private $comments; 25 26 private $userVotes = array(); 27 28 public function attachQuestion(PonderQuestion $question = null) { 29 $this->question = $question; 30 return $this; 31 } 32 33 public function getQuestion() { 34 return $this->assertAttached($this->question); 35 } 36 37 public function getURI() { 38 return '/Q'.$this->getQuestionID().'#A'.$this->getID(); 39 } 40 41 public function setUserVote($vote) { 42 $this->vote = $vote['data']; 43 if (!$this->vote) { 44 $this->vote = PonderVote::VOTE_NONE; 45 } 46 return $this; 47 } 48 49 public function attachUserVote($user_phid, $vote) { 50 $this->vote = $vote; 51 return $this; 52 } 53 54 public function getUserVote() { 55 return $this->vote; 56 } 57 58 public function setComments($comments) { 59 $this->comments = $comments; 60 return $this; 61 } 62 63 public function getComments() { 64 return $this->comments; 65 } 66 67 public function getConfiguration() { 68 return array( 69 self::CONFIG_AUX_PHID => true, 70 self::CONFIG_COLUMN_SCHEMA => array( 71 'voteCount' => 'sint32', 72 'content' => 'text', 73 74 // T6203/NULLABILITY 75 // This should always exist. 76 'contentSource' => 'text?', 77 ), 78 self::CONFIG_KEY_SCHEMA => array( 79 'key_phid' => null, 80 'phid' => array( 81 'columns' => array('phid'), 82 'unique' => true, 83 ), 84 'key_oneanswerperquestion' => array( 85 'columns' => array('questionID', 'authorPHID'), 86 'unique' => true, 87 ), 88 'questionID' => array( 89 'columns' => array('questionID'), 90 ), 91 'authorPHID' => array( 92 'columns' => array('authorPHID'), 93 ), 94 ), 95 ) + parent::getConfiguration(); 96 } 97 98 public function generatePHID() { 99 return PhabricatorPHID::generateNewPHID(PonderAnswerPHIDType::TYPECONST); 100 } 101 102 public function setContentSource(PhabricatorContentSource $content_source) { 103 $this->contentSource = $content_source->serialize(); 104 return $this; 105 } 106 107 public function getContentSource() { 108 return PhabricatorContentSource::newFromSerialized($this->contentSource); 109 } 110 111 public function getMarkupField() { 112 return self::MARKUP_FIELD_CONTENT; 113 } 114 115 // Markup interface 116 117 public function getMarkupFieldKey($field) { 118 $hash = PhabricatorHash::digest($this->getMarkupText($field)); 119 $id = $this->getID(); 120 return "ponder:A{$id}:{$field}:{$hash}"; 121 } 122 123 public function getMarkupText($field) { 124 return $this->getContent(); 125 } 126 127 public function newMarkupEngine($field) { 128 return PhabricatorMarkupEngine::getEngine(); 129 } 130 131 public function didMarkupText( 132 $field, 133 $output, 134 PhutilMarkupEngine $engine) { 135 return $output; 136 } 137 138 public function shouldUseMarkupCache($field) { 139 return (bool)$this->getID(); 140 } 141 142 // votable interface 143 public function getUserVoteEdgeType() { 144 return PhabricatorEdgeConfig::TYPE_VOTING_USER_HAS_ANSWER; 145 } 146 147 public function getVotablePHID() { 148 return $this->getPHID(); 149 } 150 151 152 /* -( PhabricatorPolicyInterface )----------------------------------------- */ 153 154 155 public function getCapabilities() { 156 return array( 157 PhabricatorPolicyCapability::CAN_VIEW, 158 PhabricatorPolicyCapability::CAN_EDIT, 159 ); 160 } 161 162 public function getPolicy($capability) { 163 switch ($capability) { 164 case PhabricatorPolicyCapability::CAN_VIEW: 165 return $this->getQuestion()->getPolicy($capability); 166 case PhabricatorPolicyCapability::CAN_EDIT: 167 return PhabricatorPolicies::POLICY_NOONE; 168 } 169 } 170 171 public function hasAutomaticCapability($capability, PhabricatorUser $viewer) { 172 switch ($capability) { 173 case PhabricatorPolicyCapability::CAN_VIEW: 174 if ($this->getAuthorPHID() == $viewer->getPHID()) { 175 return true; 176 } 177 return $this->getQuestion()->hasAutomaticCapability( 178 $capability, 179 $viewer); 180 case PhabricatorPolicyCapability::CAN_EDIT: 181 return ($this->getAuthorPHID() == $viewer->getPHID()); 182 } 183 } 184 185 186 public function describeAutomaticCapability($capability) { 187 $out = array(); 188 $out[] = pht('The author of an answer can always view and edit it.'); 189 switch ($capability) { 190 case PhabricatorPolicyCapability::CAN_VIEW: 191 $out[] = pht( 192 'The user who asks a question can always view the answers.'); 193 break; 194 } 195 return $out; 196 } 197 198 199 /* -( PhabricatorTokenReceiverInterface )---------------------------------- */ 200 201 202 public function getUsersToNotifyOfTokenGiven() { 203 return array( 204 $this->getAuthorPHID(), 205 ); 206 } 207 208 209 /* -( PhabricatorSubscribableInterface )----------------------------------- */ 210 211 212 public function isAutomaticallySubscribed($phid) { 213 return ($phid == $this->getAuthorPHID()); 214 } 215 216 public function shouldShowSubscribersProperty() { 217 return true; 218 } 219 220 public function shouldAllowSubscription($phid) { 221 return true; 222 } 223 224 225 /* -( PhabricatorDestructibleInterface )----------------------------------- */ 226 227 228 public function destroyObjectPermanently( 229 PhabricatorDestructionEngine $engine) { 230 231 $this->openTransaction(); 232 $this->delete(); 233 $this->saveTransaction(); 234 } 235 236 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Sun Nov 30 09:20:46 2014 | Cross-referenced by PHPXref 0.7.1 |