@recaptime-dev's working patches + fork for Phorge, a community fork of Phabricator. (Upstream dev and stable branches are at upstream/main and upstream/stable respectively.) hq.recaptime.dev/wiki/Phorge
phorge phabricator
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

at upstream/main 164 lines 4.3 kB view raw
1<?php 2 3final class PhabricatorBadgesSearchEngine 4 extends PhabricatorApplicationSearchEngine { 5 6 public function getResultTypeDescription() { 7 return pht('Badges'); 8 } 9 10 public function getApplicationClassName() { 11 return PhabricatorBadgesApplication::class; 12 } 13 14 public function newQuery() { 15 return new PhabricatorBadgesQuery(); 16 } 17 18 protected function buildCustomSearchFields() { 19 return array( 20 id(new PhabricatorSearchTextField()) 21 ->setLabel(pht('Name Contains')) 22 ->setKey('name') 23 ->setDescription(pht('Search for badges by name substring.')), 24 id(new PhabricatorSearchCheckboxesField()) 25 ->setKey('qualities') 26 ->setLabel(pht('Quality')) 27 ->setEnableForConduit(false) 28 ->setOptions(PhabricatorBadgesQuality::getDropdownQualityMap()), 29 id(new PhabricatorSearchCheckboxesField()) 30 ->setKey('statuses') 31 ->setLabel(pht('Status')) 32 ->setDescription( 33 pht('Search for active or archived badges.')) 34 ->setOptions( 35 id(new PhabricatorBadgesBadge()) 36 ->getStatusNameMap()), 37 ); 38 } 39 40 protected function buildQueryFromParameters(array $map) { 41 $query = $this->newQuery(); 42 43 if ($map['statuses']) { 44 $query->withStatuses($map['statuses']); 45 } 46 47 if ($map['qualities']) { 48 $query->withQualities($map['qualities']); 49 } 50 51 if ($map['name'] !== null) { 52 $query->withNameNgrams($map['name']); 53 } 54 55 return $query; 56 } 57 58 protected function getURI($path) { 59 return '/badges/'.$path; 60 } 61 62 protected function getBuiltinQueryNames() { 63 $names = array(); 64 65 $names['open'] = pht('Active Badges'); 66 $names['all'] = pht('All Badges'); 67 68 return $names; 69 } 70 71 public function buildSavedQueryFromBuiltin($query_key) { 72 $query = $this->newSavedQuery(); 73 $query->setQueryKey($query_key); 74 75 switch ($query_key) { 76 case 'all': 77 return $query; 78 case 'open': 79 return $query->setParameter( 80 'statuses', 81 array( 82 PhabricatorBadgesBadge::STATUS_ACTIVE, 83 )); 84 } 85 86 return parent::buildSavedQueryFromBuiltin($query_key); 87 } 88 89 protected function getRequiredHandlePHIDsForResultList( 90 array $badges, 91 PhabricatorSavedQuery $query) { 92 93 $phids = array(); 94 95 return $phids; 96 } 97 98 /** 99 * @param array<PhabricatorBadgesBadge> $badges 100 * @param PhabricatorSavedQuery $query 101 * @param array<PhabricatorObjectHandle> $handles 102 */ 103 protected function renderResultList( 104 array $badges, 105 PhabricatorSavedQuery $query, 106 array $handles) { 107 assert_instances_of($badges, PhabricatorBadgesBadge::class); 108 109 $viewer = $this->requireViewer(); 110 111 $list = new PHUIObjectItemListView(); 112 foreach ($badges as $badge) { 113 $quality_name = PhabricatorBadgesQuality::getQualityName( 114 $badge->getQuality()); 115 116 $mini_badge = id(new PHUIBadgeMiniView()) 117 ->setHeader($badge->getName()) 118 ->setIcon($badge->getIcon()) 119 ->setQuality($badge->getQuality()); 120 121 $item = id(new PHUIObjectItemView()) 122 ->setHeader($badge->getName()) 123 ->setBadge($mini_badge) 124 ->setHref('/badges/view/'.$badge->getID().'/') 125 ->addAttribute($quality_name) 126 ->addAttribute($badge->getFlavor()); 127 128 if ($badge->isArchived()) { 129 $item->setDisabled(true); 130 $item->addIcon('fa-ban', pht('Archived')); 131 } 132 133 $list->addItem($item); 134 } 135 136 $result = new PhabricatorApplicationSearchResultView(); 137 $result->setObjectList($list); 138 $result->setNoDataString(pht('No badges found.')); 139 140 return $result; 141 142 } 143 144 protected function getNewUserBody() { 145 $create_button = id(new PHUIButtonView()) 146 ->setTag('a') 147 ->setText(pht('Create a Badge')) 148 ->setHref('/badges/create/') 149 ->setColor(PHUIButtonView::GREEN); 150 151 $icon = $this->getApplication()->getIcon(); 152 $app_name = $this->getApplication()->getName(); 153 $view = id(new PHUIBigInfoView()) 154 ->setIcon($icon) 155 ->setTitle(pht('Welcome to %s', $app_name)) 156 ->setDescription( 157 pht('Badges let you award and distinguish special users '. 158 'throughout your install.')) 159 ->addAction($create_button); 160 161 return $view; 162 } 163 164}