3 final class PhabricatorFileAttachmentQuery
4 extends PhabricatorCursorPagedPolicyAwareQuery
{
11 public function withObjectPHIDs(array $object_phids) {
12 $this->objectPHIDs
= $object_phids;
16 public function withFilePHIDs(array $file_phids) {
17 $this->filePHIDs
= $file_phids;
21 public function withVisibleFiles($visible_files) {
22 $this->visibleFiles
= $visible_files;
26 public function needFiles($need) {
27 $this->needFiles
= $need;
31 public function newResultObject() {
32 return new PhabricatorFileAttachment();
35 protected function buildWhereClauseParts(AphrontDatabaseConnection
$conn) {
36 $where = parent
::buildWhereClauseParts($conn);
38 if ($this->objectPHIDs
!== null) {
41 'attachments.objectPHID IN (%Ls)',
45 if ($this->filePHIDs
!== null) {
48 'attachments.filePHID IN (%Ls)',
55 protected function willFilterPage(array $attachments) {
56 $viewer = $this->getViewer();
57 $object_phids = array();
59 foreach ($attachments as $attachment) {
60 $object_phid = $attachment->getObjectPHID();
61 $object_phids[$object_phid] = $object_phid;
65 $objects = id(new PhabricatorObjectQuery())
67 ->setParentQuery($this)
68 ->withPHIDs($object_phids)
70 $objects = mpull($objects, null, 'getPHID');
75 foreach ($attachments as $key => $attachment) {
76 $object_phid = $attachment->getObjectPHID();
77 $object = idx($objects, $object_phid);
80 $this->didRejectResult($attachment);
81 unset($attachments[$key]);
85 $attachment->attachObject($object);
88 if ($this->needFiles
) {
89 $file_phids = array();
90 foreach ($attachments as $attachment) {
91 $file_phid = $attachment->getFilePHID();
92 $file_phids[$file_phid] = $file_phid;
96 $files = id(new PhabricatorFileQuery())
98 ->setParentQuery($this)
99 ->withPHIDs($file_phids)
101 $files = mpull($files, null, 'getPHID');
106 foreach ($attachments as $key => $attachment) {
107 $file_phid = $attachment->getFilePHID();
108 $file = idx($files, $file_phid);
110 if ($this->visibleFiles
&& !$file) {
111 $this->didRejectResult($attachment);
112 unset($attachments[$key]);
116 $attachment->attachFile($file);
123 protected function getPrimaryTableAlias() {
124 return 'attachments';
127 public function getQueryApplicationClass() {
128 return 'PhabricatorFilesApplication';