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 buildWhereClauseParts(AphrontDatabaseConnection
$conn) {
48 $where = parent
::buildWhereClauseParts($conn);
50 if ($this->ids
!== null) {
57 if ($this->phids
!== null) {
64 if ($this->mockPHIDs
!== null) {
74 protected function willFilterPage(array $images) {
75 assert_instances_of($images, 'PholioImage');
77 $mock_phids = array();
78 foreach ($images as $image) {
79 if (!$image->hasMock()) {
83 $mock_phids[] = $image->getMockPHID();
88 $mocks = $this->mocks
;
90 $mocks = id(new PholioMockQuery())
91 ->setViewer($this->getViewer())
92 ->withPHIDs($mock_phids)
96 $mocks = mpull($mocks, null, 'getPHID');
98 foreach ($images as $key => $image) {
99 if (!$image->hasMock()) {
103 $mock = idx($mocks, $image->getMockPHID());
105 unset($images[$key]);
106 $this->didRejectResult($image);
110 $image->attachMock($mock);
117 protected function didFilterPage(array $images) {
118 assert_instances_of($images, 'PholioImage');
120 $file_phids = mpull($images, 'getFilePHID');
122 $all_files = id(new PhabricatorFileQuery())
123 ->setParentQuery($this)
124 ->setViewer($this->getViewer())
125 ->withPHIDs($file_phids)
127 $all_files = mpull($all_files, null, 'getPHID');
129 if ($this->needInlineComments
) {
130 // Only load inline comments the viewer has permission to see.
131 $all_inline_comments = id(new PholioTransactionComment())->loadAllWhere(
133 AND (transactionPHID IS NOT NULL OR authorPHID = %s)',
134 mpull($images, 'getID'),
135 $this->getViewer()->getPHID());
136 $all_inline_comments = mgroup($all_inline_comments, 'getImageID');
139 foreach ($images as $image) {
140 $file = idx($all_files, $image->getFilePHID());
142 $file = PhabricatorFile
::loadBuiltin($this->getViewer(), 'missing.png');
144 $image->attachFile($file);
145 if ($this->needInlineComments
) {
146 $inlines = idx($all_inline_comments, $image->getID(), array());
147 $image->attachInlineComments($inlines);
154 public function getQueryApplicationClass() {
155 return 'PhabricatorPholioApplication';