[ Index ] |
PHP Cross Reference of Phabricator |
[Summary view] [Print] [Text view]
1 <?php 2 3 final class PonderAnswerQuery 4 extends PhabricatorCursorPagedPolicyAwareQuery { 5 6 private $ids; 7 private $phids; 8 private $authorPHIDs; 9 private $questionIDs; 10 11 private $needViewerVotes; 12 13 14 public function withIDs(array $ids) { 15 $this->ids = $ids; 16 return $this; 17 } 18 19 public function withPHIDs(array $phids) { 20 $this->phids = $phids; 21 return $this; 22 } 23 24 public function withAuthorPHIDs(array $phids) { 25 $this->authorPHIDs = $phids; 26 return $this; 27 } 28 29 public function withQuestionIDs(array $ids) { 30 $this->questionIDs = $ids; 31 return $this; 32 } 33 34 public function needViewerVotes($need_viewer_votes) { 35 $this->needViewerVotes = $need_viewer_votes; 36 return $this; 37 } 38 39 private function buildWhereClause($conn_r) { 40 $where = array(); 41 42 if ($this->ids) { 43 $where[] = qsprintf( 44 $conn_r, 45 'id IN (%Ld)', 46 $this->ids); 47 } 48 49 if ($this->phids) { 50 $where[] = qsprintf( 51 $conn_r, 52 'phid IN (%Ls)', 53 $this->phids); 54 } 55 56 if ($this->authorPHIDs) { 57 $where[] = qsprintf( 58 $conn_r, 59 'authorPHID IN (%Ls)', 60 $this->authorPHIDs); 61 } 62 63 $where[] = $this->buildPagingClause($conn_r); 64 65 return $this->formatWhereClause($where); 66 } 67 68 public function loadPage() { 69 $answer = new PonderAnswer(); 70 $conn_r = $answer->establishConnection('r'); 71 72 $data = queryfx_all( 73 $conn_r, 74 'SELECT a.* FROM %T a %Q %Q %Q', 75 $answer->getTableName(), 76 $this->buildWhereClause($conn_r), 77 $this->buildOrderClause($conn_r), 78 $this->buildLimitClause($conn_r)); 79 80 return $answer->loadAllFromArray($data); 81 } 82 83 public function willFilterPage(array $answers) { 84 $questions = id(new PonderQuestionQuery()) 85 ->setViewer($this->getViewer()) 86 ->withIDs(mpull($answers, 'getQuestionID')) 87 ->execute(); 88 89 foreach ($answers as $key => $answer) { 90 $question = idx($questions, $answer->getQuestionID()); 91 if (!$question) { 92 unset($answers[$key]); 93 continue; 94 } 95 $answer->attachQuestion($question); 96 } 97 98 if ($this->needViewerVotes) { 99 $viewer_phid = $this->getViewer()->getPHID(); 100 101 $etype = PhabricatorEdgeConfig::TYPE_ANSWER_HAS_VOTING_USER; 102 $edges = id(new PhabricatorEdgeQuery()) 103 ->withSourcePHIDs(mpull($answers, 'getPHID')) 104 ->withDestinationPHIDs(array($viewer_phid)) 105 ->withEdgeTypes(array($etype)) 106 ->needEdgeData(true) 107 ->execute(); 108 foreach ($answers as $answer) { 109 $user_edge = idx( 110 $edges[$answer->getPHID()][$etype], 111 $viewer_phid, 112 array()); 113 114 $answer->attachUserVote($viewer_phid, idx($user_edge, 'data', 0)); 115 } 116 } 117 118 return $answers; 119 } 120 121 protected function getReversePaging() { 122 return true; 123 } 124 125 public function getQueryApplicationClass() { 126 return 'PhabricatorPonderApplication'; 127 } 128 129 }
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 |