@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 192 lines 5.2 kB view raw
1<?php 2 3final class PhabricatorSlowvoteSearchEngine 4 extends PhabricatorApplicationSearchEngine { 5 6 public function getResultTypeDescription() { 7 return pht('Slowvotes'); 8 } 9 10 public function getApplicationClassName() { 11 return PhabricatorSlowvoteApplication::class; 12 } 13 14 public function newQuery() { 15 return new PhabricatorSlowvoteQuery(); 16 } 17 18 protected function buildQueryFromParameters(array $map) { 19 $query = $this->newQuery(); 20 21 if ($map['voted']) { 22 $query->withVotesByViewer(true); 23 } 24 25 if ($map['authorPHIDs']) { 26 $query->withAuthorPHIDs($map['authorPHIDs']); 27 } 28 29 if ($map['statuses']) { 30 $query->withStatuses($map['statuses']); 31 } 32 33 return $query; 34 } 35 36 protected function buildCustomSearchFields() { 37 38 $status_options = SlowvotePollStatus::getAll(); 39 $status_options = mpull($status_options, 'getName'); 40 41 return array( 42 id(new PhabricatorUsersSearchField()) 43 ->setKey('authorPHIDs') 44 ->setAliases(array('authors')) 45 ->setDescription( 46 pht('Search for objects created by specific authors.')) 47 ->setLabel(pht('Authors')), 48 id(new PhabricatorSearchCheckboxesField()) 49 ->setKey('voted') 50 ->setLabel(pht('Voted')) 51 52 // TODO: This should probably become a list of "voterPHIDs", so hide 53 // the field from Conduit to avoid a backward compatibility break when 54 // this changes. 55 56 ->setEnableForConduit(false) 57 ->setOptions(array( 58 'voted' => pht("Show only polls I've voted in."), 59 )), 60 id(new PhabricatorSearchCheckboxesField()) 61 ->setKey('statuses') 62 ->setLabel(pht('Statuses')) 63 ->setOptions($status_options), 64 ); 65 } 66 67 protected function getURI($path) { 68 return '/vote/'.$path; 69 } 70 71 protected function getBuiltinQueryNames() { 72 $names = array( 73 'open' => pht('Open Polls'), 74 'all' => pht('All Polls'), 75 ); 76 77 if ($this->requireViewer()->isLoggedIn()) { 78 $names['authored'] = pht('Authored'); 79 $names['voted'] = pht('Voted In'); 80 } 81 82 return $names; 83 } 84 85 public function buildSavedQueryFromBuiltin($query_key) { 86 $query = $this->newSavedQuery(); 87 $query->setQueryKey($query_key); 88 89 switch ($query_key) { 90 case 'open': 91 return $query->setParameter('statuses', array('open')); 92 case 'all': 93 return $query; 94 case 'authored': 95 return $query->setParameter( 96 'authorPHIDs', 97 array($this->requireViewer()->getPHID())); 98 case 'voted': 99 return $query->setParameter('voted', array('voted')); 100 } 101 102 return parent::buildSavedQueryFromBuiltin($query_key); 103 } 104 105 protected function getRequiredHandlePHIDsForResultList( 106 array $polls, 107 PhabricatorSavedQuery $query) { 108 return mpull($polls, 'getAuthorPHID'); 109 } 110 111 /** 112 * @param array<PhabricatorSlowvotePoll> $polls 113 * @param PhabricatorSavedQuery $query 114 * @param array<PhabricatorObjectHandle> $handles 115 */ 116 protected function renderResultList( 117 array $polls, 118 PhabricatorSavedQuery $query, 119 array $handles) { 120 121 assert_instances_of($polls, PhabricatorSlowvotePoll::class); 122 $viewer = $this->requireViewer(); 123 124 $list = id(new PHUIObjectItemListView()) 125 ->setUser($viewer); 126 127 $phids = mpull($polls, 'getAuthorPHID'); 128 129 foreach ($polls as $poll) { 130 $date_created = phabricator_datetime($poll->getDateCreated(), $viewer); 131 if ($poll->getAuthorPHID()) { 132 $author = $handles[$poll->getAuthorPHID()]->renderLink(); 133 } else { 134 $author = null; 135 } 136 137 $item = id(new PHUIObjectItemView()) 138 ->setUser($viewer) 139 ->setObject($poll) 140 ->setObjectName($poll->getMonogram()) 141 ->setHeader($poll->getQuestion()) 142 ->setHref($poll->getURI()) 143 ->addIcon('none', $date_created); 144 145 if ($poll->isClosed()) { 146 $item->setStatusIcon('fa-ban grey'); 147 $item->setDisabled(true); 148 } else { 149 $item->setStatusIcon('fa-bar-chart'); 150 } 151 152 $description = $poll->getDescription(); 153 if (strlen($description)) { 154 $item->addAttribute(id(new PhutilUTF8StringTruncator()) 155 ->setMaximumGlyphs(120) 156 ->truncateString($poll->getDescription())); 157 } 158 159 if ($author) { 160 $item->addByline(pht('Author: %s', $author)); 161 } 162 163 $list->addItem($item); 164 } 165 166 $result = new PhabricatorApplicationSearchResultView(); 167 $result->setObjectList($list); 168 $result->setNoDataString(pht('No polls found.')); 169 170 return $result; 171 } 172 173 protected function getNewUserBody() { 174 $create_button = id(new PHUIButtonView()) 175 ->setTag('a') 176 ->setText(pht('Create a Poll')) 177 ->setHref('/vote/create/') 178 ->setColor(PHUIButtonView::GREEN); 179 180 $icon = $this->getApplication()->getIcon(); 181 $app_name = $this->getApplication()->getName(); 182 $view = id(new PHUIBigInfoView()) 183 ->setIcon($icon) 184 ->setTitle(pht('Welcome to %s', $app_name)) 185 ->setDescription( 186 pht('Poll other users to help facilitate decision making.')) 187 ->addAction($create_button); 188 189 return $view; 190 } 191 192}