[ Index ] |
PHP Cross Reference of Phabricator |
[Summary view] [Print] [Text view]
1 <?php 2 3 final class PhortuneMerchantQuery 4 extends PhabricatorCursorPagedPolicyAwareQuery { 5 6 private $ids; 7 private $phids; 8 private $memberPHIDs; 9 10 public function withIDs(array $ids) { 11 $this->ids = $ids; 12 return $this; 13 } 14 15 public function withPHIDs(array $phids) { 16 $this->phids = $phids; 17 return $this; 18 } 19 20 public function withMemberPHIDs(array $member_phids) { 21 $this->memberPHIDs = $member_phids; 22 return $this; 23 } 24 25 protected function loadPage() { 26 $table = new PhortuneMerchant(); 27 $conn = $table->establishConnection('r'); 28 29 $rows = queryfx_all( 30 $conn, 31 'SELECT m.* FROM %T m %Q %Q %Q %Q', 32 $table->getTableName(), 33 $this->buildJoinClause($conn), 34 $this->buildWhereClause($conn), 35 $this->buildOrderClause($conn), 36 $this->buildLimitClause($conn)); 37 38 return $table->loadAllFromArray($rows); 39 } 40 41 protected function willFilterPage(array $merchants) { 42 $query = id(new PhabricatorEdgeQuery()) 43 ->withSourcePHIDs(mpull($merchants, 'getPHID')) 44 ->withEdgeTypes(array(PhortuneMerchantHasMemberEdgeType::EDGECONST)); 45 $query->execute(); 46 47 foreach ($merchants as $merchant) { 48 $member_phids = $query->getDestinationPHIDs(array($merchant->getPHID())); 49 $member_phids = array_reverse($member_phids); 50 $merchant->attachMemberPHIDs($member_phids); 51 } 52 53 return $merchants; 54 } 55 56 private function buildWhereClause(AphrontDatabaseConnection $conn) { 57 $where = array(); 58 59 if ($this->ids !== null) { 60 $where[] = qsprintf( 61 $conn, 62 'id IN (%Ld)', 63 $this->ids); 64 } 65 66 if ($this->phids !== null) { 67 $where[] = qsprintf( 68 $conn, 69 'phid IN (%Ls)', 70 $this->phids); 71 } 72 73 if ($this->memberPHIDs !== null) { 74 $where[] = qsprintf( 75 $conn, 76 'e.dst IN (%Ls)', 77 $this->memberPHIDs); 78 } 79 80 $where[] = $this->buildPagingClause($conn); 81 82 return $this->formatWhereClause($where); 83 } 84 85 private function buildJoinClause(AphrontDatabaseConnection $conn) { 86 $joins = array(); 87 88 if ($this->memberPHIDs !== null) { 89 $joins[] = qsprintf( 90 $conn, 91 'LEFT JOIN %T e ON m.phid = e.src AND e.type = %d', 92 PhabricatorEdgeConfig::TABLE_NAME_EDGE, 93 PhortuneMerchantHasMemberEdgeType::EDGECONST); 94 } 95 96 return implode(' ', $joins); 97 } 98 99 public function getQueryApplicationClass() { 100 return 'PhabricatorPhortuneApplication'; 101 } 102 103 }
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 |