1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2025-03-26 11:10:16 +01:00

Surface token counts for Pholio

Summary: Provide this data so the list view can present it somehow.

Test Plan: {F34520}

Reviewers: chad

Reviewed By: chad

CC: aran

Differential Revision: https://secure.phabricator.com/D5210
This commit is contained in:
epriestley 2013-03-04 11:47:58 -08:00
parent ab5e019b3d
commit 1beda30792
5 changed files with 99 additions and 18 deletions

View file

@ -1343,6 +1343,7 @@ phutil_register_library_map(array(
'PhabricatorToken' => 'applications/tokens/storage/PhabricatorToken.php', 'PhabricatorToken' => 'applications/tokens/storage/PhabricatorToken.php',
'PhabricatorTokenController' => 'applications/tokens/controller/PhabricatorTokenController.php', 'PhabricatorTokenController' => 'applications/tokens/controller/PhabricatorTokenController.php',
'PhabricatorTokenCount' => 'applications/tokens/storage/PhabricatorTokenCount.php', 'PhabricatorTokenCount' => 'applications/tokens/storage/PhabricatorTokenCount.php',
'PhabricatorTokenCountQuery' => 'applications/tokens/query/PhabricatorTokenCountQuery.php',
'PhabricatorTokenDAO' => 'applications/tokens/storage/PhabricatorTokenDAO.php', 'PhabricatorTokenDAO' => 'applications/tokens/storage/PhabricatorTokenDAO.php',
'PhabricatorTokenGiveController' => 'applications/tokens/controller/PhabricatorTokenGiveController.php', 'PhabricatorTokenGiveController' => 'applications/tokens/controller/PhabricatorTokenGiveController.php',
'PhabricatorTokenGiven' => 'applications/tokens/storage/PhabricatorTokenGiven.php', 'PhabricatorTokenGiven' => 'applications/tokens/storage/PhabricatorTokenGiven.php',
@ -2813,6 +2814,7 @@ phutil_register_library_map(array(
), ),
'PhabricatorTokenController' => 'PhabricatorController', 'PhabricatorTokenController' => 'PhabricatorController',
'PhabricatorTokenCount' => 'PhabricatorTokenDAO', 'PhabricatorTokenCount' => 'PhabricatorTokenDAO',
'PhabricatorTokenCountQuery' => 'PhabricatorOffsetPagedQuery',
'PhabricatorTokenDAO' => 'PhabricatorLiskDAO', 'PhabricatorTokenDAO' => 'PhabricatorLiskDAO',
'PhabricatorTokenGiveController' => 'PhabricatorTokenController', 'PhabricatorTokenGiveController' => 'PhabricatorTokenController',
'PhabricatorTokenGiven' => 'PhabricatorTokenGiven' =>

View file

@ -18,7 +18,8 @@ final class PholioMockListController extends PholioController {
$query = id(new PholioMockQuery()) $query = id(new PholioMockQuery())
->setViewer($user) ->setViewer($user)
->needCoverFiles(true); ->needCoverFiles(true)
->needTokenCounts(true);
$nav = $this->buildSideNav(); $nav = $this->buildSideNav();
$filter = $nav->selectFilter('view/'.$this->view, 'view/all'); $filter = $nav->selectFilter('view/'.$this->view, 'view/all');
@ -65,6 +66,7 @@ final class PholioMockListController extends PholioController {
'div', 'div',
array(), array(),
pht('Created on %s', $datetime))); pht('Created on %s', $datetime)));
$board->addItem($item); $board->addItem($item);
} }

View file

