Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F14417052
D15665.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
6 KB
Referenced Files
None
Subscribers
None
D15665.diff
View Options
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',
@@ -6274,6 +6275,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
@@ -18,60 +18,52 @@
$view_uri = '/p/'.$user->getUsername();
if ($request->isFormPost()) {
- $xactions = array();
- $badge_phid = $request->getStr('badgePHID');
- $badge = id(new PhabricatorBadgesQuery())
+ $badge_phids = $request->getArr('badgePHIDs');
+ $badges = id(new PhabricatorBadgesQuery())
->setViewer($viewer)
- ->withPHIDs(array($badge_phid))
+ ->withPHIDs($badge_phids)
->needRecipients(true)
->requireCapabilities(
array(
PhabricatorPolicyCapability::CAN_EDIT,
PhabricatorPolicyCapability::CAN_VIEW,
))
- ->executeOne();
- if (!$badge) {
+ ->execute();
+ if (!$badges) {
return new Aphront404Response();
}
$award_phids = array($user->getPHID());
- $xactions[] = id(new PhabricatorBadgesTransaction())
- ->setTransactionType(PhabricatorBadgesTransaction::TYPE_AWARD)
- ->setNewValue($award_phids);
+ foreach ($badges as $badge) {
+ $xactions = array();
+ $xactions[] = id(new PhabricatorBadgesTransaction())
+ ->setTransactionType(PhabricatorBadgesTransaction::TYPE_AWARD)
+ ->setNewValue($award_phids);
- $editor = id(new PhabricatorBadgesEditor($badge))
- ->setActor($viewer)
- ->setContentSourceFromRequest($request)
- ->setContinueOnNoEffect(true)
- ->setContinueOnMissingFields(true)
- ->applyTransactions($badge, $xactions);
+ $editor = id(new PhabricatorBadgesEditor($badge))
+ ->setActor($viewer)
+ ->setContentSourceFromRequest($request)
+ ->setContinueOnNoEffect(true)
+ ->setContinueOnMissingFields(true)
+ ->applyTransactions($badge, $xactions);
+ }
return id(new AphrontRedirectResponse())
->setURI($view_uri);
}
- $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);
-
$form = id(new AphrontFormView())
->setUser($viewer)
- ->appendChild(
- id(new AphrontFormSelectControl())
+ ->appendControl(
+ id(new AphrontFormTokenizerControl())
->setLabel(pht('Badge'))
- ->setName('badgePHID')
- ->setOptions($options));
+ ->setName('badgePHIDs')
+ ->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,69 @@
+<?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)
+ ->requireCapabilities(
+ array(
+ PhabricatorPolicyCapability::CAN_VIEW,
+ PhabricatorPolicyCapability::CAN_EDIT,
+ ))
+ ->execute();
+
+ $awards = id(new PhabricatorBadgesAwardQuery())
+ ->setViewer($viewer)
+ ->withAwarderPHIDs(array($viewer->getPHID()))
+ ->withRecipientPHIDs(array($recipient_phid))
+ ->execute();
+ $awards = mpull($awards, null, 'getBadgePHID');
+
+ $results = array();
+ foreach ($badges as $badge) {
+ $closed = null;
+
+ $badge_awards = idx($awards, $badge->getPHID(), null);
+ if ($badge_awards) {
+ $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
Details
Attached
Mime Type
text/plain
Expires
Wed, Dec 25, 11:54 PM (38 m, 29 s)
Storage Engine
blob
Storage Format
Encrypted (AES-256-CBC)
Storage Handle
6927947
Default Alt Text
D15665.diff (6 KB)
Attached To
Mode
D15665: First stab at a badges typeahead
Attached
Detach File
Event Timeline
Log In to Comment