Path: blob/master/src/applications/files/query/PhabricatorFileAttachmentQuery.php
12242 views
<?php12final class PhabricatorFileAttachmentQuery3extends PhabricatorCursorPagedPolicyAwareQuery {45private $objectPHIDs;6private $filePHIDs;7private $needFiles;8private $visibleFiles;910public function withObjectPHIDs(array $object_phids) {11$this->objectPHIDs = $object_phids;12return $this;13}1415public function withFilePHIDs(array $file_phids) {16$this->filePHIDs = $file_phids;17return $this;18}1920public function withVisibleFiles($visible_files) {21$this->visibleFiles = $visible_files;22return $this;23}2425public function needFiles($need) {26$this->needFiles = $need;27return $this;28}2930public function newResultObject() {31return new PhabricatorFileAttachment();32}3334protected function buildWhereClauseParts(AphrontDatabaseConnection $conn) {35$where = parent::buildWhereClauseParts($conn);3637if ($this->objectPHIDs !== null) {38$where[] = qsprintf(39$conn,40'attachments.objectPHID IN (%Ls)',41$this->objectPHIDs);42}4344if ($this->filePHIDs !== null) {45$where[] = qsprintf(46$conn,47'attachments.filePHID IN (%Ls)',48$this->filePHIDs);49}5051return $where;52}5354protected function willFilterPage(array $attachments) {55$viewer = $this->getViewer();56$object_phids = array();5758foreach ($attachments as $attachment) {59$object_phid = $attachment->getObjectPHID();60$object_phids[$object_phid] = $object_phid;61}6263if ($object_phids) {64$objects = id(new PhabricatorObjectQuery())65->setViewer($viewer)66->setParentQuery($this)67->withPHIDs($object_phids)68->execute();69$objects = mpull($objects, null, 'getPHID');70} else {71$objects = array();72}7374foreach ($attachments as $key => $attachment) {75$object_phid = $attachment->getObjectPHID();76$object = idx($objects, $object_phid);7778if (!$object) {79$this->didRejectResult($attachment);80unset($attachments[$key]);81continue;82}8384$attachment->attachObject($object);85}8687if ($this->needFiles) {88$file_phids = array();89foreach ($attachments as $attachment) {90$file_phid = $attachment->getFilePHID();91$file_phids[$file_phid] = $file_phid;92}9394if ($file_phids) {95$files = id(new PhabricatorFileQuery())96->setViewer($viewer)97->setParentQuery($this)98->withPHIDs($file_phids)99->execute();100$files = mpull($files, null, 'getPHID');101} else {102$files = array();103}104105foreach ($attachments as $key => $attachment) {106$file_phid = $attachment->getFilePHID();107$file = idx($files, $file_phid);108109if ($this->visibleFiles && !$file) {110$this->didRejectResult($attachment);111unset($attachments[$key]);112continue;113}114115$attachment->attachFile($file);116}117}118119return $attachments;120}121122protected function getPrimaryTableAlias() {123return 'attachments';124}125126public function getQueryApplicationClass() {127return 'PhabricatorFilesApplication';128}129130}131132133