@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 recaptime-dev/main 173 lines 4.6 kB view raw
1<?php 2 3final class PhabricatorCountdownSearchEngine 4 extends PhabricatorApplicationSearchEngine { 5 6 public function getResultTypeDescription() { 7 return pht('Countdowns'); 8 } 9 10 public function getApplicationClassName() { 11 return PhabricatorCountdownApplication::class; 12 } 13 14 public function newQuery() { 15 return new PhabricatorCountdownQuery(); 16 } 17 18 protected function buildQueryFromParameters(array $map) { 19 $query = $this->newQuery(); 20 21 if ($map['authorPHIDs']) { 22 $query->withAuthorPHIDs($map['authorPHIDs']); 23 } 24 25 if ($map['upcoming'] && $map['upcoming'][0] == 'upcoming') { 26 $query->withUpcoming(); 27 } 28 29 return $query; 30 } 31 32 protected function buildCustomSearchFields() { 33 return array( 34 id(new PhabricatorUsersSearchField()) 35 ->setLabel(pht('Authors')) 36 ->setKey('authorPHIDs') 37 ->setDescription( 38 pht('Search for objects created by specific authors.')) 39 ->setAliases(array('author', 'authors')), 40 id(new PhabricatorSearchCheckboxesField()) 41 ->setKey('upcoming') 42 ->setOptions( 43 array( 44 'upcoming' => pht('Show only upcoming countdowns.'), 45 )), 46 ); 47 } 48 49 protected function getURI($path) { 50 return '/countdown/'.$path; 51 } 52 53 protected function getBuiltinQueryNames() { 54 $names = array( 55 'upcoming' => pht('Upcoming'), 56 'all' => pht('All'), 57 ); 58 59 if ($this->requireViewer()->getPHID()) { 60 $names['authored'] = pht('Authored'); 61 } 62 63 return $names; 64 } 65 66 public function buildSavedQueryFromBuiltin($query_key) { 67 $query = $this->newSavedQuery(); 68 $query->setQueryKey($query_key); 69 70 switch ($query_key) { 71 case 'all': 72 return $query; 73 case 'authored': 74 return $query->setParameter( 75 'authorPHIDs', 76 array($this->requireViewer()->getPHID())); 77 case 'upcoming': 78 return $query->setParameter('upcoming', array('upcoming')); 79 } 80 81 return parent::buildSavedQueryFromBuiltin($query_key); 82 } 83 84 protected function getRequiredHandlePHIDsForResultList( 85 array $countdowns, 86 PhabricatorSavedQuery $query) { 87 88 return mpull($countdowns, 'getAuthorPHID'); 89 } 90 91 /** 92 * @param array<PhabricatorCountdown> $countdowns 93 * @param PhabricatorSavedQuery $query 94 * @param array<PhabricatorObjectHandle> $handles 95 */ 96 protected function renderResultList( 97 array $countdowns, 98 PhabricatorSavedQuery $query, 99 array $handles) { 100 101 assert_instances_of($countdowns, PhabricatorCountdown::class); 102 103 $viewer = $this->requireViewer(); 104 105 $list = new PHUIObjectItemListView(); 106 $list->setUser($viewer); 107 foreach ($countdowns as $countdown) { 108 $id = $countdown->getID(); 109 $ended = false; 110 $epoch = $countdown->getEpoch(); 111 if ($epoch <= PhabricatorTime::getNow()) { 112 $ended = true; 113 } 114 115 $item = id(new PHUIObjectItemView()) 116 ->setUser($viewer) 117 ->setObject($countdown) 118 ->setObjectName($countdown->getMonogram()) 119 ->setHeader($countdown->getTitle()) 120 ->setHref($countdown->getURI()) 121 ->addByline( 122 pht( 123 'Created by %s', 124 $handles[$countdown->getAuthorPHID()]->renderLink())); 125 126 if ($ended) { 127 $item->addAttribute( 128 pht('Launched on %s', phabricator_datetime($epoch, $viewer))); 129 $item->setDisabled(true); 130 } else { 131 $time_left = ($epoch - PhabricatorTime::getNow()); 132 $num = round($time_left / (60 * 60 * 24)); 133 $noun = pht('Days'); 134 if ($num < 1) { 135 $num = round($time_left / (60 * 60), 1); 136 $noun = pht('Hours'); 137 } 138 $item->setCountdown($num, $noun); 139 $item->addAttribute( 140 phabricator_datetime($epoch, $viewer)); 141 } 142 143 $list->addItem($item); 144 } 145 146 $result = new PhabricatorApplicationSearchResultView(); 147 $result->setObjectList($list); 148 $result->setNoDataString(pht('No countdowns found.')); 149 150 return $result; 151 } 152 153 protected function getNewUserBody() { 154 $create_button = id(new PHUIButtonView()) 155 ->setTag('a') 156 ->setText(pht('Create a Countdown')) 157 ->setHref('/countdown/edit/') 158 ->setColor(PHUIButtonView::GREEN); 159 160 $icon = $this->getApplication()->getIcon(); 161 $app_name = $this->getApplication()->getName(); 162 $view = id(new PHUIBigInfoView()) 163 ->setIcon($icon) 164 ->setTitle(pht('Welcome to %s', $app_name)) 165 ->setDescription( 166 pht('Keep track of upcoming launch dates with '. 167 'embeddable counters.')) 168 ->addAction($create_button); 169 170 return $view; 171 } 172 173}