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;
 }
 protected function getTagAttributes()
 {
     require_celerity_resource('phui-badge-view-css');
     Javelin::initBehavior('phabricator-tooltips');
     $classes = array();
     $classes[] = 'phui-badge-mini';
     if ($this->quality) {
         $quality_color = PhabricatorBadgesQuality::getQualityColor($this->quality);
         $classes[] = 'phui-badge-mini-' . $quality_color;
     }
     return array('class' => implode(' ', $classes), 'sigil' => 'has-tooltip', 'href' => $this->href, 'meta' => array('tip' => $this->header, 'align' => $this->tipDirection, 'size' => 300));
 }
 protected function renderResultList(array $badges, PhabricatorSavedQuery $query, array $handles)
 {
     assert_instances_of($badges, 'PhabricatorBadgesBadge');
     $viewer = $this->requireViewer();
     $list = id(new PHUIObjectItemListView());
     foreach ($badges as $badge) {
         $quality_name = PhabricatorBadgesQuality::getQualityName($badge->getQuality());
         $mini_badge = id(new PHUIBadgeMiniView())->setHeader($badge->getName())->setIcon($badge->getIcon())->setQuality($badge->getQuality());
         $item = id(new PHUIObjectItemView())->setHeader($badge->getName())->setBadge($mini_badge)->setHref('/badges/view/' . $badge->getID() . '/')->addAttribute($quality_name)->addAttribute($badge->getFlavor());
         if ($badge->isArchived()) {
             $item->setDisabled(true);
             $item->addIcon('fa-ban', pht('Archived'));
         }
         $list->addItem($item);
     }
     $result = new PhabricatorApplicationSearchResultView();
     $result->setObjectList($list);
     $result->setNoDataString(pht('No badges found.'));
     return $result;
 }
 protected function buildCustomEditFields($object)
 {
     return array(id(new PhabricatorTextEditField())->setKey('name')->setLabel(pht('Name'))->setDescription(pht('Badge name.'))->setConduitTypeDescription(pht('New badge name.'))->setTransactionType(PhabricatorBadgesTransaction::TYPE_NAME)->setValue($object->getName()), id(new PhabricatorTextEditField())->setKey('flavor')->setLabel(pht('Flavor text'))->setDescription(pht('Short description of the badge.'))->setConduitTypeDescription(pht('New badge flavor.'))->setValue($object->getFlavor())->setTransactionType(PhabricatorBadgesTransaction::TYPE_FLAVOR), id(new PhabricatorIconSetEditField())->setKey('icon')->setLabel(pht('Icon'))->setIconSet(new PhabricatorBadgesIconSet())->setTransactionType(PhabricatorBadgesTransaction::TYPE_ICON)->setConduitDescription(pht('Change the badge icon.'))->setConduitTypeDescription(pht('New badge icon.'))->setValue($object->getIcon()), id(new PhabricatorSelectEditField())->setKey('quality')->setLabel(pht('Quality'))->setDescription(pht('Color and rarity of the badge.'))->setConduitTypeDescription(pht('New badge quality.'))->setValue($object->getQuality())->setTransactionType(PhabricatorBadgesTransaction::TYPE_QUALITY)->setOptions(PhabricatorBadgesQuality::getDropdownQualityMap()), id(new PhabricatorRemarkupEditField())->setKey('description')->setLabel(pht('Description'))->setDescription(pht('Badge long description.'))->setConduitTypeDescription(pht('New badge description.'))->setTransactionType(PhabricatorBadgesTransaction::TYPE_DESCRIPTION)->setValue($object->getDescription()));
 }
Example #5
0
 private function getQualityName()
 {
     return PhabricatorBadgesQuality::getQualityName($this->quality);
 }
 public function getTitle()
 {
     $author_phid = $this->getAuthorPHID();
     $object_phid = $this->getObjectPHID();
     $old = $this->getOldValue();
     $new = $this->getNewValue();
     $type = $this->getTransactionType();
     switch ($type) {
         case self::TYPE_NAME:
             if ($old === null) {
                 return pht('%s created this badge.', $this->renderHandleLink($author_phid));
             } else {
                 return pht('%s renamed this badge from "%s" to "%s".', $this->renderHandleLink($author_phid), $old, $new);
             }
             break;
         case self::TYPE_FLAVOR:
             if ($old === null) {
                 return pht('%s set the flavor text for this badge.', $this->renderHandleLink($author_phid));
             } else {
                 return pht('%s updated the flavor text for this badge.', $this->renderHandleLink($author_phid));
             }
             break;
         case self::TYPE_DESCRIPTION:
             if ($old === null) {
                 return pht('%s set the description for this badge.', $this->renderHandleLink($author_phid));
             } else {
                 return pht('%s updated the description for this badge.', $this->renderHandleLink($author_phid));
             }
             break;
         case self::TYPE_STATUS:
             switch ($new) {
                 case PhabricatorBadgesBadge::STATUS_ACTIVE:
                     return pht('%s activated this badge.', $this->renderHandleLink($author_phid));
                 case PhabricatorBadgesBadge::STATUS_ARCHIVED:
                     return pht('%s archived this badge.', $this->renderHandleLink($author_phid));
             }
             break;
         case self::TYPE_ICON:
             if ($old === null) {
                 return pht('%s set the icon for this badge as "%s".', $this->renderHandleLink($author_phid), $new);
             } else {
                 $set = new PhabricatorBadgesIconSet();
                 $icon_old = $set->getIconLabel($old);
                 $icon_new = $set->getIconLabel($new);
                 return pht('%s updated the icon for this badge from "%s" to "%s".', $this->renderHandleLink($author_phid), $icon_old, $icon_new);
             }
             break;
         case self::TYPE_QUALITY:
             if ($old === null) {
                 return pht('%s set the quality for this badge as "%s".', $this->renderHandleLink($author_phid), $new);
             } else {
                 $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), $qual_old, $qual_new);
             }
             break;
         case self::TYPE_AWARD:
             if (!is_array($new)) {
                 $new = array();
             }
             $handles = $this->renderHandleList($new);
             return pht('%s awarded this badge to %s recipient(s): %s.', $this->renderHandleLink($author_phid), new PhutilNumber(count($new)), $handles);
         case self::TYPE_REVOKE:
             if (!is_array($new)) {
                 $new = array();
             }
             $handles = $this->renderHandleList($new);
             return pht('%s revoked this badge from %s recipient(s): %s.', $this->renderHandleLink($author_phid), new PhutilNumber(count($new)), $handles);
     }
     return parent::getTitle();
 }