3 final class PholioImageQuery
4 extends PhabricatorCursorPagedPolicyAwareQuery
{
11 private $needInlineComments;
13 public function withIDs(array $ids) {
18 public function withPHIDs(array $phids) {
19 $this->phids
= $phids;
23 public function withMocks(array $mocks) {
24 assert_instances_of($mocks, 'PholioMock');
26 $mocks = mpull($mocks, null, 'getPHID');
27 $this->mocks
= $mocks;
28 $this->mockPHIDs
= array_keys($mocks);
33 public function withMockPHIDs(array $mock_phids) {
34 $this->mockPHIDs
= $mock_phids;
38 public function needInlineComments($need_inline_comments) {
39 $this->needInlineComments
= $need_inline_comments;
43 public function newResultObject() {
44 return new PholioImage();
47 protected function loadPage() {
48 return $this->loadStandardPage($this->newResultObject());
51 protected function buildWhereClauseParts(AphrontDatabaseConnection
$conn) {
52 $where = parent
::buildWhereClauseParts($conn);
54 if ($this->ids
!== null) {
61 if ($this->phids
!== null) {
68 if ($this->mockPHIDs
!== null) {
78 protected function willFilterPage(array $images) {
79 assert_instances_of($images, 'PholioImage');
81 $mock_phids = array();
82 foreach ($images as $image) {
83 if (!$image->hasMock()) {
87 $mock_phids[] = $image->getMockPHID();
92 $mocks = $this->mocks
;
94 $mocks = id(new PholioMockQuery())
95 ->setViewer($this->getViewer())
96 ->withPHIDs($mock_phids)
100 $mocks = mpull($mocks, null, 'getPHID');
102 foreach ($images as $key => $image) {
103 if (!$image->hasMock()) {
107 $mock = idx($mocks, $image->getMockPHID());
109 unset($images[$key]);
110 $this->didRejectResult($image);
114 $image->attachMock($mock);
121 protected function didFilterPage(array $images) {
122 assert_instances_of($images, 'PholioImage');
124 $file_phids = mpull($images, 'getFilePHID');
126 $all_files = id(new PhabricatorFileQuery())
127 ->setParentQuery($this)
128 ->setViewer($this->getViewer())
129 ->withPHIDs($file_phids)
131 $all_files = mpull($all_files, null, 'getPHID');
133 if ($this->needInlineComments
) {
134 // Only load inline comments the viewer has permission to see.
135 $all_inline_comments = id(new PholioTransactionComment())->loadAllWhere(
137 AND (transactionPHID IS NOT NULL OR authorPHID = %s)',
138 mpull($images, 'getID'),
139 $this->getViewer()->getPHID());
140 $all_inline_comments = mgroup($all_inline_comments, 'getImageID');
143 foreach ($images as $image) {
144 $file = idx($all_files, $image->getFilePHID());
146 $file = PhabricatorFile
::loadBuiltin($this->getViewer(), 'missing.png');
148 $image->attachFile($file);
149 if ($this->needInlineComments
) {
150 $inlines = idx($all_inline_comments, $image->getID(), array());
151 $image->attachInlineComments($inlines);
158 public function getQueryApplicationClass() {
159 return 'PhabricatorPholioApplication';