Changeset View
Changeset View
Standalone View
Standalone View
src/applications/phortune/query/PhortuneMerchantQuery.php
<?php | <?php | ||||
final class PhortuneMerchantQuery | final class PhortuneMerchantQuery | ||||
extends PhabricatorCursorPagedPolicyAwareQuery { | extends PhabricatorCursorPagedPolicyAwareQuery { | ||||
private $ids; | private $ids; | ||||
private $phids; | private $phids; | ||||
private $memberPHIDs; | private $memberPHIDs; | ||||
private $needProfileImage; | |||||
public function withIDs(array $ids) { | public function withIDs(array $ids) { | ||||
$this->ids = $ids; | $this->ids = $ids; | ||||
return $this; | return $this; | ||||
} | } | ||||
public function withPHIDs(array $phids) { | public function withPHIDs(array $phids) { | ||||
$this->phids = $phids; | $this->phids = $phids; | ||||
return $this; | return $this; | ||||
} | } | ||||
public function withMemberPHIDs(array $member_phids) { | public function withMemberPHIDs(array $member_phids) { | ||||
$this->memberPHIDs = $member_phids; | $this->memberPHIDs = $member_phids; | ||||
return $this; | return $this; | ||||
} | } | ||||
public function needProfileImage($need) { | |||||
$this->needProfileImage = $need; | |||||
return $this; | |||||
} | |||||
protected function loadPage() { | protected function loadPage() { | ||||
$table = new PhortuneMerchant(); | $table = new PhortuneMerchant(); | ||||
$conn = $table->establishConnection('r'); | $conn = $table->establishConnection('r'); | ||||
$rows = queryfx_all( | $rows = queryfx_all( | ||||
$conn, | $conn, | ||||
'SELECT m.* FROM %T m %Q %Q %Q %Q', | 'SELECT m.* FROM %T m %Q %Q %Q %Q', | ||||
$table->getTableName(), | $table->getTableName(), | ||||
Show All 12 Lines | protected function willFilterPage(array $merchants) { | ||||
$query->execute(); | $query->execute(); | ||||
foreach ($merchants as $merchant) { | foreach ($merchants as $merchant) { | ||||
$member_phids = $query->getDestinationPHIDs(array($merchant->getPHID())); | $member_phids = $query->getDestinationPHIDs(array($merchant->getPHID())); | ||||
$member_phids = array_reverse($member_phids); | $member_phids = array_reverse($member_phids); | ||||
$merchant->attachMemberPHIDs($member_phids); | $merchant->attachMemberPHIDs($member_phids); | ||||
} | } | ||||
if ($this->needProfileImage) { | |||||
$default = null; | |||||
$file_phids = mpull($merchants, 'getProfileImagePHID'); | |||||
$file_phids = array_filter($file_phids); | |||||
if ($file_phids) { | |||||
$files = id(new PhabricatorFileQuery()) | |||||
->setParentQuery($this) | |||||
->setViewer($this->getViewer()) | |||||
->withPHIDs($file_phids) | |||||
->execute(); | |||||
$files = mpull($files, null, 'getPHID'); | |||||
} else { | |||||
$files = array(); | |||||
} | |||||
foreach ($merchants as $merchant) { | |||||
$file = idx($files, $merchant->getProfileImagePHID()); | |||||
if (!$file) { | |||||
if (!$default) { | |||||
$default = PhabricatorFile::loadBuiltin( | |||||
$this->getViewer(), | |||||
'merchant.png'); | |||||
} | |||||
$file = $default; | |||||
} | |||||
$merchant->attachProfileImageFile($file); | |||||
} | |||||
} | |||||
return $merchants; | return $merchants; | ||||
} | } | ||||
protected function buildWhereClause(AphrontDatabaseConnection $conn) { | protected function buildWhereClause(AphrontDatabaseConnection $conn) { | ||||
$where = array(); | $where = array(); | ||||
if ($this->ids !== null) { | if ($this->ids !== null) { | ||||
$where[] = qsprintf( | $where[] = qsprintf( | ||||
▲ Show 20 Lines • Show All 43 Lines • Show Last 20 Lines |