3 final class PholioMockQuery
4 extends PhabricatorCursorPagedPolicyAwareQuery
{
11 private $needCoverFiles;
13 private $needInlineComments;
14 private $needTokenCounts;
16 public function withIDs(array $ids) {
21 public function withPHIDs(array $phids) {
22 $this->phids
= $phids;
26 public function withAuthorPHIDs(array $author_phids) {
27 $this->authorPHIDs
= $author_phids;
31 public function withStatuses(array $statuses) {
32 $this->statuses
= $statuses;
36 public function needCoverFiles($need_cover_files) {
37 $this->needCoverFiles
= $need_cover_files;
41 public function needImages($need_images) {
42 $this->needImages
= $need_images;
46 public function needInlineComments($need_inline_comments) {
47 $this->needInlineComments
= $need_inline_comments;
51 public function needTokenCounts($need) {
52 $this->needTokenCounts
= $need;
56 public function newResultObject() {
57 return new PholioMock();
60 protected function loadPage() {
61 if ($this->needInlineComments
&& !$this->needImages
) {
64 'You can not query for inline comments without also querying for '.
68 return $this->loadStandardPage(new PholioMock());
71 protected function buildWhereClauseParts(AphrontDatabaseConnection
$conn) {
72 $where = parent
::buildWhereClauseParts($conn);
74 if ($this->ids
!== null) {
81 if ($this->phids
!== null) {
88 if ($this->authorPHIDs
!== null) {
91 'mock.authorPHID in (%Ls)',
95 if ($this->statuses
!== null) {
98 'mock.status IN (%Ls)',
105 protected function didFilterPage(array $mocks) {
106 $viewer = $this->getViewer();
108 if ($this->needImages
) {
109 $images = id(new PholioImageQuery())
112 ->needInlineComments($this->needInlineComments
)
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())
125 ->withPHIDs(mpull($mocks, 'getCoverPHID'))
127 $cover_files = mpull($cover_files, null, 'getPHID');
129 foreach ($mocks as $mock) {
130 $file = idx($cover_files, $mock->getCoverPHID());
132 $file = PhabricatorFile
::loadBuiltin(
136 $mock->attachCoverFile($file);
140 if ($this->needTokenCounts
) {
141 $counts = id(new PhabricatorTokenCountQuery())
142 ->withObjectPHIDs(mpull($mocks, 'getPHID'))
145 foreach ($mocks as $mock) {
146 $token_count = idx($counts, $mock->getPHID(), 0);
147 $mock->attachTokenCount($token_count);
154 public function getQueryApplicationClass() {
155 return 'PhabricatorPholioApplication';
158 protected function getPrimaryTableAlias() {