@recaptime-dev's working patches + fork for Phorge, a community fork of Phabricator. (Upstream dev and stable branches are at upstream/main and upstream/stable respectively.)
hq.recaptime.dev/wiki/Phorge
phorge
phabricator
1<?php
2
3/**
4 * @extends PhabricatorCursorPagedPolicyAwareQuery<PonderAnswer>
5 */
6final class PonderAnswerQuery
7 extends PhabricatorCursorPagedPolicyAwareQuery {
8
9 private $ids;
10 private $phids;
11 private $authorPHIDs;
12 private $questionIDs;
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 protected function buildWhereClauseParts(AphrontDatabaseConnection $conn) {
35 $where = parent::buildWhereClauseParts($conn);
36
37 if ($this->ids !== null) {
38 $where[] = qsprintf(
39 $conn,
40 'id IN (%Ld)',
41 $this->ids);
42 }
43
44 if ($this->phids !== null) {
45 $where[] = qsprintf(
46 $conn,
47 'phid IN (%Ls)',
48 $this->phids);
49 }
50
51 if ($this->authorPHIDs !== null) {
52 $where[] = qsprintf(
53 $conn,
54 'authorPHID IN (%Ls)',
55 $this->authorPHIDs);
56 }
57
58 return $where;
59 }
60
61 public function newResultObject() {
62 return new PonderAnswer();
63 }
64
65 protected function willFilterPage(array $answers) {
66 $questions = id(new PonderQuestionQuery())
67 ->setViewer($this->getViewer())
68 ->withIDs(mpull($answers, 'getQuestionID'))
69 ->execute();
70
71 foreach ($answers as $key => $answer) {
72 $question = idx($questions, $answer->getQuestionID());
73 if (!$question) {
74 unset($answers[$key]);
75 continue;
76 }
77 $answer->attachQuestion($question);
78 }
79
80 return $answers;
81 }
82
83 public function getQueryApplicationClass() {
84 return PhabricatorPonderApplication::class;
85 }
86
87}