Changeset View
Changeset View
Standalone View
Standalone View
src/applications/phortune/query/PhortuneAccountQuery.php
| Show All 36 Lines | public function withPHIDs(array $phids) { | ||||
| return $this; | return $this; | ||||
| } | } | ||||
| public function withMemberPHIDs(array $phids) { | public function withMemberPHIDs(array $phids) { | ||||
| $this->memberPHIDs = $phids; | $this->memberPHIDs = $phids; | ||||
| return $this; | return $this; | ||||
| } | } | ||||
| protected function loadPage() { | public function newResultObject() { | ||||
| $table = new PhortuneAccount(); | return new PhortuneAccount(); | ||||
| $conn = $table->establishConnection('r'); | } | ||||
| $rows = queryfx_all( | |||||
| $conn, | |||||
| 'SELECT a.* FROM %T a %Q %Q %Q %Q', | |||||
| $table->getTableName(), | |||||
| $this->buildJoinClause($conn), | |||||
| $this->buildWhereClause($conn), | |||||
| $this->buildOrderClause($conn), | |||||
| $this->buildLimitClause($conn)); | |||||
| return $table->loadAllFromArray($rows); | protected function loadPage() { | ||||
| return $this->loadStandardPage($this->newResultObject()); | |||||
| } | } | ||||
| protected function willFilterPage(array $accounts) { | protected function willFilterPage(array $accounts) { | ||||
| $query = id(new PhabricatorEdgeQuery()) | $query = id(new PhabricatorEdgeQuery()) | ||||
| ->withSourcePHIDs(mpull($accounts, 'getPHID')) | ->withSourcePHIDs(mpull($accounts, 'getPHID')) | ||||
| ->withEdgeTypes(array(PhortuneAccountHasMemberEdgeType::EDGECONST)); | ->withEdgeTypes(array(PhortuneAccountHasMemberEdgeType::EDGECONST)); | ||||
| $query->execute(); | $query->execute(); | ||||
| foreach ($accounts as $account) { | foreach ($accounts as $account) { | ||||
| $member_phids = $query->getDestinationPHIDs(array($account->getPHID())); | $member_phids = $query->getDestinationPHIDs(array($account->getPHID())); | ||||
| $member_phids = array_reverse($member_phids); | $member_phids = array_reverse($member_phids); | ||||
| $account->attachMemberPHIDs($member_phids); | $account->attachMemberPHIDs($member_phids); | ||||
| } | } | ||||
| return $accounts; | return $accounts; | ||||
| } | } | ||||
| protected function buildWhereClause(AphrontDatabaseConnection $conn) { | protected function buildWhereClauseParts(AphrontDatabaseConnection $conn) { | ||||
| $where = array(); | $where = parent::buildWhereClauseParts($conn); | ||||
| $where[] = $this->buildPagingClause($conn); | |||||
| if ($this->ids) { | if ($this->ids !== null) { | ||||
| $where[] = qsprintf( | $where[] = qsprintf( | ||||
| $conn, | $conn, | ||||
| 'a.id IN (%Ld)', | 'a.id IN (%Ld)', | ||||
| $this->ids); | $this->ids); | ||||
| } | } | ||||
| if ($this->phids) { | if ($this->phids !== null) { | ||||
| $where[] = qsprintf( | $where[] = qsprintf( | ||||
| $conn, | $conn, | ||||
| 'a.phid IN (%Ls)', | 'a.phid IN (%Ls)', | ||||
| $this->phids); | $this->phids); | ||||
| } | } | ||||
| if ($this->memberPHIDs) { | if ($this->memberPHIDs !== null) { | ||||
| $where[] = qsprintf( | $where[] = qsprintf( | ||||
| $conn, | $conn, | ||||
| 'm.dst IN (%Ls)', | 'm.dst IN (%Ls)', | ||||
| $this->memberPHIDs); | $this->memberPHIDs); | ||||
| } | } | ||||
| return $this->formatWhereClause($conn, $where); | return $where; | ||||
| } | } | ||||
| protected function buildJoinClause(AphrontDatabaseConnection $conn) { | protected function buildJoinClauseParts(AphrontDatabaseConnection $conn) { | ||||
| $joins = array(); | $joins = parent::buildJoinClauseParts($conn); | ||||
| if ($this->memberPHIDs) { | if ($this->memberPHIDs !== null) { | ||||
| $joins[] = qsprintf( | $joins[] = qsprintf( | ||||
| $conn, | $conn, | ||||
| 'LEFT JOIN %T m ON a.phid = m.src AND m.type = %d', | 'LEFT JOIN %T m ON a.phid = m.src AND m.type = %d', | ||||
| PhabricatorEdgeConfig::TABLE_NAME_EDGE, | PhabricatorEdgeConfig::TABLE_NAME_EDGE, | ||||
| PhortuneAccountHasMemberEdgeType::EDGECONST); | PhortuneAccountHasMemberEdgeType::EDGECONST); | ||||
| } | } | ||||
| return implode(' ', $joins); | return $joins; | ||||
| } | } | ||||
| public function getQueryApplicationClass() { | public function getQueryApplicationClass() { | ||||
| return 'PhabricatorPhortuneApplication'; | return 'PhabricatorPhortuneApplication'; | ||||
| } | } | ||||
| protected function getPrimaryTableAlias() { | |||||
| return 'a'; | |||||
| } | |||||
| } | } | ||||