[ Index ] |
PHP Cross Reference of Phabricator |
[Summary view] [Print] [Text view]
1 <?php 2 3 final class PholioMockQuery 4 extends PhabricatorCursorPagedPolicyAwareQuery { 5 6 private $ids; 7 private $phids; 8 private $authorPHIDs; 9 private $statuses; 10 11 private $needCoverFiles; 12 private $needImages; 13 private $needInlineComments; 14 private $needTokenCounts; 15 16 public function withIDs(array $ids) { 17 $this->ids = $ids; 18 return $this; 19 } 20 21 public function withPHIDs(array $phids) { 22 $this->phids = $phids; 23 return $this; 24 } 25 26 public function withAuthorPHIDs(array $author_phids) { 27 $this->authorPHIDs = $author_phids; 28 return $this; 29 } 30 31 public function withStatuses(array $statuses) { 32 $this->statuses = $statuses; 33 return $this; 34 } 35 36 public function needCoverFiles($need_cover_files) { 37 $this->needCoverFiles = $need_cover_files; 38 return $this; 39 } 40 41 public function needImages($need_images) { 42 $this->needImages = $need_images; 43 return $this; 44 } 45 46 public function needInlineComments($need_inline_comments) { 47 $this->needInlineComments = $need_inline_comments; 48 return $this; 49 } 50 51 public function needTokenCounts($need) { 52 $this->needTokenCounts = $need; 53 return $this; 54 } 55 56 protected function loadPage() { 57 $table = new PholioMock(); 58 $conn_r = $table->establishConnection('r'); 59 60 $data = queryfx_all( 61 $conn_r, 62 'SELECT * FROM %T %Q %Q %Q', 63 $table->getTableName(), 64 $this->buildWhereClause($conn_r), 65 $this->buildOrderClause($conn_r), 66 $this->buildLimitClause($conn_r)); 67 68 $mocks = $table->loadAllFromArray($data); 69 70 if ($mocks && $this->needImages) { 71 $this->loadImages($mocks); 72 } 73 74 if ($mocks && $this->needCoverFiles) { 75 $this->loadCoverFiles($mocks); 76 } 77 78 if ($mocks && $this->needTokenCounts) { 79 $this->loadTokenCounts($mocks); 80 } 81 82 return $mocks; 83 } 84 85 private function buildWhereClause(AphrontDatabaseConnection $conn_r) { 86 $where = array(); 87 88 $where[] = $this->buildPagingClause($conn_r); 89 90 if ($this->ids) { 91 $where[] = qsprintf( 92 $conn_r, 93 'id IN (%Ld)', 94 $this->ids); 95 } 96 97 if ($this->phids) { 98 $where[] = qsprintf( 99 $conn_r, 100 'phid IN (%Ls)', 101 $this->phids); 102 } 103 104 if ($this->authorPHIDs) { 105 $where[] = qsprintf( 106 $conn_r, 107 'authorPHID in (%Ls)', 108 $this->authorPHIDs); 109 } 110 111 if ($this->statuses) { 112 $where[] = qsprintf( 113 $conn_r, 114 'status IN (%Ls)', 115 $this->statuses); 116 } 117 118 return $this->formatWhereClause($where); 119 } 120 121 private function loadImages(array $mocks) { 122 assert_instances_of($mocks, 'PholioMock'); 123 124 $mock_map = mpull($mocks, null, 'getID'); 125 $all_images = id(new PholioImageQuery()) 126 ->setViewer($this->getViewer()) 127 ->setMockCache($mock_map) 128 ->withMockIDs(array_keys($mock_map)) 129 ->needInlineComments($this->needInlineComments) 130 ->execute(); 131 132 $image_groups = mgroup($all_images, 'getMockID'); 133 134 foreach ($mocks as $mock) { 135 $mock_images = idx($image_groups, $mock->getID(), array()); 136 $mock->attachAllImages($mock_images); 137 $active_images = mfilter($mock_images, 'getIsObsolete', true); 138 $mock->attachImages(msort($active_images, 'getSequence')); 139 } 140 } 141 142 private function loadCoverFiles(array $mocks) { 143 assert_instances_of($mocks, 'PholioMock'); 144 $cover_file_phids = mpull($mocks, 'getCoverPHID'); 145 $cover_files = id(new PhabricatorFileQuery()) 146 ->setViewer($this->getViewer()) 147 ->withPHIDs($cover_file_phids) 148 ->execute(); 149 150 $cover_files = mpull($cover_files, null, 'getPHID'); 151 152 foreach ($mocks as $mock) { 153 $file = idx($cover_files, $mock->getCoverPHID()); 154 if (!$file) { 155 $file = PhabricatorFile::loadBuiltin($this->getViewer(), 'missing.png'); 156 } 157 $mock->attachCoverFile($file); 158 } 159 } 160 161 private function loadTokenCounts(array $mocks) { 162 assert_instances_of($mocks, 'PholioMock'); 163 164 $phids = mpull($mocks, 'getPHID'); 165 $counts = id(new PhabricatorTokenCountQuery()) 166 ->withObjectPHIDs($phids) 167 ->execute(); 168 169 foreach ($mocks as $mock) { 170 $mock->attachTokenCount(idx($counts, $mock->getPHID(), 0)); 171 } 172 } 173 174 public function getQueryApplicationClass() { 175 return 'PhabricatorPholioApplication'; 176 } 177 178 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Sun Nov 30 09:20:46 2014 | Cross-referenced by PHPXref 0.7.1 |