1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-11-27 01:02:42 +01:00

Enrich "gave a token" feed story

Summary: Name the token which was given in the feed story.

Test Plan: Gave/rescinded tokens. Looked at a feed story.

Reviewers: btrahan

Reviewed By: btrahan

CC: aran

Differential Revision: https://secure.phabricator.com/D7110
This commit is contained in:
epriestley 2013-09-24 17:00:31 -07:00
parent d5bda56acd
commit c373baa766
4 changed files with 60 additions and 3 deletions

View file

@ -1698,6 +1698,7 @@ phutil_register_library_map(array(
'PhabricatorTokenGivenFeedStory' => 'applications/tokens/feed/PhabricatorTokenGivenFeedStory.php',
'PhabricatorTokenGivenQuery' => 'applications/tokens/query/PhabricatorTokenGivenQuery.php',
'PhabricatorTokenLeaderController' => 'applications/tokens/controller/PhabricatorTokenLeaderController.php',
'PhabricatorTokenPHIDTypeToken' => 'applications/tokens/phid/PhabricatorTokenPHIDTypeToken.php',
'PhabricatorTokenQuery' => 'applications/tokens/query/PhabricatorTokenQuery.php',
'PhabricatorTokenReceiverInterface' => 'applications/tokens/interface/PhabricatorTokenReceiverInterface.php',
'PhabricatorTokenReceiverQuery' => 'applications/tokens/query/PhabricatorTokenReceiverQuery.php',
@ -3856,6 +3857,7 @@ phutil_register_library_map(array(
'PhabricatorTokenGivenFeedStory' => 'PhabricatorFeedStory',
'PhabricatorTokenGivenQuery' => 'PhabricatorCursorPagedPolicyAwareQuery',
'PhabricatorTokenLeaderController' => 'PhabricatorTokenController',
'PhabricatorTokenPHIDTypeToken' => 'PhabricatorPHIDType',
'PhabricatorTokenQuery' => 'PhabricatorCursorPagedPolicyAwareQuery',
'PhabricatorTokenReceiverQuery' => 'PhabricatorCursorPagedPolicyAwareQuery',
'PhabricatorTokenUIEventListener' => 'PhutilEventListener',

View file

@ -14,6 +14,12 @@ final class PhabricatorTokenGivenFeedStory
return $phids;
}
public function getRequiredObjectPHIDs() {
$phids = array();
$phids[] = $this->getValue('tokenPHID');
return $phids;
}
public function renderView() {
$view = $this->newStoryView();
$view->setAppIcon('token-dark');
@ -22,10 +28,13 @@ final class PhabricatorTokenGivenFeedStory
$href = $this->getHandle($this->getPrimaryObjectPHID())->getURI();
$view->setHref($href);
$token = $this->getObject($this->getValue('tokenPHID'));
$title = pht(
'%s awarded %s a token.',
'%s awarded %s a %s token.',
$this->linkTo($this->getValue('authorPHID')),
$this->linkTo($this->getValue('objectPHID')));
$this->linkTo($this->getValue('objectPHID')),
$token->getName());
$view->setTitle($title);
$view->setImage($this->getHandle($author_phid)->getImageURI());

View file

@ -0,0 +1,44 @@
<?php
final class PhabricatorTokenPHIDTypeToken extends PhabricatorPHIDType {
const TYPECONST = 'TOKN';
public function getTypeConstant() {
return self::TYPECONST;
}
public function getTypeName() {
return pht('Token');
}
public function newObject() {
return new PhabricatorToken();
}
public function loadObjects(
PhabricatorObjectQuery $query,
array $phids) {
return id(new PhabricatorTokenQuery())
->setViewer($query->getViewer())
->setParentQuery($query)
->withPHIDs($phids)
->execute();
}
public function loadHandles(
PhabricatorHandleQuery $query,
array $handles,
array $objects) {
foreach ($handles as $phid => $handle) {
$token = $objects[$phid];
$name = $token->getName();
$handle->setName("{$name} Token");
}
}
}

View file

@ -45,6 +45,8 @@ final class PhabricatorTokenQuery
array('misc-4', pht('The World Burns')),
);
$type = PhabricatorTokenPHIDTypeToken::TYPECONST;
$tokens = array();
foreach ($specs as $id => $spec) {
list($image, $name) = $spec;
@ -52,7 +54,7 @@ final class PhabricatorTokenQuery
$token = id(new PhabricatorToken())
->setID($id)
->setName($name)
->setPHID('PHID-TOKN-'.$image);
->setPHID('PHID-'.$type.'-'.$image);
$tokens[] = $token;
}