[ Index ] |
PHP Cross Reference of Phabricator |
[Summary view] [Print] [Text view]
1 <?php 2 3 final class PhragmentSnapshotChildQuery 4 extends PhabricatorCursorPagedPolicyAwareQuery { 5 6 private $ids; 7 private $snapshotPHIDs; 8 private $fragmentPHIDs; 9 private $fragmentVersionPHIDs; 10 private $needFragments; 11 private $needFragmentVersions; 12 13 public function withIDs(array $ids) { 14 $this->ids = $ids; 15 return $this; 16 } 17 18 public function withSnapshotPHIDs(array $snapshot_phids) { 19 $this->snapshotPHIDs = $snapshot_phids; 20 return $this; 21 } 22 23 public function withFragmentPHIDs(array $fragment_phids) { 24 $this->fragmentPHIDs = $fragment_phids; 25 return $this; 26 } 27 28 public function withFragmentVersionPHIDs(array $fragment_version_phids) { 29 $this->fragmentVersionPHIDs = $fragment_version_phids; 30 return $this; 31 } 32 33 public function needFragments($need_fragments) { 34 $this->needFragments = $need_fragments; 35 return $this; 36 } 37 38 public function needFragmentVersions($need_fragment_versions) { 39 $this->needFragmentVersions = $need_fragment_versions; 40 return $this; 41 } 42 43 public function loadPage() { 44 $table = new PhragmentSnapshotChild(); 45 $conn_r = $table->establishConnection('r'); 46 47 $data = queryfx_all( 48 $conn_r, 49 'SELECT * FROM %T %Q %Q %Q', 50 $table->getTableName(), 51 $this->buildWhereClause($conn_r), 52 $this->buildOrderClause($conn_r), 53 $this->buildLimitClause($conn_r)); 54 55 return $table->loadAllFromArray($data); 56 } 57 58 protected function buildWhereClause($conn_r) { 59 $where = array(); 60 61 if ($this->ids) { 62 $where[] = qsprintf( 63 $conn_r, 64 'id IN (%Ld)', 65 $this->ids); 66 } 67 68 if ($this->snapshotPHIDs) { 69 $where[] = qsprintf( 70 $conn_r, 71 'snapshotPHID IN (%Ls)', 72 $this->snapshotPHIDs); 73 } 74 75 if ($this->fragmentPHIDs) { 76 $where[] = qsprintf( 77 $conn_r, 78 'fragmentPHID IN (%Ls)', 79 $this->fragmentPHIDs); 80 } 81 82 if ($this->fragmentVersionPHIDs) { 83 $where[] = qsprintf( 84 $conn_r, 85 'fragmentVersionPHID IN (%Ls)', 86 $this->fragmentVersionPHIDs); 87 } 88 89 $where[] = $this->buildPagingClause($conn_r); 90 91 return $this->formatWhereClause($where); 92 } 93 94 protected function willFilterPage(array $page) { 95 $snapshots = array(); 96 97 $snapshot_phids = array_filter(mpull($page, 'getSnapshotPHID')); 98 if ($snapshot_phids) { 99 $snapshots = id(new PhabricatorObjectQuery()) 100 ->setViewer($this->getViewer()) 101 ->withPHIDs($snapshot_phids) 102 ->setParentQuery($this) 103 ->execute(); 104 $snapshots = mpull($snapshots, null, 'getPHID'); 105 } 106 107 foreach ($page as $key => $child) { 108 $snapshot_phid = $child->getSnapshotPHID(); 109 if (empty($snapshots[$snapshot_phid])) { 110 unset($page[$key]); 111 continue; 112 } 113 $child->attachSnapshot($snapshots[$snapshot_phid]); 114 } 115 116 return $page; 117 } 118 119 protected function didFilterPage(array $page) { 120 if ($this->needFragments) { 121 $fragments = array(); 122 123 $fragment_phids = array_filter(mpull($page, 'getFragmentPHID')); 124 if ($fragment_phids) { 125 $fragments = id(new PhabricatorObjectQuery()) 126 ->setViewer($this->getViewer()) 127 ->withPHIDs($fragment_phids) 128 ->setParentQuery($this) 129 ->execute(); 130 $fragments = mpull($fragments, null, 'getPHID'); 131 } 132 133 foreach ($page as $key => $child) { 134 $fragment_phid = $child->getFragmentPHID(); 135 if (empty($fragments[$fragment_phid])) { 136 unset($page[$key]); 137 continue; 138 } 139 $child->attachFragment($fragments[$fragment_phid]); 140 } 141 } 142 143 if ($this->needFragmentVersions) { 144 $fragment_versions = array(); 145 146 $fragment_version_phids = array_filter(mpull( 147 $page, 148 'getFragmentVersionPHID')); 149 if ($fragment_version_phids) { 150 $fragment_versions = id(new PhabricatorObjectQuery()) 151 ->setViewer($this->getViewer()) 152 ->withPHIDs($fragment_version_phids) 153 ->setParentQuery($this) 154 ->execute(); 155 $fragment_versions = mpull($fragment_versions, null, 'getPHID'); 156 } 157 158 foreach ($page as $key => $child) { 159 $fragment_version_phid = $child->getFragmentVersionPHID(); 160 if (empty($fragment_versions[$fragment_version_phid])) { 161 continue; 162 } 163 $child->attachFragmentVersion( 164 $fragment_versions[$fragment_version_phid]); 165 } 166 } 167 168 return $page; 169 } 170 171 public function getQueryApplicationClass() { 172 return 'PhabricatorPhragmentApplication'; 173 } 174 }
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 |