Changeset View
Changeset View
Standalone View
Standalone View
src/applications/tokens/query/PhabricatorTokenQuery.php
- This file was copied to src/applications/tokens/query/PhabricatorBuiltinTokenQuery.php.
<?php | <?php | ||||
final class PhabricatorTokenQuery | final class PhabricatorTokenQuery | ||||
extends PhabricatorCursorPagedPolicyAwareQuery { | extends PhabricatorCursorPagedPolicyAwareQuery { | ||||
private $ids; | |||||
private $phids; | private $phids; | ||||
private $statuses; | |||||
private $needImages; | |||||
public function withIDs(array $ids) { | |||||
$this->ids = $ids; | |||||
return $this; | |||||
} | |||||
public function withPHIDs(array $phids) { | public function withPHIDs(array $phids) { | ||||
$this->phids = $phids; | $this->phids = $phids; | ||||
return $this; | return $this; | ||||
} | } | ||||
public function withStatuses(array $statuses) { | |||||
$this->statuses = $statuses; | |||||
return $this; | |||||
} | |||||
protected function loadPage() { | protected function loadPage() { | ||||
$tokens = $this->getBuiltinTokens(); | return $this->loadStandardPage($this->newResultObject()); | ||||
} | |||||
if ($this->phids) { | public function newResultObject() { | ||||
$map = array_fill_keys($this->phids, true); | return new PhabricatorTokensToken(); | ||||
foreach ($tokens as $key => $token) { | |||||
if (empty($map[$token->getPHID()])) { | |||||
unset($tokens[$key]); | |||||
} | } | ||||
protected function getPrimaryTableAlias() { | |||||
return 'tokens_token'; | |||||
} | } | ||||
protected function buildWhereClauseParts(AphrontDatabaseConnection $conn) { | |||||
$where = parent::buildWhereClauseParts($conn); | |||||
if ($this->ids !== null) { | |||||
$where[] = qsprintf( | |||||
$conn, | |||||
'id IN (%Ld)', | |||||
$this->ids); | |||||
} | } | ||||
return $tokens; | if ($this->phids !== null) { | ||||
$where[] = qsprintf( | |||||
$conn, | |||||
'phid IN (%Ls)', | |||||
$this->phids); | |||||
} | |||||
if ($this->statuses !== null) { | |||||
$where[] = qsprintf( | |||||
$conn, | |||||
'status IN (%Ls)', | |||||
$this->statuses); | |||||
} | |||||
return $where; | |||||
} | } | ||||
private function getBuiltinTokens() { | private function getBuiltinTokens() { | ||||
$specs = array( | $specs = array( | ||||
array('like-1', pht('Like')), | array('like-1', pht('Like')), | ||||
array('like-2', pht('Dislike')), | array('like-2', pht('Dislike')), | ||||
array('heart-1', pht('Love')), | array('heart-1', pht('Love')), | ||||
array('heart-2', pht('Heartbreak')), | array('heart-2', pht('Heartbreak')), | ||||
array('medal-1', pht('Orange Medal')), | array('medal-1', pht('Orange Medal')), | ||||
array('medal-2', pht('Grey Medal')), | array('medal-2', pht('Grey Medal')), | ||||
array('medal-3', pht('Yellow Medal')), | array('medal-3', pht('Yellow Medal')), | ||||
array('medal-4', pht('Manufacturing Defect?')), | array('medal-4', pht('Manufacturing Defect?')), | ||||
array('coin-1', pht('Haypence')), | array('coin-1', pht('Haypence')), | ||||
array('coin-2', pht('Piece of Eight')), | array('coin-2', pht('Piece of Eight')), | ||||
array('coin-3', pht('Doubloon')), | array('coin-3', pht('Doubloon')), | ||||
array('coin-4', pht('Mountain of Wealth')), | array('coin-4', pht('Mountain of Wealth')), | ||||
array('misc-1', pht('Pterodactyl')), | array('misc-1', pht('Pterodactyl')), | ||||
array('misc-2', pht('Evil Spooky Haunted Tree')), | array('misc-2', pht('Evil Spooky Haunted Tree')), | ||||
array('misc-3', pht('Baby Tequila')), | array('misc-3', pht('Baby Tequila')), | ||||
array('misc-4', pht('The World Burns')), | array('misc-4', pht('The World Burns')), | ||||
); | ); | ||||
$type = PhabricatorTokenTokenPHIDType::TYPECONST; | $type = PhabricatorTokensTokenPHIDType::TYPECONST; | ||||
$tokens = array(); | $tokens = array(); | ||||
foreach ($specs as $id => $spec) { | foreach ($specs as $id => $spec) { | ||||
list($image, $name) = $spec; | list($image, $name) = $spec; | ||||
$token = id(new PhabricatorToken()) | $token = id(new PhabricatorToken()) | ||||
->setID($id) | ->setID($id) | ||||
->setName($name) | ->setName($name) | ||||
Show All 13 Lines |