Changeset View
Changeset View
Standalone View
Standalone View
src/applications/ponder/storage/PonderQuestion.php
| <?php | <?php | ||||
| final class PonderQuestion extends PonderDAO | final class PonderQuestion extends PonderDAO | ||||
| implements | implements | ||||
| PhabricatorApplicationTransactionInterface, | PhabricatorApplicationTransactionInterface, | ||||
| PhabricatorMarkupInterface, | PhabricatorMarkupInterface, | ||||
| PonderVotableInterface, | |||||
| PhabricatorSubscribableInterface, | PhabricatorSubscribableInterface, | ||||
| PhabricatorFlaggableInterface, | PhabricatorFlaggableInterface, | ||||
| PhabricatorPolicyInterface, | PhabricatorPolicyInterface, | ||||
| PhabricatorTokenReceiverInterface, | PhabricatorTokenReceiverInterface, | ||||
| PhabricatorProjectInterface, | PhabricatorProjectInterface, | ||||
| PhabricatorDestructibleInterface, | PhabricatorDestructibleInterface, | ||||
| PhabricatorSpacesInterface { | PhabricatorSpacesInterface { | ||||
| const MARKUP_FIELD_CONTENT = 'markup:content'; | const MARKUP_FIELD_CONTENT = 'markup:content'; | ||||
| protected $title; | protected $title; | ||||
| protected $phid; | protected $phid; | ||||
| protected $authorPHID; | protected $authorPHID; | ||||
| protected $status; | protected $status; | ||||
| protected $content; | protected $content; | ||||
| protected $contentSource; | protected $contentSource; | ||||
| protected $viewPolicy; | protected $viewPolicy; | ||||
| protected $spacePHID; | protected $spacePHID; | ||||
| protected $voteCount; | |||||
| protected $answerCount; | protected $answerCount; | ||||
| protected $heat; | |||||
| protected $mailKey; | protected $mailKey; | ||||
| private $answers; | private $answers; | ||||
| private $vote; | |||||
| private $comments; | private $comments; | ||||
| private $projectPHIDs = self::ATTACHABLE; | private $projectPHIDs = self::ATTACHABLE; | ||||
| public static function initializeNewQuestion(PhabricatorUser $actor) { | public static function initializeNewQuestion(PhabricatorUser $actor) { | ||||
| $app = id(new PhabricatorApplicationQuery()) | $app = id(new PhabricatorApplicationQuery()) | ||||
| ->setViewer($actor) | ->setViewer($actor) | ||||
| ->withClasses(array('PhabricatorPonderApplication')) | ->withClasses(array('PhabricatorPonderApplication')) | ||||
| ->executeOne(); | ->executeOne(); | ||||
| $view_policy = $app->getPolicy( | $view_policy = $app->getPolicy( | ||||
| PonderDefaultViewCapability::CAPABILITY); | PonderDefaultViewCapability::CAPABILITY); | ||||
| return id(new PonderQuestion()) | return id(new PonderQuestion()) | ||||
| ->setAuthorPHID($actor->getPHID()) | ->setAuthorPHID($actor->getPHID()) | ||||
| ->setViewPolicy($view_policy) | ->setViewPolicy($view_policy) | ||||
| ->setStatus(PonderQuestionStatus::STATUS_OPEN) | ->setStatus(PonderQuestionStatus::STATUS_OPEN) | ||||
| ->setVoteCount(0) | |||||
| ->setAnswerCount(0) | ->setAnswerCount(0) | ||||
| ->setHeat(0.0) | |||||
| ->setSpacePHID($actor->getDefaultSpacePHID()); | ->setSpacePHID($actor->getDefaultSpacePHID()); | ||||
| } | } | ||||
| protected function getConfiguration() { | protected function getConfiguration() { | ||||
| return array( | return array( | ||||
| self::CONFIG_AUX_PHID => true, | self::CONFIG_AUX_PHID => true, | ||||
| self::CONFIG_COLUMN_SCHEMA => array( | self::CONFIG_COLUMN_SCHEMA => array( | ||||
| 'title' => 'text255', | 'title' => 'text255', | ||||
| 'voteCount' => 'sint32', | |||||
| 'status' => 'text32', | 'status' => 'text32', | ||||
| 'content' => 'text', | 'content' => 'text', | ||||
| 'heat' => 'double', | |||||
| 'answerCount' => 'uint32', | 'answerCount' => 'uint32', | ||||
| 'mailKey' => 'bytes20', | 'mailKey' => 'bytes20', | ||||
| // T6203/NULLABILITY | // T6203/NULLABILITY | ||||
| // This should always exist. | // This should always exist. | ||||
| 'contentSource' => 'text?', | 'contentSource' => 'text?', | ||||
| ), | ), | ||||
| self::CONFIG_KEY_SCHEMA => array( | self::CONFIG_KEY_SCHEMA => array( | ||||
| 'key_phid' => null, | 'key_phid' => null, | ||||
| 'phid' => array( | 'phid' => array( | ||||
| 'columns' => array('phid'), | 'columns' => array('phid'), | ||||
| 'unique' => true, | 'unique' => true, | ||||
| ), | ), | ||||
| 'authorPHID' => array( | 'authorPHID' => array( | ||||
| 'columns' => array('authorPHID'), | 'columns' => array('authorPHID'), | ||||
| ), | ), | ||||
| 'heat' => array( | |||||
| 'columns' => array('heat'), | |||||
| ), | |||||
| 'status' => array( | 'status' => array( | ||||
| 'columns' => array('status'), | 'columns' => array('status'), | ||||
| ), | ), | ||||
| ), | ), | ||||
| ) + parent::getConfiguration(); | ) + parent::getConfiguration(); | ||||
| } | } | ||||
| public function generatePHID() { | public function generatePHID() { | ||||
| return PhabricatorPHID::generateNewPHID(PonderQuestionPHIDType::TYPECONST); | return PhabricatorPHID::generateNewPHID(PonderQuestionPHIDType::TYPECONST); | ||||
| } | } | ||||
| public function setContentSource(PhabricatorContentSource $content_source) { | public function setContentSource(PhabricatorContentSource $content_source) { | ||||
| $this->contentSource = $content_source->serialize(); | $this->contentSource = $content_source->serialize(); | ||||
| return $this; | return $this; | ||||
| } | } | ||||
| public function getContentSource() { | public function getContentSource() { | ||||
| return PhabricatorContentSource::newFromSerialized($this->contentSource); | return PhabricatorContentSource::newFromSerialized($this->contentSource); | ||||
| } | } | ||||
| public function attachVotes($user_phid) { | |||||
| $qa_phids = mpull($this->answers, 'getPHID') + array($this->getPHID()); | |||||
| $edges = id(new PhabricatorEdgeQuery()) | |||||
| ->withSourcePHIDs(array($user_phid)) | |||||
| ->withDestinationPHIDs($qa_phids) | |||||
| ->withEdgeTypes( | |||||
| array( | |||||
| PonderVotingUserHasQuestionEdgeType::EDGECONST, | |||||
| PonderVotingUserHasAnswerEdgeType::EDGECONST, | |||||
| )) | |||||
| ->needEdgeData(true) | |||||
| ->execute(); | |||||
| $question_edge = | |||||
| $edges[$user_phid][PonderVotingUserHasQuestionEdgeType::EDGECONST]; | |||||
| $answer_edges = | |||||
| $edges[$user_phid][PonderVotingUserHasAnswerEdgeType::EDGECONST]; | |||||
| $edges = null; | |||||
| $this->setUserVote(idx($question_edge, $this->getPHID())); | |||||
| foreach ($this->answers as $answer) { | |||||
| $answer->setUserVote(idx($answer_edges, $answer->getPHID())); | |||||
| } | |||||
| } | |||||
| public function setUserVote($vote) { | |||||
| $this->vote = $vote['data']; | |||||
| if (!$this->vote) { | |||||
| $this->vote = PonderVote::VOTE_NONE; | |||||
| } | |||||
| return $this; | |||||
| } | |||||
| public function attachUserVote($user_phid, $vote) { | |||||
| $this->vote = $vote; | |||||
| return $this; | |||||
| } | |||||
| public function getUserVote() { | |||||
| return $this->vote; | |||||
| } | |||||
| public function setComments($comments) { | public function setComments($comments) { | ||||
| $this->comments = $comments; | $this->comments = $comments; | ||||
| return $this; | return $this; | ||||
| } | } | ||||
| public function getComments() { | public function getComments() { | ||||
| return $this->comments; | return $this->comments; | ||||
| } | } | ||||
| ▲ Show 20 Lines • Show All 67 Lines • ▼ Show 20 Lines | public function didMarkupText( | ||||
| PhutilMarkupEngine $engine) { | PhutilMarkupEngine $engine) { | ||||
| return $output; | return $output; | ||||
| } | } | ||||
| public function shouldUseMarkupCache($field) { | public function shouldUseMarkupCache($field) { | ||||
| return (bool)$this->getID(); | return (bool)$this->getID(); | ||||
| } | } | ||||
| // votable interface | |||||
| public function getUserVoteEdgeType() { | |||||
| return PonderVotingUserHasQuestionEdgeType::EDGECONST; | |||||
| } | |||||
| public function getVotablePHID() { | |||||
| return $this->getPHID(); | |||||
| } | |||||
| public function save() { | public function save() { | ||||
| if (!$this->getMailKey()) { | if (!$this->getMailKey()) { | ||||
| $this->setMailKey(Filesystem::readRandomCharacters(20)); | $this->setMailKey(Filesystem::readRandomCharacters(20)); | ||||
| } | } | ||||
| return parent::save(); | return parent::save(); | ||||
| } | } | ||||
| public function getOriginalTitle() { | public function getOriginalTitle() { | ||||
| ▲ Show 20 Lines • Show All 107 Lines • Show Last 20 Lines | |||||