[ Index ] |
PHP Cross Reference of Phabricator |
[Summary view] [Print] [Text view]
1 <?php 2 3 final class PhabricatorSlowvoteSearchEngine 4 extends PhabricatorApplicationSearchEngine { 5 6 public function getResultTypeDescription() { 7 return pht('Slowvotes'); 8 } 9 10 public function buildSavedQueryFromRequest(AphrontRequest $request) { 11 $saved = new PhabricatorSavedQuery(); 12 $saved->setParameter( 13 'authorPHIDs', 14 $this->readUsersFromRequest($request, 'authors')); 15 16 $saved->setParameter('voted', $request->getBool('voted')); 17 $saved->setParameter('statuses', $request->getArr('statuses')); 18 19 return $saved; 20 } 21 22 public function buildQueryFromSavedQuery(PhabricatorSavedQuery $saved) { 23 $query = id(new PhabricatorSlowvoteQuery()) 24 ->withAuthorPHIDs($saved->getParameter('authorPHIDs', array())); 25 26 if ($saved->getParameter('voted')) { 27 $query->withVotesByViewer(true); 28 } 29 30 $statuses = $saved->getParameter('statuses', array()); 31 if (count($statuses) == 1) { 32 $status = head($statuses); 33 if ($status == 'open') { 34 $query->withIsClosed(false); 35 } else { 36 $query->withIsClosed(true); 37 } 38 } 39 40 return $query; 41 } 42 43 public function buildSearchForm( 44 AphrontFormView $form, 45 PhabricatorSavedQuery $saved_query) { 46 $phids = $saved_query->getParameter('authorPHIDs', array()); 47 $author_handles = id(new PhabricatorHandleQuery()) 48 ->setViewer($this->requireViewer()) 49 ->withPHIDs($phids) 50 ->execute(); 51 52 $voted = $saved_query->getParameter('voted', false); 53 $statuses = $saved_query->getParameter('statuses', array()); 54 55 $form 56 ->appendChild( 57 id(new AphrontFormTokenizerControl()) 58 ->setDatasource(new PhabricatorPeopleDatasource()) 59 ->setName('authors') 60 ->setLabel(pht('Authors')) 61 ->setValue($author_handles)) 62 ->appendChild( 63 id(new AphrontFormCheckboxControl()) 64 ->addCheckbox( 65 'voted', 66 1, 67 pht("Show only polls I've voted in."), 68 $voted)) 69 ->appendChild( 70 id(new AphrontFormCheckboxControl()) 71 ->setLabel(pht('Status')) 72 ->addCheckbox( 73 'statuses[]', 74 'open', 75 pht('Open'), 76 in_array('open', $statuses)) 77 ->addCheckbox( 78 'statuses[]', 79 'closed', 80 pht('Closed'), 81 in_array('closed', $statuses))); 82 } 83 84 protected function getURI($path) { 85 return '/vote/'.$path; 86 } 87 88 public function getBuiltinQueryNames() { 89 $names = array( 90 'open' => pht('Open Polls'), 91 'all' => pht('All Polls'), 92 ); 93 94 if ($this->requireViewer()->isLoggedIn()) { 95 $names['authored'] = pht('Authored'); 96 $names['voted'] = pht('Voted In'); 97 } 98 99 return $names; 100 } 101 102 public function buildSavedQueryFromBuiltin($query_key) { 103 $query = $this->newSavedQuery(); 104 $query->setQueryKey($query_key); 105 106 switch ($query_key) { 107 case 'open': 108 return $query->setParameter('statuses', array('open')); 109 case 'all': 110 return $query; 111 case 'authored': 112 return $query->setParameter( 113 'authorPHIDs', 114 array($this->requireViewer()->getPHID())); 115 case 'voted': 116 return $query->setParameter('voted', true); 117 } 118 119 return parent::buildSavedQueryFromBuiltin($query_key); 120 } 121 122 public function getRequiredHandlePHIDsForResultList( 123 array $polls, 124 PhabricatorSavedQuery $query) { 125 return mpull($polls, 'getAuthorPHID'); 126 } 127 128 protected function renderResultList( 129 array $polls, 130 PhabricatorSavedQuery $query, 131 array $handles) { 132 133 assert_instances_of($polls, 'PhabricatorSlowvotePoll'); 134 $viewer = $this->requireViewer(); 135 136 $list = id(new PHUIObjectItemListView()) 137 ->setUser($viewer); 138 139 $phids = mpull($polls, 'getAuthorPHID'); 140 141 foreach ($polls as $poll) { 142 $date_created = phabricator_datetime($poll->getDateCreated(), $viewer); 143 if ($poll->getAuthorPHID()) { 144 $author = $handles[$poll->getAuthorPHID()]->renderLink(); 145 } else { 146 $author = null; 147 } 148 149 $item = id(new PHUIObjectItemView()) 150 ->setObjectName('V'.$poll->getID()) 151 ->setHeader($poll->getQuestion()) 152 ->setHref('/V'.$poll->getID()) 153 ->setDisabled($poll->getIsClosed()) 154 ->addIcon('none', $date_created); 155 156 $description = $poll->getDescription(); 157 if (strlen($description)) { 158 $item->addAttribute(id(new PhutilUTF8StringTruncator()) 159 ->setMaximumGlyphs(120) 160 ->truncateString($poll->getDescription())); 161 } 162 163 if ($author) { 164 $item->addByline(pht('Author: %s', $author)); 165 } 166 167 $list->addItem($item); 168 } 169 170 return $list; 171 } 172 173 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Sun Nov 30 09:20:46 2014 | Cross-referenced by PHPXref 0.7.1 |