mirror of
https://we.phorge.it/source/phorge.git
synced 2024-11-22 14:52:41 +01:00
Converting badge quality property from color to an integer representation for later sorting purposes
Summary: Ref T9007 Test Plan: Create badges, update quality, search by quality without change of functionality. Reviewers: epriestley, #blessed_reviewers Reviewed By: epriestley, #blessed_reviewers Subscribers: Korvin Maniphest Tasks: T9007 Differential Revision: https://secure.phabricator.com/D15551
This commit is contained in:
parent
d9bb66f610
commit
00425cac94
12 changed files with 199 additions and 68 deletions
32
resources/sql/autopatches/20160330.badges.migratequality.sql
Normal file
32
resources/sql/autopatches/20160330.badges.migratequality.sql
Normal file
|
@ -0,0 +1,32 @@
|
|||
/* Change quality from color to int */
|
||||
|
||||
UPDATE {$NAMESPACE}_badges.badges_badge
|
||||
SET quality = 140
|
||||
WHERE quality = 'grey';
|
||||
|
||||
UPDATE {$NAMESPACE}_badges.badges_badge
|
||||
SET quality = 120
|
||||
WHERE quality = 'white';
|
||||
|
||||
UPDATE {$NAMESPACE}_badges.badges_badge
|
||||
SET quality = 100
|
||||
WHERE quality = 'green';
|
||||
|
||||
UPDATE {$NAMESPACE}_badges.badges_badge
|
||||
SET quality = 80
|
||||
WHERE quality = 'blue';
|
||||
|
||||
UPDATE {$NAMESPACE}_badges.badges_badge
|
||||
SET quality = 60
|
||||
WHERE quality = 'indigo';
|
||||
|
||||
UPDATE {$NAMESPACE}_badges.badges_badge
|
||||
SET quality = 40
|
||||
WHERE quality = 'orange';
|
||||
|
||||
UPDATE {$NAMESPACE}_badges.badges_badge
|
||||
SET quality = 20
|
||||
WHERE quality = 'yellow';
|
||||
|
||||
ALTER TABLE {$NAMESPACE}_badges.badges_badge
|
||||
MODIFY quality INT UNSIGNED NOT NULL;
|
|
@ -0,0 +1,59 @@
|
|||
/* Migrate old badge quality transactions */
|
||||
|
||||
UPDATE {$NAMESPACE}_badges.badges_transaction
|
||||
SET oldValue = 140
|
||||
WHERE oldValue = '"grey"' AND transactionType = 'badges:quality';
|
||||
|
||||
UPDATE {$NAMESPACE}_badges.badges_transaction
|
||||
SET oldValue = 120
|
||||
WHERE oldValue = '"white"' AND transactionType = 'badges:quality';
|
||||
|
||||
UPDATE {$NAMESPACE}_badges.badges_transaction
|
||||
SET oldValue = 100
|
||||
WHERE oldValue = '"green"' AND transactionType = 'badges:quality';
|
||||
|
||||
UPDATE {$NAMESPACE}_badges.badges_transaction
|
||||
SET oldValue = 80
|
||||
WHERE oldValue = '"blue"' AND transactionType = 'badges:quality';
|
||||
|
||||
UPDATE {$NAMESPACE}_badges.badges_transaction
|
||||
SET oldValue = 60
|
||||
WHERE oldValue = '"indigo"' AND transactionType = 'badges:quality';
|
||||
|
||||
UPDATE {$NAMESPACE}_badges.badges_transaction
|
||||
SET oldValue = 40
|
||||
WHERE oldValue = '"orange"' AND transactionType = 'badges:quality';
|
||||
|
||||
UPDATE {$NAMESPACE}_badges.badges_transaction
|
||||
SET oldValue = 20
|
||||
WHERE oldValue = '"yellow"' AND transactionType = 'badges:quality';
|
||||
|
||||
|
||||
|
||||
UPDATE {$NAMESPACE}_badges.badges_transaction
|
||||
SET newValue = 140
|
||||
WHERE newValue = '"grey"' AND transactionType = 'badges:quality';
|
||||
|
||||
UPDATE {$NAMESPACE}_badges.badges_transaction
|
||||
SET newValue = 120
|
||||
WHERE newValue = '"white"' AND transactionType = 'badges:quality';
|
||||
|
||||
UPDATE {$NAMESPACE}_badges.badges_transaction
|
||||
SET newValue = 100
|
||||
WHERE newValue = '"green"' AND transactionType = 'badges:quality';
|
||||
|
||||
UPDATE {$NAMESPACE}_badges.badges_transaction
|
||||
SET newValue = 80
|
||||
WHERE newValue = '"blue"' AND transactionType = 'badges:quality';
|
||||
|
||||
UPDATE {$NAMESPACE}_badges.badges_transaction
|
||||
SET newValue = 60
|
||||
WHERE newValue = '"indigo"' AND transactionType = 'badges:quality';
|
||||
|
||||
UPDATE {$NAMESPACE}_badges.badges_transaction
|
||||
SET newValue = 40
|
||||
WHERE newValue = '"orange"' AND transactionType = 'badges:quality';
|
||||
|
||||
UPDATE {$NAMESPACE}_badges.badges_transaction
|
||||
SET newValue = 20
|
||||
WHERE newValue = '"yellow"' AND transactionType = 'badges:quality';
|
|
@ -1880,6 +1880,7 @@ phutil_register_library_map(array(
|
|||
'PhabricatorBadgesListController' => 'applications/badges/controller/PhabricatorBadgesListController.php',
|
||||
'PhabricatorBadgesMailReceiver' => 'applications/badges/mail/PhabricatorBadgesMailReceiver.php',
|
||||
'PhabricatorBadgesPHIDType' => 'applications/badges/phid/PhabricatorBadgesPHIDType.php',
|
||||
'PhabricatorBadgesQuality' => 'applications/badges/constants/PhabricatorBadgesQuality.php',
|
||||
'PhabricatorBadgesQuery' => 'applications/badges/query/PhabricatorBadgesQuery.php',
|
||||
'PhabricatorBadgesRecipientsListView' => 'applications/badges/view/PhabricatorBadgesRecipientsListView.php',
|
||||
'PhabricatorBadgesRemoveRecipientsController' => 'applications/badges/controller/PhabricatorBadgesRemoveRecipientsController.php',
|
||||
|
@ -6245,6 +6246,7 @@ phutil_register_library_map(array(
|
|||
'PhabricatorBadgesListController' => 'PhabricatorBadgesController',
|
||||
'PhabricatorBadgesMailReceiver' => 'PhabricatorObjectMailReceiver',
|
||||
'PhabricatorBadgesPHIDType' => 'PhabricatorPHIDType',
|
||||
'PhabricatorBadgesQuality' => 'Phobject',
|
||||
'PhabricatorBadgesQuery' => 'PhabricatorCursorPagedPolicyAwareQuery',
|
||||
'PhabricatorBadgesRecipientsListView' => 'AphrontView',
|
||||
'PhabricatorBadgesRemoveRecipientsController' => 'PhabricatorBadgesController',
|
||||
|
|
|
@ -0,0 +1,78 @@
|
|||
<?php
|
||||
|
||||
final class PhabricatorBadgesQuality
|
||||
extends Phobject {
|
||||
|
||||
const POOR = 140;
|
||||
const COMMON = 120;
|
||||
const UNCOMMON = 100;
|
||||
const RARE = 80;
|
||||
const EPIC = 60;
|
||||
const LEGENDARY = 40;
|
||||
const HEIRLOOM = 20;
|
||||
|
||||
const DEFAULT_QUALITY = 140;
|
||||
|
||||
public static function getQualityName($quality) {
|
||||
$map = self::getQualityDictionary($quality);
|
||||
$default = pht('Unknown Quality ("%s")', $quality);
|
||||
return idx($map, 'name', $default);
|
||||
}
|
||||
|
||||
public static function getQualityColor($quality) {
|
||||
$map = self::getQualityDictionary($quality);
|
||||
$default = 'grey';
|
||||
return idx($map, 'color', $default);
|
||||
}
|
||||
|
||||
private static function getQualityDictionary($quality) {
|
||||
$map = self::getQualityMap();
|
||||
$default = array();
|
||||
return idx($map, $quality, $default);
|
||||
}
|
||||
|
||||
public static function getQualityMap() {
|
||||
return array(
|
||||
self::POOR => array(
|
||||
'rarity' => 140,
|
||||
'name' => pht('Poor'),
|
||||
'color' => 'grey',
|
||||
),
|
||||
self::COMMON => array(
|
||||
'rarity' => 120,
|
||||
'name' => pht('Common'),
|
||||
'color' => 'white',
|
||||
),
|
||||
self::UNCOMMON => array(
|
||||
'rarity' => 100,
|
||||
'name' => pht('Uncommon'),
|
||||
'color' => 'green',
|
||||
),
|
||||
self::RARE => array(
|
||||
'rarity' => 80,
|
||||
'name' => pht('Rare'),
|
||||
'color' => 'blue',
|
||||
),
|
||||
self::EPIC => array(
|
||||
'rarity' => 60,
|
||||
'name' => pht('Epic'),
|
||||
'color' => 'indigo',
|
||||
),
|
||||
self::LEGENDARY => array(
|
||||
'rarity' => 40,
|
||||
'name' => pht('Legendary'),
|
||||
'color' => 'orange',
|
||||
),
|
||||
self::HEIRLOOM => array(
|
||||
'rarity' => 20,
|
||||
'name' => pht('Heirloom'),
|
||||
'color' => 'yellow',
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
public static function getDropdownQualityMap() {
|
||||
$map = self::getQualityMap();
|
||||
return ipull($map, 'name');
|
||||
}
|
||||
}
|
|
@ -86,11 +86,12 @@ final class PhabricatorBadgesViewController
|
|||
$view = id(new PHUIPropertyListView())
|
||||
->setUser($viewer);
|
||||
|
||||
$quality = idx($badge->getQualityNameMap(), $badge->getQuality());
|
||||
$quality_name = PhabricatorBadgesQuality::getQualityName(
|
||||
$badge->getQuality());
|
||||
|
||||
$view->addProperty(
|
||||
pht('Quality'),
|
||||
$quality);
|
||||
$quality_name);
|
||||
|
||||
$view->addProperty(
|
||||
pht('Icon'),
|
||||
|
|
|
@ -89,7 +89,7 @@ final class PhabricatorBadgesEditEngine
|
|||
->setLabel(pht('Quality'))
|
||||
->setValue($object->getQuality())
|
||||
->setTransactionType(PhabricatorBadgesTransaction::TYPE_QUALITY)
|
||||
->setOptions($object->getQualityNameMap()),
|
||||
->setOptions(PhabricatorBadgesQuality::getDropdownQualityMap()),
|
||||
id(new PhabricatorRemarkupEditField())
|
||||
->setKey('description')
|
||||
->setLabel(pht('Description'))
|
||||
|
|
|
@ -66,10 +66,11 @@ final class PhabricatorBadgesEditor
|
|||
case PhabricatorBadgesTransaction::TYPE_DESCRIPTION:
|
||||
case PhabricatorBadgesTransaction::TYPE_ICON:
|
||||
case PhabricatorBadgesTransaction::TYPE_STATUS:
|
||||
case PhabricatorBadgesTransaction::TYPE_QUALITY:
|
||||
case PhabricatorBadgesTransaction::TYPE_AWARD:
|
||||
case PhabricatorBadgesTransaction::TYPE_REVOKE:
|
||||
return $xaction->getNewValue();
|
||||
case PhabricatorBadgesTransaction::TYPE_QUALITY:
|
||||
return (int)$xaction->getNewValue();
|
||||
}
|
||||
|
||||
return parent::getCustomTransactionNewValue($object, $xaction);
|
||||
|
|
|
@ -34,9 +34,7 @@ final class PhabricatorBadgesSearchEngine
|
|||
id(new PhabricatorSearchCheckboxesField())
|
||||
->setKey('qualities')
|
||||
->setLabel(pht('Quality'))
|
||||
->setOptions(
|
||||
id(new PhabricatorBadgesBadge())
|
||||
->getQualityNameMap()),
|
||||
->setOptions(PhabricatorBadgesQuality::getDropdownQualityMap()),
|
||||
id(new PhabricatorSearchCheckboxesField())
|
||||
->setKey('statuses')
|
||||
->setLabel(pht('Status'))
|
||||
|
@ -110,8 +108,9 @@ final class PhabricatorBadgesSearchEngine
|
|||
|
||||
$list = id(new PHUIObjectItemListView());
|
||||
foreach ($badges as $badge) {
|
||||
$quality_name = PhabricatorBadgesQuality::getQualityName(
|
||||
$badge->getQuality());
|
||||
|
||||
$quality = idx($badge->getQualityNameMap(), $badge->getQuality());
|
||||
$mini_badge = id(new PHUIBadgeMiniView())
|
||||
->setHeader($badge->getName())
|
||||
->setIcon($badge->getIcon())
|
||||
|
@ -121,7 +120,7 @@ final class PhabricatorBadgesSearchEngine
|
|||
->setHeader($badge->getName())
|
||||
->setBadge($mini_badge)
|
||||
->setHref('/badges/view/'.$badge->getID().'/')
|
||||
->addAttribute($quality)
|
||||
->addAttribute($quality_name)
|
||||
->addAttribute($badge->getFlavor());
|
||||
|
||||
if ($badge->isArchived()) {
|
||||
|
|
|
@ -25,15 +25,6 @@ final class PhabricatorBadgesBadge extends PhabricatorBadgesDAO
|
|||
const STATUS_ARCHIVED = 'closed';
|
||||
|
||||
const DEFAULT_ICON = 'fa-star';
|
||||
const DEFAULT_QUALITY = 'green';
|
||||
|
||||
const POOR = 'grey';
|
||||
const COMMON = 'white';
|
||||
const UNCOMMON = 'green';
|
||||
const RARE = 'blue';
|
||||
const EPIC = 'indigo';
|
||||
const LEGENDARY = 'orange';
|
||||
const HEIRLOOM = 'yellow';
|
||||
|
||||
public static function getStatusNameMap() {
|
||||
return array(
|
||||
|
@ -42,18 +33,6 @@ final class PhabricatorBadgesBadge extends PhabricatorBadgesDAO
|
|||
);
|
||||
}
|
||||
|
||||
public static function getQualityNameMap() {
|
||||
return array(
|
||||
self::POOR => pht('Poor'),
|
||||
self::COMMON => pht('Common'),
|
||||
self::UNCOMMON => pht('Uncommon'),
|
||||
self::RARE => pht('Rare'),
|
||||
self::EPIC => pht('Epic'),
|
||||
self::LEGENDARY => pht('Legendary'),
|
||||
self::HEIRLOOM => pht('Heirloom'),
|
||||
);
|
||||
}
|
||||
|
||||
public static function initializeNewBadge(PhabricatorUser $actor) {
|
||||
$app = id(new PhabricatorApplicationQuery())
|
||||
->setViewer($actor)
|
||||
|
@ -67,7 +46,7 @@ final class PhabricatorBadgesBadge extends PhabricatorBadgesDAO
|
|||
|
||||
return id(new PhabricatorBadgesBadge())
|
||||
->setIcon(self::DEFAULT_ICON)
|
||||
->setQuality(self::DEFAULT_QUALITY)
|
||||
->setQuality(PhabricatorBadgesQuality::DEFAULT_QUALITY)
|
||||
->setCreatorPHID($actor->getPHID())
|
||||
->setEditPolicy($edit_policy)
|
||||
->setStatus(self::STATUS_ACTIVE);
|
||||
|
@ -81,7 +60,7 @@ final class PhabricatorBadgesBadge extends PhabricatorBadgesDAO
|
|||
'flavor' => 'text255',
|
||||
'description' => 'text',
|
||||
'icon' => 'text255',
|
||||
'quality' => 'text255',
|
||||
'quality' => 'uint32',
|
||||
'status' => 'text32',
|
||||
'mailKey' => 'bytes20',
|
||||
),
|
||||
|
|
|
@ -111,9 +111,8 @@ final class PhabricatorBadgesTransaction
|
|||
$this->renderHandleLink($author_phid),
|
||||
$new);
|
||||
} else {
|
||||
$qual_map = PhabricatorBadgesBadge::getQualityNameMap();
|
||||
$qual_new = idx($qual_map, $new, $new);
|
||||
$qual_old = idx($qual_map, $old, $old);
|
||||
$qual_new = PhabricatorBadgesQuality::getQualityName($new);
|
||||
$qual_old = PhabricatorBadgesQuality::getQualityName($old);
|
||||
return pht(
|
||||
'%s updated the quality for this badge from "%s" to "%s".',
|
||||
$this->renderHandleLink($author_phid),
|
||||
|
|
|
@ -48,7 +48,9 @@ final class PHUIBadgeMiniView extends AphrontTagView {
|
|||
$classes = array();
|
||||
$classes[] = 'phui-badge-mini';
|
||||
if ($this->quality) {
|
||||
$classes[] = 'phui-badge-mini-'.$this->quality;
|
||||
$quality_color = PhabricatorBadgesQuality::getQualityColor(
|
||||
$this->quality);
|
||||
$classes[] = 'phui-badge-mini-'.$quality_color;
|
||||
}
|
||||
|
||||
return array(
|
||||
|
|
|
@ -10,16 +10,6 @@ final class PHUIBadgeView extends AphrontTagView {
|
|||
private $subhead;
|
||||
private $bylines = array();
|
||||
|
||||
// Yes, World of Warcraft Item Quality
|
||||
const POOR = 'grey';
|
||||
const COMMON = 'white';
|
||||
const UNCOMMON = 'green';
|
||||
const RARE = 'blue';
|
||||
const EPIC = 'indigo';
|
||||
const LEGENDARY = 'orange';
|
||||
const HEIRLOOM = 'yellow';
|
||||
|
||||
|
||||
public function setIcon($icon) {
|
||||
$this->icon = $icon;
|
||||
return $this;
|
||||
|
@ -35,6 +25,14 @@ final class PHUIBadgeView extends AphrontTagView {
|
|||
return $this;
|
||||
}
|
||||
|
||||
private function getQualityColor() {
|
||||
return PhabricatorBadgesQuality::getQualityColor($this->quality);
|
||||
}
|
||||
|
||||
private function getQualityName() {
|
||||
return PhabricatorBadgesQuality::getQualityName($this->quality);
|
||||
}
|
||||
|
||||
public function setSource($source) {
|
||||
$this->source = $source;
|
||||
return $this;
|
||||
|
@ -55,26 +53,6 @@ final class PHUIBadgeView extends AphrontTagView {
|
|||
return $this;
|
||||
}
|
||||
|
||||
private function getQualityTitle() {
|
||||
|
||||
switch ($this->quality) {
|
||||
case self::POOR:
|
||||
return pht('Poor');
|
||||
case self::COMMON:
|
||||
return pht('Common');
|
||||
case self::UNCOMMON:
|
||||
return pht('Uncommon');
|
||||
case self::RARE:
|
||||
return pht('Rare');
|
||||
case self::EPIC:
|
||||
return pht('Epic');
|
||||
case self::LEGENDARY:
|
||||
return pht('Legendary');
|
||||
case self::HEIRLOOM:
|
||||
return pht('Heirloom');
|
||||
}
|
||||
}
|
||||
|
||||
protected function getTagName() {
|
||||
return 'span';
|
||||
}
|
||||
|
@ -86,7 +64,8 @@ final class PHUIBadgeView extends AphrontTagView {
|
|||
$classes = array();
|
||||
$classes[] = 'phui-badge-view';
|
||||
if ($this->quality) {
|
||||
$classes[] = 'phui-badge-view-'.$this->quality;
|
||||
$color = $this->getQualityColor();
|
||||
$classes[] = 'phui-badge-view-'.$color;
|
||||
}
|
||||
|
||||
return array(
|
||||
|
@ -131,7 +110,7 @@ final class PHUIBadgeView extends AphrontTagView {
|
|||
),
|
||||
array($header, $subhead));
|
||||
|
||||
$quality = phutil_tag_div('phui-badge-quality', $this->getQualityTitle());
|
||||
$quality = phutil_tag_div('phui-badge-quality', $this->getQualityName());
|
||||
$source = phutil_tag_div('phui-badge-source', $this->source);
|
||||
|
||||
$bylines = array();
|
||||
|
|
Loading…
Reference in a new issue