@ -13,6 +13,7 @@ final class PholioMockQuery
private $needCoverFiles; private $needCoverFiles;
private $needImages; private $needImages;
private $needInlineComments; private $needInlineComments;
private $needTokenCounts;
public function withIDs(array $ids) { public function withIDs(array $ids) {
$this->ids = $ids; $this->ids = $ids;
@ -29,6 +30,26 @@ final class PholioMockQuery
return $this; return $this;
} }
public function needCoverFiles($need_cover_files) {
$this->needCoverFiles = $need_cover_files;
return $this;
}
public function needImages($need_images) {
$this->needImages = $need_images;
return $this;
}
public function needInlineComments($need_inline_comments) {
$this->needInlineComments = $need_inline_comments;
return $this;
}
public function needTokenCounts($need) {
$this->needTokenCounts = $need;
return $this;
}
public function loadPage() { public function loadPage() {
$table = new PholioMock(); $table = new PholioMock();
$conn_r = $table->establishConnection('r'); $conn_r = $table->establishConnection('r');
@ -46,10 +67,14 @@ final class PholioMockQuery
if ($mocks && $this->needImages) { if ($mocks && $this->needImages) {
$this->loadImages($mocks); $this->loadImages($mocks);
} }
if ($mocks && $this->needCoverFiles) { if ($mocks && $this->needCoverFiles) {
$this->loadCoverFiles($mocks); $this->loadCoverFiles($mocks);
} }
if ($mocks && $this->needTokenCounts) {
$this->loadTokenCounts($mocks);
}
return $mocks; return $mocks;
} }
@ -83,22 +108,7 @@ final class PholioMockQuery
return $this->formatWhereClause($where); return $this->formatWhereClause($where);
} }
public function needCoverFiles($need_cover_files) { private function loadImages(array $mocks) {
$this->needCoverFiles = $need_cover_files;
return $this;
}
public function needImages($need_images) {
$this->needImages = $need_images;
return $this;
}
public function needInlineComments($need_inline_comments) {
$this->needInlineComments = $need_inline_comments;
return $this;
}
public function loadImages(array $mocks) {
assert_instances_of($mocks, 'PholioMock'); assert_instances_of($mocks, 'PholioMock');
$mock_ids = mpull($mocks, 'getID'); $mock_ids = mpull($mocks, 'getID');
@ -133,7 +143,7 @@ final class PholioMockQuery
} }
} }
public function loadCoverFiles(array $mocks) { private function loadCoverFiles(array $mocks) {
assert_instances_of($mocks, 'PholioMock'); assert_instances_of($mocks, 'PholioMock');
$cover_file_phids = mpull($mocks, 'getCoverPHID'); $cover_file_phids = mpull($mocks, 'getCoverPHID');
$cover_files = mpull(id(new PhabricatorFile())->loadAllWhere( $cover_files = mpull(id(new PhabricatorFile())->loadAllWhere(
@ -144,4 +154,18 @@ final class PholioMockQuery
$mock->attachCoverFile($cover_files[$mock->getCoverPHID()]); $mock->attachCoverFile($cover_files[$mock->getCoverPHID()]);
} }
} }
private function loadTokenCounts(array $mocks) {
assert_instances_of($mocks, 'PholioMock');
$phids = mpull($mocks, 'getPHID');
$counts = id(new PhabricatorTokenCountQuery())
->withObjectPHIDs($phids)
->execute();
foreach ($mocks as $mock) {
$mock->attachTokenCount(idx($counts, $mock->getPHID(), 0));
}
}
} }

View file

@ -24,6 +24,7 @@ final class PholioMock extends PholioDAO
private $images; private $images;
private $coverFile; private $coverFile;
private $tokenCount;
public function getConfiguration() { public function getConfiguration() {
return array( return array(
@ -67,6 +68,18 @@ final class PholioMock extends PholioDAO
return $this->coverFile; return $this->coverFile;
} }
public function getTokenCount() {
if ($this->tokenCount === null) {
throw new Exception("Call attachTokenCount() before getTokenCount()!");
}
return $this->tokenCount;
}
public function attachTokenCount($count) {
$this->tokenCount = $count;
return $this;
}
/* -( PhabricatorSubscribableInterface Implementation )-------------------- */ /* -( PhabricatorSubscribableInterface Implementation )-------------------- */

View file

@ -0,0 +1,40 @@
<?php
final class PhabricatorTokenCountQuery
extends PhabricatorOffsetPagedQuery {
private $objectPHIDs;
public function withObjectPHIDs(array $object_phids) {
$this->objectPHIDs = $object_phids;
return $this;
}
final public function execute() {
$table = new PhabricatorTokenCount();
$conn_r = $table->establishConnection('r');
$rows = queryfx_all(
$conn_r,
'SELECT objectPHID, tokenCount FROM %T %Q %Q',
$table->getTableName(),
$this->buildWhereClause($conn_r),
$this->buildLimitClause($conn_r));
return ipull($rows, 'tokenCount', 'objectPHID');
}
private function buildWhereClause(AphrontDatabaseConnection $conn_r) {
$where = array();
if ($this->objectPHIDs) {
$where[] = qsprintf(
$conn_r,
'objectPHID IN (%Ls)',
$this->objectPHIDs);
}
return $this->formatWhereClause($where);
}
}