Page MenuHomePhabricator

D15665.id37751.diff
No OneTemporary

D15665.id37751.diff

diff --git a/src/__phutil_library_map__.php b/src/__phutil_library_map__.php
--- a/src/__phutil_library_map__.php
+++ b/src/__phutil_library_map__.php
@@ -1880,6 +1880,7 @@
'PhabricatorBadgesController' => 'applications/badges/controller/PhabricatorBadgesController.php',
'PhabricatorBadgesCreateCapability' => 'applications/badges/capability/PhabricatorBadgesCreateCapability.php',
'PhabricatorBadgesDAO' => 'applications/badges/storage/PhabricatorBadgesDAO.php',
+ 'PhabricatorBadgesDatasource' => 'applications/badges/typeahead/PhabricatorBadgesDatasource.php',
'PhabricatorBadgesDefaultEditCapability' => 'applications/badges/capability/PhabricatorBadgesDefaultEditCapability.php',
'PhabricatorBadgesEditConduitAPIMethod' => 'applications/badges/conduit/PhabricatorBadgesEditConduitAPIMethod.php',
'PhabricatorBadgesEditController' => 'applications/badges/controller/PhabricatorBadgesEditController.php',
@@ -6264,6 +6265,7 @@
'PhabricatorBadgesController' => 'PhabricatorController',
'PhabricatorBadgesCreateCapability' => 'PhabricatorPolicyCapability',
'PhabricatorBadgesDAO' => 'PhabricatorLiskDAO',
+ 'PhabricatorBadgesDatasource' => 'PhabricatorTypeaheadDatasource',
'PhabricatorBadgesDefaultEditCapability' => 'PhabricatorPolicyCapability',
'PhabricatorBadgesEditConduitAPIMethod' => 'PhabricatorEditEngineAPIMethod',
'PhabricatorBadgesEditController' => 'PhabricatorBadgesController',
diff --git a/src/applications/badges/controller/PhabricatorBadgesAwardController.php b/src/applications/badges/controller/PhabricatorBadgesAwardController.php
--- a/src/applications/badges/controller/PhabricatorBadgesAwardController.php
+++ b/src/applications/badges/controller/PhabricatorBadgesAwardController.php
@@ -19,10 +19,10 @@
if ($request->isFormPost()) {
$xactions = array();
- $badge_phid = $request->getStr('badgePHID');
+ $badge_phids = $request->getArr('badgePHID');
$badge = id(new PhabricatorBadgesQuery())
->setViewer($viewer)
- ->withPHIDs(array($badge_phid))
+ ->withPHIDs($badge_phids)
->needRecipients(true)
->requireCapabilities(
array(
@@ -50,28 +50,33 @@
->setURI($view_uri);
}
- $badges = id(new PhabricatorBadgesQuery())
- ->setViewer($viewer)
- ->withStatuses(array(
- PhabricatorBadgesBadge::STATUS_ACTIVE,
- ))
- ->requireCapabilities(
- array(
- PhabricatorPolicyCapability::CAN_VIEW,
- PhabricatorPolicyCapability::CAN_EDIT,
- ))
- ->execute();
+ // $badges = id(new PhabricatorBadgesQuery())
+ // ->setViewer($viewer)
+ // ->withStatuses(array(
+ // PhabricatorBadgesBadge::STATUS_ACTIVE,
+ // ))
+ // ->requireCapabilities(
+ // array(
+ // PhabricatorPolicyCapability::CAN_VIEW,
+ // PhabricatorPolicyCapability::CAN_EDIT,
+ // ))
+ // ->execute();
- $options = mpull($badges, 'getName', 'getPHID');
- asort($options);
+ // $options = mpull($badges, 'getName', 'getPHID');
+ // asort($options);
$form = id(new AphrontFormView())
->setUser($viewer)
- ->appendChild(
- id(new AphrontFormSelectControl())
+ ->appendControl(
+ id(new AphrontFormTokenizerControl())
->setLabel(pht('Badge'))
->setName('badgePHID')
- ->setOptions($options));
+ ->setDatasource(
+ id(new PhabricatorBadgesDatasource())
+ ->setParameters(
+ array(
+ 'recipientPHID' => $user->getPHID(),
+ ))));
$dialog = $this->newDialog()
->setTitle(pht('Grant Badge'))
diff --git a/src/applications/badges/typeahead/PhabricatorBadgesDatasource.php b/src/applications/badges/typeahead/PhabricatorBadgesDatasource.php
new file mode 100644
--- /dev/null
+++ b/src/applications/badges/typeahead/PhabricatorBadgesDatasource.php
@@ -0,0 +1,64 @@
+<?php
+
+final class PhabricatorBadgesDatasource
+ extends PhabricatorTypeaheadDatasource {
+
+ public function getBrowseTitle() {
+ return pht('Browse Badges');
+ }
+
+ public function getPlaceholderText() {
+ return pht('Type a badge name...');
+ }
+
+ public function getDatasourceApplicationClass() {
+ return 'PhabricatorBadgesApplication';
+ }
+
+ public function loadResults() {
+ $viewer = $this->getViewer();
+ $raw_query = $this->getRawQuery();
+
+ $params = $this->getParameters();
+ $recipient_phid = $params['recipientPHID'];
+
+ $badges = id(new PhabricatorBadgesQuery())
+ ->setViewer($viewer)
+ ->needRecipients(true)
+ ->requireCapabilities(
+ array(
+ PhabricatorPolicyCapability::CAN_VIEW,
+ PhabricatorPolicyCapability::CAN_EDIT,
+ ))
+ ->execute();
+
+ $results = array();
+ foreach ($badges as $badge) {
+ $closed = null;
+
+ $awards = $badge->getAwards();
+ $awarded_users = mpull($awards, null, 'getRecipientPHID');
+ if (idx($awarded_users, $recipient_phid, null)) {
+ $closed = pht('Already awarded');
+ }
+
+ $status = $badge->getStatus();
+ if ($status === PhabricatorBadgesBadge::STATUS_ARCHIVED) {
+ $closed = pht('Archived');
+ }
+
+ $results[] = id(new PhabricatorTypeaheadResult())
+ ->setName($badge->getName())
+ ->setIcon($badge->getIcon())
+ ->setColor(
+ PhabricatorBadgesQuality::getQualityColor($badge->getQuality()))
+ ->setClosed($closed)
+ ->setPHID($badge->getPHID());
+ }
+
+ $results = $this->filterResultsAgainstTokens($results);
+
+ return $results;
+ }
+
+}

File Metadata

Mime Type
text/plain
Expires
Thu, Dec 26, 11:11 AM (12 h, 3 m)
Storage Engine
blob
Storage Format
Encrypted (AES-256-CBC)
Storage Handle
6929155
Default Alt Text
D15665.id37751.diff (5 KB)

Event Timeline