Changeset View
Changeset View
Standalone View
Standalone View
src/applications/ponder/query/PonderQuestionQuery.php
| <?php | <?php | ||||
| final class PonderQuestionQuery | final class PonderQuestionQuery | ||||
| extends PhabricatorCursorPagedPolicyAwareQuery { | extends PhabricatorCursorPagedPolicyAwareQuery { | ||||
| private $ids; | private $ids; | ||||
| private $phids; | private $phids; | ||||
| private $status; | private $status; | ||||
| private $authorPHIDs; | private $authorPHIDs; | ||||
| private $answererPHIDs; | private $answererPHIDs; | ||||
| private $needProjectPHIDs; | private $needProjectPHIDs; | ||||
| private $needAnswers; | private $needAnswers; | ||||
| private $needViewerVotes; | |||||
| public function withIDs(array $ids) { | public function withIDs(array $ids) { | ||||
| $this->ids = $ids; | $this->ids = $ids; | ||||
| return $this; | return $this; | ||||
| } | } | ||||
| public function withPHIDs(array $phids) { | public function withPHIDs(array $phids) { | ||||
| $this->phids = $phids; | $this->phids = $phids; | ||||
| Show All 15 Lines | public function withAnswererPHIDs(array $phids) { | ||||
| return $this; | return $this; | ||||
| } | } | ||||
| public function needAnswers($need_answers) { | public function needAnswers($need_answers) { | ||||
| $this->needAnswers = $need_answers; | $this->needAnswers = $need_answers; | ||||
| return $this; | return $this; | ||||
| } | } | ||||
| public function needViewerVotes($need_viewer_votes) { | |||||
| $this->needViewerVotes = $need_viewer_votes; | |||||
| return $this; | |||||
| } | |||||
| public function needProjectPHIDs($need_projects) { | public function needProjectPHIDs($need_projects) { | ||||
| $this->needProjectPHIDs = $need_projects; | $this->needProjectPHIDs = $need_projects; | ||||
| return $this; | return $this; | ||||
| } | } | ||||
| protected function buildWhereClauseParts(AphrontDatabaseConnection $conn) { | protected function buildWhereClauseParts(AphrontDatabaseConnection $conn) { | ||||
| $where = parent::buildWhereClauseParts($conn); | $where = parent::buildWhereClauseParts($conn); | ||||
| ▲ Show 20 Lines • Show All 41 Lines • ▼ Show 20 Lines | protected function willFilterPage(array $questions) { | ||||
| $phids = mpull($questions, 'getPHID'); | $phids = mpull($questions, 'getPHID'); | ||||
| if ($this->needAnswers) { | if ($this->needAnswers) { | ||||
| $aquery = id(new PonderAnswerQuery()) | $aquery = id(new PonderAnswerQuery()) | ||||
| ->setViewer($this->getViewer()) | ->setViewer($this->getViewer()) | ||||
| ->setOrderVector(array('-id')) | ->setOrderVector(array('-id')) | ||||
| ->withQuestionIDs(mpull($questions, 'getID')); | ->withQuestionIDs(mpull($questions, 'getID')); | ||||
| if ($this->needViewerVotes) { | |||||
| $aquery->needViewerVotes($this->needViewerVotes); | |||||
| } | |||||
| $answers = $aquery->execute(); | $answers = $aquery->execute(); | ||||
| $answers = mgroup($answers, 'getQuestionID'); | $answers = mgroup($answers, 'getQuestionID'); | ||||
| foreach ($questions as $question) { | foreach ($questions as $question) { | ||||
| $question_answers = idx($answers, $question->getID(), array()); | $question_answers = idx($answers, $question->getID(), array()); | ||||
| $question->attachAnswers(mpull($question_answers, null, 'getPHID')); | $question->attachAnswers(mpull($question_answers, null, 'getPHID')); | ||||
| } | } | ||||
| } | } | ||||
| if ($this->needViewerVotes) { | |||||
| $viewer_phid = $this->getViewer()->getPHID(); | |||||
| $etype = PonderQuestionHasVotingUserEdgeType::EDGECONST; | |||||
| $edges = id(new PhabricatorEdgeQuery()) | |||||
| ->withSourcePHIDs($phids) | |||||
| ->withDestinationPHIDs(array($viewer_phid)) | |||||
| ->withEdgeTypes(array($etype)) | |||||
| ->needEdgeData(true) | |||||
| ->execute(); | |||||
| foreach ($questions as $question) { | |||||
| $user_edge = idx( | |||||
| $edges[$question->getPHID()][$etype], | |||||
| $viewer_phid, | |||||
| array()); | |||||
| $question->attachUserVote($viewer_phid, idx($user_edge, 'data', 0)); | |||||
| } | |||||
| } | |||||
| if ($this->needProjectPHIDs) { | if ($this->needProjectPHIDs) { | ||||
| $edge_query = id(new PhabricatorEdgeQuery()) | $edge_query = id(new PhabricatorEdgeQuery()) | ||||
| ->withSourcePHIDs($phids) | ->withSourcePHIDs($phids) | ||||
| ->withEdgeTypes( | ->withEdgeTypes( | ||||
| array( | array( | ||||
| PhabricatorProjectObjectHasProjectEdgeType::EDGECONST, | PhabricatorProjectObjectHasProjectEdgeType::EDGECONST, | ||||
| )); | )); | ||||
| $edge_query->execute(); | $edge_query->execute(); | ||||
| Show All 35 Lines | |||||