mirror of
https://we.phorge.it/source/phorge.git
synced 2025-04-02 23:48:18 +02: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:
parent
a72d18765f
commit
fd69dfaa9a
4 changed files with 52 additions and 13 deletions
|
@ -6,7 +6,7 @@ final class PhabricatorBadgesAwardQuery
|
||||||
private $badgePHIDs;
|
private $badgePHIDs;
|
||||||
private $recipientPHIDs;
|
private $recipientPHIDs;
|
||||||
private $awarderPHIDs;
|
private $awarderPHIDs;
|
||||||
|
private $badgeStatuses = null;
|
||||||
|
|
||||||
protected function willFilterPage(array $awards) {
|
protected function willFilterPage(array $awards) {
|
||||||
$badge_phids = array();
|
$badge_phids = array();
|
||||||
|
@ -22,6 +22,11 @@ final class PhabricatorBadgesAwardQuery
|
||||||
$badges = mpull($badges, null, 'getPHID');
|
$badges = mpull($badges, null, 'getPHID');
|
||||||
foreach ($awards as $key => $award) {
|
foreach ($awards as $key => $award) {
|
||||||
$award_badge = idx($badges, $award->getBadgePHID());
|
$award_badge = idx($badges, $award->getBadgePHID());
|
||||||
|
if (!$award_badge) {
|
||||||
|
unset($awards[$key]);
|
||||||
|
$this->didRejectResult($award);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
$award->attachBadge($award_badge);
|
$award->attachBadge($award_badge);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -43,6 +48,15 @@ final class PhabricatorBadgesAwardQuery
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function withBadgeStatuses(array $statuses) {
|
||||||
|
$this->badgeStatuses = $statuses;
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
private function shouldJoinBadge() {
|
||||||
|
return (bool)$this->badgeStatuses;
|
||||||
|
}
|
||||||
|
|
||||||
protected function loadPage() {
|
protected function loadPage() {
|
||||||
return $this->loadStandardPage($this->newResultObject());
|
return $this->loadStandardPage($this->newResultObject());
|
||||||
}
|
}
|
||||||
|
@ -51,33 +65,59 @@ final class PhabricatorBadgesAwardQuery
|
||||||
return new PhabricatorBadgesAward();
|
return new PhabricatorBadgesAward();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected function getPrimaryTableAlias() {
|
||||||
|
return 'badges_award';
|
||||||
|
}
|
||||||
|
|
||||||
protected function buildWhereClauseParts(AphrontDatabaseConnection $conn) {
|
protected function buildWhereClauseParts(AphrontDatabaseConnection $conn) {
|
||||||
$where = parent::buildWhereClauseParts($conn);
|
$where = parent::buildWhereClauseParts($conn);
|
||||||
|
|
||||||
if ($this->badgePHIDs !== null) {
|
if ($this->badgePHIDs !== null) {
|
||||||
$where[] = qsprintf(
|
$where[] = qsprintf(
|
||||||
$conn,
|
$conn,
|
||||||
'badgePHID IN (%Ls)',
|
'badges_award.badgePHID IN (%Ls)',
|
||||||
$this->badgePHIDs);
|
$this->badgePHIDs);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($this->recipientPHIDs !== null) {
|
if ($this->recipientPHIDs !== null) {
|
||||||
$where[] = qsprintf(
|
$where[] = qsprintf(
|
||||||
$conn,
|
$conn,
|
||||||
'recipientPHID IN (%Ls)',
|
'badges_award.recipientPHID IN (%Ls)',
|
||||||
$this->recipientPHIDs);
|
$this->recipientPHIDs);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($this->awarderPHIDs !== null) {
|
if ($this->awarderPHIDs !== null) {
|
||||||
$where[] = qsprintf(
|
$where[] = qsprintf(
|
||||||
$conn,
|
$conn,
|
||||||
'awarderPHID IN (%Ls)',
|
'badges_award.awarderPHID IN (%Ls)',
|
||||||
$this->awarderPHIDs);
|
$this->awarderPHIDs);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ($this->badgeStatuses !== null) {
|
||||||
|
$where[] = qsprintf(
|
||||||
|
$conn,
|
||||||
|
'badges_badge.status IN (%Ls)',
|
||||||
|
$this->badgeStatuses);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
return $where;
|
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() {
|
public function getQueryApplicationClass() {
|
||||||
return 'PhabricatorBadgesApplication';
|
return 'PhabricatorBadgesApplication';
|
||||||
}
|
}
|
||||||
|
|
|
@ -84,16 +84,15 @@ final class PhabricatorPeopleProfileBadgesController
|
||||||
$awards = id(new PhabricatorBadgesAwardQuery())
|
$awards = id(new PhabricatorBadgesAwardQuery())
|
||||||
->setViewer($viewer)
|
->setViewer($viewer)
|
||||||
->withRecipientPHIDs(array($user->getPHID()))
|
->withRecipientPHIDs(array($user->getPHID()))
|
||||||
|
->withBadgeStatuses(array(PhabricatorBadgesBadge::STATUS_ACTIVE))
|
||||||
->execute();
|
->execute();
|
||||||
$awards = mpull($awards, null, 'getBadgePHID');
|
$awards = mpull($awards, null, 'getBadgePHID');
|
||||||
|
|
||||||
$badges = array();
|
$badges = array();
|
||||||
foreach ($awards as $award) {
|
foreach ($awards as $award) {
|
||||||
$badge = $award->getBadge();
|
$badge = $award->getBadge();
|
||||||
if ($badge->getStatus() == PhabricatorBadgesBadge::STATUS_ACTIVE) {
|
|
||||||
$badges[$award->getBadgePHID()] = $badge;
|
$badges[$award->getBadgePHID()] = $badge;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
if (count($badges)) {
|
if (count($badges)) {
|
||||||
$flex = new PHUIBadgeBoxView();
|
$flex = new PHUIBadgeBoxView();
|
||||||
|
|
|
@ -528,12 +528,14 @@ class PhabricatorApplicationTransactionCommentView extends AphrontView {
|
||||||
$awards = id(new PhabricatorBadgesAwardQuery())
|
$awards = id(new PhabricatorBadgesAwardQuery())
|
||||||
->setViewer($this->getUser())
|
->setViewer($this->getUser())
|
||||||
->withRecipientPHIDs(array($user->getPHID()))
|
->withRecipientPHIDs(array($user->getPHID()))
|
||||||
|
->withBadgeStatuses(array(PhabricatorBadgesBadge::STATUS_ACTIVE))
|
||||||
->setLimit(2)
|
->setLimit(2)
|
||||||
->execute();
|
->execute();
|
||||||
|
|
||||||
$badge_view = null;
|
|
||||||
if ($awards) {
|
|
||||||
$badges = mpull($awards, 'getBadge');
|
$badges = mpull($awards, 'getBadge');
|
||||||
|
|
||||||
|
$badge_view = null;
|
||||||
|
if ($badges) {
|
||||||
$badge_list = array();
|
$badge_list = array();
|
||||||
foreach ($badges as $badge) {
|
foreach ($badges as $badge) {
|
||||||
$badge_view = id(new PHUIBadgeMiniView())
|
$badge_view = id(new PHUIBadgeMiniView())
|
||||||
|
|
|
@ -220,7 +220,6 @@ final class PHUITimelineView extends AphrontView {
|
||||||
}
|
}
|
||||||
|
|
||||||
$user_phid_type = PhabricatorPeopleUserPHIDType::TYPECONST;
|
$user_phid_type = PhabricatorPeopleUserPHIDType::TYPECONST;
|
||||||
$badge_edge_type = PhabricatorRecipientHasBadgeEdgeType::EDGECONST;
|
|
||||||
|
|
||||||
$user_phids = array();
|
$user_phids = array();
|
||||||
foreach ($events as $key => $event) {
|
foreach ($events as $key => $event) {
|
||||||
|
@ -248,6 +247,7 @@ final class PHUITimelineView extends AphrontView {
|
||||||
$awards = id(new PhabricatorBadgesAwardQuery())
|
$awards = id(new PhabricatorBadgesAwardQuery())
|
||||||
->setViewer($this->getViewer())
|
->setViewer($this->getViewer())
|
||||||
->withRecipientPHIDs($user_phids)
|
->withRecipientPHIDs($user_phids)
|
||||||
|
->withBadgeStatuses(array(PhabricatorBadgesBadge::STATUS_ACTIVE))
|
||||||
->execute();
|
->execute();
|
||||||
|
|
||||||
$awards = mgroup($awards, 'getRecipientPHID');
|
$awards = mgroup($awards, 'getRecipientPHID');
|
||||||
|
@ -259,10 +259,8 @@ final class PHUITimelineView extends AphrontView {
|
||||||
$badges = array();
|
$badges = array();
|
||||||
foreach ($author_awards as $award) {
|
foreach ($author_awards as $award) {
|
||||||
$badge = $award->getBadge();
|
$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
|
// TODO: Pick the "best" badges in some smart way. For now, just pick
|
||||||
// the first two.
|
// the first two.
|
||||||
|
|
Loading…
Add table
Reference in a new issue