mirror of
https://we.phorge.it/source/phorge.git
synced 2024-11-10 08:52:39 +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:
parent
ab5e019b3d
commit
1beda30792
5 changed files with 99 additions and 18 deletions
|
@ -1343,6 +1343,7 @@ phutil_register_library_map(array(
|
|||
'PhabricatorToken' => 'applications/tokens/storage/PhabricatorToken.php',
|
||||
'PhabricatorTokenController' => 'applications/tokens/controller/PhabricatorTokenController.php',
|
||||
'PhabricatorTokenCount' => 'applications/tokens/storage/PhabricatorTokenCount.php',
|
||||
'PhabricatorTokenCountQuery' => 'applications/tokens/query/PhabricatorTokenCountQuery.php',
|
||||
'PhabricatorTokenDAO' => 'applications/tokens/storage/PhabricatorTokenDAO.php',
|
||||
'PhabricatorTokenGiveController' => 'applications/tokens/controller/PhabricatorTokenGiveController.php',
|
||||
'PhabricatorTokenGiven' => 'applications/tokens/storage/PhabricatorTokenGiven.php',
|
||||
|
@ -2813,6 +2814,7 @@ phutil_register_library_map(array(
|
|||
),
|
||||
'PhabricatorTokenController' => 'PhabricatorController',
|
||||
'PhabricatorTokenCount' => 'PhabricatorTokenDAO',
|
||||
'PhabricatorTokenCountQuery' => 'PhabricatorOffsetPagedQuery',
|
||||
'PhabricatorTokenDAO' => 'PhabricatorLiskDAO',
|
||||
'PhabricatorTokenGiveController' => 'PhabricatorTokenController',
|
||||
'PhabricatorTokenGiven' =>
|
||||
|
|
|
@ -18,7 +18,8 @@ final class PholioMockListController extends PholioController {
|
|||
|
||||
$query = id(new PholioMockQuery())
|
||||
->setViewer($user)
|
||||
->needCoverFiles(true);
|
||||
->needCoverFiles(true)
|
||||
->needTokenCounts(true);
|
||||
|
||||
$nav = $this->buildSideNav();
|
||||
$filter = $nav->selectFilter('view/'.$this->view, 'view/all');
|
||||
|
@ -65,6 +66,7 @@ final class PholioMockListController extends PholioController {
|
|||
'div',
|
||||
array(),
|
||||
pht('Created on %s', $datetime)));
|
||||
|
||||
$board->addItem($item);
|
||||
}
|
||||
|
||||
|
|
|
@ -13,6 +13,7 @@ final class PholioMockQuery
|
|||
private $needCoverFiles;
|
||||
private $needImages;
|
||||
private $needInlineComments;
|
||||
private $needTokenCounts;
|
||||
|
||||
public function withIDs(array $ids) {
|
||||
$this->ids = $ids;
|
||||
|
@ -29,6 +30,26 @@ final class PholioMockQuery
|
|||
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() {
|
||||
$table = new PholioMock();
|
||||
$conn_r = $table->establishConnection('r');
|
||||
|
@ -46,10 +67,14 @@ final class PholioMockQuery
|
|||
if ($mocks && $this->needImages) {
|
||||
$this->loadImages($mocks);
|
||||
}
|
||||
|
||||
if ($mocks && $this->needCoverFiles) {
|
||||
$this->loadCoverFiles($mocks);
|
||||
}
|
||||
|
||||
if ($mocks && $this->needTokenCounts) {
|
||||
$this->loadTokenCounts($mocks);
|
||||
}
|
||||
|
||||
return $mocks;
|
||||
}
|
||||
|
@ -83,22 +108,7 @@ final class PholioMockQuery
|
|||
return $this->formatWhereClause($where);
|
||||
}
|
||||
|
||||
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 loadImages(array $mocks) {
|
||||
private function loadImages(array $mocks) {
|
||||
assert_instances_of($mocks, 'PholioMock');
|
||||
|
||||
$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');
|
||||
$cover_file_phids = mpull($mocks, 'getCoverPHID');
|
||||
$cover_files = mpull(id(new PhabricatorFile())->loadAllWhere(
|
||||
|
@ -144,4 +154,18 @@ final class PholioMockQuery
|
|||
$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));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -24,6 +24,7 @@ final class PholioMock extends PholioDAO
|
|||
|
||||
private $images;
|
||||
private $coverFile;
|
||||
private $tokenCount;
|
||||
|
||||
public function getConfiguration() {
|
||||
return array(
|
||||
|
@ -67,6 +68,18 @@ final class PholioMock extends PholioDAO
|
|||
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 )-------------------- */
|
||||
|
||||
|
|
40
src/applications/tokens/query/PhabricatorTokenCountQuery.php
Normal file
40
src/applications/tokens/query/PhabricatorTokenCountQuery.php
Normal 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);
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in a new issue