Tokens v1

Summary:
Features!

  - Giving tokens.
  - Taking tokens back.
  - Not giving tokens.

Test Plan: See screenshots.

Reviewers: chad, vrana

Reviewed By: chad

CC: aran, btrahan

Maniphest Tasks: T2541

Differential Revision: https://secure.phabricator.com/D4964
This commit is contained in:
epriestley
2013-02-15 07:47:14 -08:00
parent f9f29253e4
commit 49c40d209d
60 changed files with 1758 additions and 452 deletions

View File

@@ -0,0 +1,89 @@
<?php
final class PhabricatorTokenGivenQuery
extends PhabricatorCursorPagedPolicyAwareQuery {
private $authorPHIDs;
private $objectPHIDs;
private $tokenPHIDs;
public function withTokenPHIDs(array $token_phids) {
$this->tokenPHIDs = $token_phids;
return $this;
}
public function withObjectPHIDs(array $object_phids) {
$this->objectPHIDs = $object_phids;
return $this;
}
public function withAuthorPHIDs(array $author_phids) {
$this->authorPHIDs = $author_phids;
return $this;
}
public function loadPage() {
$table = new PhabricatorTokenGiven();
$conn_r = $table->establishConnection('r');
$rows = queryfx_all(
$conn_r,
'SELECT * FROM %T %Q %Q %Q',
$table->getTableName(),
$this->buildWhereClause($conn_r),
$this->buildOrderClause($conn_r),
$this->buildLimitClause($conn_r));
return $table->loadAllFromArray($rows);
}
private function buildWhereClause(AphrontDatabaseConnection $conn_r) {
$where = array();
if ($this->authorPHIDs) {
$where[] = qsprintf(
$conn_r,
'authorPHID IN (%Ls)',
$this->authorPHIDs);
}
if ($this->objectPHIDs) {
$where[] = qsprintf(
$conn_r,
'objectPHID IN (%Ls)',
$this->objectPHIDs);
}
if ($this->tokenPHIDs) {
$where[] = qsprintf(
$conn_r,
'tokenPHID IN (%Ls)',
$this->tokenPHIDs);
}
return $this->formatWhereClause($where);
}
public function willFilterPage(array $results) {
$object_phids = array_filter(mpull($results, 'getObjectPHID'));
if (!$object_phids) {
return array();
}
$objects = id(new PhabricatorObjectHandleData($object_phids))
->setViewer($this->getViewer())
->loadObjects();
foreach ($results as $key => $result) {
$phid = $result->getObjectPHID();
if (empty($objects[$phid])) {
unset($results[$key]);
} else {
$result->attachObject($objects[$phid]);
}
}
return $results;
}
}

View File

@@ -0,0 +1,62 @@
<?php
final class PhabricatorTokenQuery
extends PhabricatorCursorPagedPolicyAwareQuery {
private $phids;
public function withPHIDs(array $phids) {
$this->phids = $phids;
return $this;
}
public function loadPage() {
$tokens = $this->getBuiltinTokens();
if ($this->phids) {
$map = array_fill_keys($this->phids, true);
foreach ($tokens as $key => $token) {
if (empty($map[$token->getPHID()])) {
unset($tokens[$key]);
}
}
}
return $tokens;
}
private function getBuiltinTokens() {
$specs = array(
array('like-1', pht('Like')),
array('like-2', pht('Dislike')),
array('heart-1', pht('Love')),
array('heart-2', pht('Heartbreak')),
array('medal-1', pht('Orange Medal')),
array('medal-2', pht('Grey Medal')),
array('medal-3', pht('Yellow Medal')),
array('medal-4', pht('Manufacturing Defect?')),
array('coin-1', pht('Haypence')),
array('coin-2', pht('Piece of Eight')),
array('coin-3', pht('Doubloon')),
array('coin-4', pht('Mountain of Wealth')),
array('misc-1', pht('Pterodactyl')),
array('misc-2', pht('Evil Spooky Haunted Tree')),
array('misc-3', pht('Baby Tequila')),
array('misc-4', pht('The World Burns')),
);
$tokens = array();
foreach ($specs as $id => $spec) {
list($image, $name) = $spec;
$token = id(new PhabricatorToken())
->setID($id)
->setName($name)
->setPHID('PHID-TOKN-'.$image);
$tokens[] = $token;
}
return $tokens;
}
}