1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-12-23 05:50:55 +01:00

Allow searching for Badge Awards by Badge status

Summary: Fixes T12398. This adds `withBadgeStatuses` as a query parameter when searching for Awards to show. In most (all?) cases we currently only show active badges.

Test Plan: Assign myself a badge, archive it and verify it does not appear on profile, comment form, or timeline.

Reviewers: epriestley

Reviewed By: epriestley

Subscribers: Korvin

Maniphest Tasks: T12398

Differential Revision: https://secure.phabricator.com/D17499
This commit is contained in:
Chad Little 2017-03-15 12:43:54 -07:00
parent a72d18765f
commit fd69dfaa9a
4 changed files with 52 additions and 13 deletions

View file

@ -6,7 +6,7 @@ final class PhabricatorBadgesAwardQuery
private $badgePHIDs;
private $recipientPHIDs;
private $awarderPHIDs;
private $badgeStatuses = null;
protected function willFilterPage(array $awards) {
$badge_phids = array();
@ -22,6 +22,11 @@ final class PhabricatorBadgesAwardQuery
$badges = mpull($badges, null, 'getPHID');
foreach ($awards as $key => $award) {
$award_badge = idx($badges, $award->getBadgePHID());
if (!$award_badge) {
unset($awards[$key]);
$this->didRejectResult($award);
continue;
}
$award->attachBadge($award_badge);
}
@ -43,6 +48,15 @@ final class PhabricatorBadgesAwardQuery
return $this;
}
public function withBadgeStatuses(array $statuses) {
$this->badgeStatuses = $statuses;
return $this;
}
private function shouldJoinBadge() {
return (bool)$this->badgeStatuses;
}
protected function loadPage() {
return $this->loadStandardPage($this->newResultObject());
}
@ -51,33 +65,59 @@ final class PhabricatorBadgesAwardQuery
return new PhabricatorBadgesAward();
}
protected function getPrimaryTableAlias() {
return 'badges_award';
}
protected function buildWhereClauseParts(AphrontDatabaseConnection $conn) {
$where = parent::buildWhereClauseParts($conn);
if ($this->badgePHIDs !== null) {
$where[] = qsprintf(
$conn,
'badgePHID IN (%Ls)',
'badges_award.badgePHID IN (%Ls)',
$this->badgePHIDs);
}
if ($this->recipientPHIDs !== null) {
$where[] = qsprintf(
$conn,
'recipientPHID IN (%Ls)',
'badges_award.recipientPHID IN (%Ls)',
$this->recipientPHIDs);
}
if ($this->awarderPHIDs !== null) {
$where[] = qsprintf(
$conn,
'awarderPHID IN (%Ls)',
'badges_award.awarderPHID IN (%Ls)',
$this->awarderPHIDs);
}
if ($this->badgeStatuses !== null) {
$where[] = qsprintf(
$conn,
'badges_badge.status IN (%Ls)',
$this->badgeStatuses);
}
return $where;
}
protected function buildJoinClauseParts(AphrontDatabaseConnection $conn) {
$join = parent::buildJoinClauseParts($conn);
$badges = new PhabricatorBadgesBadge();
if ($this->shouldJoinBadge()) {
$join[] = qsprintf(
$conn,
'JOIN %T badges_badge ON badges_award.badgePHID = badges_badge.phid',
$badges->getTableName());
}
return $join;
}
public function getQueryApplicationClass() {
return 'PhabricatorBadgesApplication';
}

View file

@ -84,15 +84,14 @@ final class PhabricatorPeopleProfileBadgesController
$awards = id(new PhabricatorBadgesAwardQuery())
->setViewer($viewer)
->withRecipientPHIDs(array($user->getPHID()))
->withBadgeStatuses(array(PhabricatorBadgesBadge::STATUS_ACTIVE))
->execute();
$awards = mpull($awards, null, 'getBadgePHID');
$badges = array();
foreach ($awards as $award) {
$badge = $award->getBadge();
if ($badge->getStatus() == PhabricatorBadgesBadge::STATUS_ACTIVE) {
$badges[$award->getBadgePHID()] = $badge;
}
$badges[$award->getBadgePHID()] = $badge;
}
if (count($badges)) {

View file

@ -528,12 +528,14 @@ class PhabricatorApplicationTransactionCommentView extends AphrontView {
$awards = id(new PhabricatorBadgesAwardQuery())
->setViewer($this->getUser())
->withRecipientPHIDs(array($user->getPHID()))
->withBadgeStatuses(array(PhabricatorBadgesBadge::STATUS_ACTIVE))
->setLimit(2)
->execute();
$badges = mpull($awards, 'getBadge');
$badge_view = null;
if ($awards) {
$badges = mpull($awards, 'getBadge');
if ($badges) {
$badge_list = array();
foreach ($badges as $badge) {
$badge_view = id(new PHUIBadgeMiniView())

View file

@ -220,7 +220,6 @@ final class PHUITimelineView extends AphrontView {
}
$user_phid_type = PhabricatorPeopleUserPHIDType::TYPECONST;
$badge_edge_type = PhabricatorRecipientHasBadgeEdgeType::EDGECONST;
$user_phids = array();
foreach ($events as $key => $event) {
@ -248,6 +247,7 @@ final class PHUITimelineView extends AphrontView {
$awards = id(new PhabricatorBadgesAwardQuery())
->setViewer($this->getViewer())
->withRecipientPHIDs($user_phids)
->withBadgeStatuses(array(PhabricatorBadgesBadge::STATUS_ACTIVE))
->execute();
$awards = mgroup($awards, 'getRecipientPHID');
@ -259,9 +259,7 @@ final class PHUITimelineView extends AphrontView {
$badges = array();
foreach ($author_awards as $award) {
$badge = $award->getBadge();
if ($badge->getStatus() == PhabricatorBadgesBadge::STATUS_ACTIVE) {
$badges[$award->getBadgePHID()] = $badge;
}
$badges[$award->getBadgePHID()] = $badge;
}
// TODO: Pick the "best" badges in some smart way. For now, just pick