Correct a parameter order swap in "diffusion.historyquery" for Mercurial
[phabricator.git] / src / applications / pholio / query / PholioMockQuery.php
blob4820ffd8eb1a5c4c7fe52861d40caaf3fd06f598
1 <?php
3 final class PholioMockQuery
4 extends PhabricatorCursorPagedPolicyAwareQuery {
6 private $ids;
7 private $phids;
8 private $authorPHIDs;
9 private $statuses;
11 private $needCoverFiles;
12 private $needImages;
13 private $needInlineComments;
14 private $needTokenCounts;
16 public function withIDs(array $ids) {
17 $this->ids = $ids;
18 return $this;
21 public function withPHIDs(array $phids) {
22 $this->phids = $phids;
23 return $this;
26 public function withAuthorPHIDs(array $author_phids) {
27 $this->authorPHIDs = $author_phids;
28 return $this;
31 public function withStatuses(array $statuses) {
32 $this->statuses = $statuses;
33 return $this;
36 public function needCoverFiles($need_cover_files) {
37 $this->needCoverFiles = $need_cover_files;
38 return $this;
41 public function needImages($need_images) {
42 $this->needImages = $need_images;
43 return $this;
46 public function needInlineComments($need_inline_comments) {
47 $this->needInlineComments = $need_inline_comments;
48 return $this;
51 public function needTokenCounts($need) {
52 $this->needTokenCounts = $need;
53 return $this;
56 public function newResultObject() {
57 return new PholioMock();
60 protected function loadPage() {
61 if ($this->needInlineComments && !$this->needImages) {
62 throw new Exception(
63 pht(
64 'You can not query for inline comments without also querying for '.
65 'images.'));
68 return $this->loadStandardPage(new PholioMock());
71 protected function buildWhereClauseParts(AphrontDatabaseConnection $conn) {
72 $where = parent::buildWhereClauseParts($conn);
74 if ($this->ids !== null) {
75 $where[] = qsprintf(
76 $conn,
77 'mock.id IN (%Ld)',
78 $this->ids);
81 if ($this->phids !== null) {
82 $where[] = qsprintf(
83 $conn,
84 'mock.phid IN (%Ls)',
85 $this->phids);
88 if ($this->authorPHIDs !== null) {
89 $where[] = qsprintf(
90 $conn,
91 'mock.authorPHID in (%Ls)',
92 $this->authorPHIDs);
95 if ($this->statuses !== null) {
96 $where[] = qsprintf(
97 $conn,
98 'mock.status IN (%Ls)',
99 $this->statuses);
102 return $where;
105 protected function didFilterPage(array $mocks) {
106 $viewer = $this->getViewer();
108 if ($this->needImages) {
109 $images = id(new PholioImageQuery())
110 ->setViewer($viewer)
111 ->withMocks($mocks)
112 ->needInlineComments($this->needInlineComments)
113 ->execute();
115 $image_groups = mgroup($images, 'getMockPHID');
116 foreach ($mocks as $mock) {
117 $images = idx($image_groups, $mock->getPHID(), array());
118 $mock->attachImages($images);
122 if ($this->needCoverFiles) {
123 $cover_files = id(new PhabricatorFileQuery())
124 ->setViewer($viewer)
125 ->withPHIDs(mpull($mocks, 'getCoverPHID'))
126 ->execute();
127 $cover_files = mpull($cover_files, null, 'getPHID');
129 foreach ($mocks as $mock) {
130 $file = idx($cover_files, $mock->getCoverPHID());
131 if (!$file) {
132 $file = PhabricatorFile::loadBuiltin(
133 $viewer,
134 'missing.png');
136 $mock->attachCoverFile($file);
140 if ($this->needTokenCounts) {
141 $counts = id(new PhabricatorTokenCountQuery())
142 ->withObjectPHIDs(mpull($mocks, 'getPHID'))
143 ->execute();
145 foreach ($mocks as $mock) {
146 $token_count = idx($counts, $mock->getPHID(), 0);
147 $mock->attachTokenCount($token_count);
151 return $mocks;
154 public function getQueryApplicationClass() {
155 return 'PhabricatorPholioApplication';
158 protected function getPrimaryTableAlias() {
159 return 'mock';