Changeset View
Changeset View
Standalone View
Standalone View
src/applications/ponder/storage/PonderQuestion.php
Show All 27 Lines | final class PonderQuestion extends PonderDAO | ||||
private $answers; | private $answers; | ||||
private $vote; | private $vote; | ||||
private $comments; | private $comments; | ||||
public function getConfiguration() { | public function getConfiguration() { | ||||
return array( | return array( | ||||
self::CONFIG_AUX_PHID => true, | self::CONFIG_AUX_PHID => true, | ||||
self::CONFIG_COLUMN_SCHEMA => array( | |||||
'title' => 'text255', | |||||
'voteCount' => 'sint32', | |||||
'status' => 'uint32', | |||||
'content' => 'text', | |||||
'contentSource' => 'text', | |||||
'heat' => 'double', | |||||
'answerCount' => 'uint32', | |||||
'mailKey' => 'bytes20', | |||||
), | |||||
self::CONFIG_KEY_SCHEMA => array( | |||||
'key_phid' => null, | |||||
'phid' => array( | |||||
'columns' => array('phid'), | |||||
'unique' => true, | |||||
), | |||||
'authorPHID' => array( | |||||
'columns' => array('authorPHID'), | |||||
), | |||||
'heat' => array( | |||||
'columns' => array('heat'), | |||||
), | |||||
'status' => array( | |||||
'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 attachRelated() { | |||||
$this->answers = $this->loadRelatives(new PonderAnswer(), 'questionID'); | |||||
$qa_phids = mpull($this->answers, 'getPHID') + array($this->getPHID()); | |||||
if ($qa_phids) { | |||||
$comments = id(new PonderCommentQuery()) | |||||
->withTargetPHIDs($qa_phids) | |||||
->execute(); | |||||
$comments = mgroup($comments, 'getTargetPHID'); | |||||
} else { | |||||
$comments = array(); | |||||
} | |||||
$this->setComments(idx($comments, $this->getPHID(), array())); | |||||
foreach ($this->answers as $answer) { | |||||
$answer->attachQuestion($this); | |||||
$answer->setComments(idx($comments, $answer->getPHID(), array())); | |||||
} | |||||
} | |||||
public function attachVotes($user_phid) { | public function attachVotes($user_phid) { | ||||
$qa_phids = mpull($this->answers, 'getPHID') + array($this->getPHID()); | $qa_phids = mpull($this->answers, 'getPHID') + array($this->getPHID()); | ||||
$edges = id(new PhabricatorEdgeQuery()) | $edges = id(new PhabricatorEdgeQuery()) | ||||
->withSourcePHIDs(array($user_phid)) | ->withSourcePHIDs(array($user_phid)) | ||||
->withDestinationPHIDs($qa_phids) | ->withDestinationPHIDs($qa_phids) | ||||
->withEdgeTypes( | ->withEdgeTypes( | ||||
array( | array( | ||||
▲ Show 20 Lines • Show All 189 Lines • Show Last 20 Lines |