[ Index ] |
PHP Cross Reference of Phabricator |
[Summary view] [Print] [Text view]
1 <?php 2 3 final class AlmanacPropertyQuery 4 extends PhabricatorCursorPagedPolicyAwareQuery { 5 6 private $ids; 7 private $objectPHIDs; 8 private $names; 9 private $disablePolicyFilteringAndAttachment; 10 11 public function withIDs(array $ids) { 12 $this->ids = $ids; 13 return $this; 14 } 15 16 public function withObjectPHIDs(array $phids) { 17 $this->phids = $phids; 18 return $this; 19 } 20 21 public function withNames(array $names) { 22 $this->names = $names; 23 return $this; 24 } 25 26 public function setDisablePolicyFilteringAndAttachment($disable) { 27 $this->disablePolicyFilteringAndAttachment = $disable; 28 return $this; 29 } 30 31 protected function shouldDisablePolicyFiltering() { 32 return $this->disablePolicyFilteringAndAttachment; 33 } 34 35 protected function loadPage() { 36 $table = new AlmanacProperty(); 37 $conn_r = $table->establishConnection('r'); 38 39 $data = queryfx_all( 40 $conn_r, 41 'SELECT * FROM %T %Q %Q %Q', 42 $table->getTableName(), 43 $this->buildWhereClause($conn_r), 44 $this->buildOrderClause($conn_r), 45 $this->buildLimitClause($conn_r)); 46 47 return $table->loadAllFromArray($data); 48 } 49 50 protected function willFilterPage(array $properties) { 51 if (!$this->disablePolicyFilteringAndAttachment) { 52 $object_phids = mpull($properties, 'getObjectPHID'); 53 54 $objects = id(new PhabricatorObjectQuery()) 55 ->setViewer($this->getViewer()) 56 ->setParentQuery($this) 57 ->withPHIDs($object_phids) 58 ->execute(); 59 $objects = mpull($objects, null, 'getPHID'); 60 61 foreach ($properties as $key => $property) { 62 $object = idx($objects, $property->getObjectPHID()); 63 if (!$object) { 64 unset($properties[$key]); 65 continue; 66 } 67 $property->attachObject($object); 68 } 69 } 70 71 return $properties; 72 } 73 74 protected function buildWhereClause($conn_r) { 75 $where = array(); 76 77 if ($this->ids !== null) { 78 $where[] = qsprintf( 79 $conn_r, 80 'id IN (%Ld)', 81 $this->ids); 82 } 83 84 if ($this->objectPHIDs !== null) { 85 $where[] = qsprintf( 86 $conn_r, 87 'objectPHID IN (%Ls)', 88 $this->objectPHIDs); 89 } 90 91 if ($this->names !== null) { 92 $hashes = array(); 93 foreach ($this->names as $name) { 94 $hashes[] = PhabricatorHash::digestForIndex($name); 95 } 96 $where[] = qsprintf( 97 $conn_r, 98 'fieldIndex IN (%Ls)', 99 $hashes); 100 } 101 102 $where[] = $this->buildPagingClause($conn_r); 103 104 return $this->formatWhereClause($where); 105 } 106 107 public function getQueryApplicationClass() { 108 return 'PhabricatorAlmanacApplication'; 109 } 110 111 }
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 |