[ Index ] |
PHP Cross Reference of Phabricator |
[Summary view] [Print] [Text view]
1 <?php 2 3 final class FundInitiativeSearchEngine 4 extends PhabricatorApplicationSearchEngine { 5 6 public function getResultTypeDescription() { 7 return pht('Fund Initiatives'); 8 } 9 10 public function getApplicationClassName() { 11 return 'PhabricatorFundApplication'; 12 } 13 14 public function buildSavedQueryFromRequest(AphrontRequest $request) { 15 $saved = new PhabricatorSavedQuery(); 16 17 $saved->setParameter( 18 'ownerPHIDs', 19 $this->readUsersFromRequest($request, 'owners')); 20 21 $saved->setParameter( 22 'statuses', 23 $this->readListFromRequest($request, 'statuses')); 24 25 return $saved; 26 } 27 28 public function buildQueryFromSavedQuery(PhabricatorSavedQuery $saved) { 29 $query = id(new FundInitiativeQuery()) 30 ->needProjectPHIDs(true); 31 32 $owner_phids = $saved->getParameter('ownerPHIDs'); 33 if ($owner_phids) { 34 $query->withOwnerPHIDs($owner_phids); 35 } 36 37 $statuses = $saved->getParameter('statuses'); 38 if ($statuses) { 39 $query->withStatuses($statuses); 40 } 41 42 return $query; 43 } 44 45 public function buildSearchForm( 46 AphrontFormView $form, 47 PhabricatorSavedQuery $saved) { 48 49 $statuses = $saved->getParameter('statuses', array()); 50 $statuses = array_fuse($statuses); 51 52 $owner_phids = $saved->getParameter('ownerPHIDs', array()); 53 54 $all_phids = array_mergev( 55 array( 56 $owner_phids, 57 )); 58 59 $handles = id(new PhabricatorHandleQuery()) 60 ->setViewer($this->requireViewer()) 61 ->withPHIDs($all_phids) 62 ->execute(); 63 64 $status_map = FundInitiative::getStatusNameMap(); 65 $status_control = id(new AphrontFormCheckboxControl()) 66 ->setLabel(pht('Statuses')); 67 foreach ($status_map as $status => $name) { 68 $status_control->addCheckbox( 69 'statuses[]', 70 $status, 71 $name, 72 isset($statuses[$status])); 73 } 74 75 $form 76 ->appendChild( 77 id(new AphrontFormTokenizerControl()) 78 ->setLabel(pht('Owners')) 79 ->setName('owners') 80 ->setDatasource(new PhabricatorPeopleDatasource()) 81 ->setValue(array_select_keys($handles, $owner_phids))) 82 ->appendChild($status_control); 83 } 84 85 protected function getURI($path) { 86 return '/fund/'.$path; 87 } 88 89 public function getBuiltinQueryNames() { 90 $names = array(); 91 92 $names['open'] = pht('Open Initiatives'); 93 if ($this->requireViewer()->isLoggedIn()) { 94 $names['owned'] = pht('Owned Initiatives'); 95 } 96 $names['all'] = pht('All Initiatives'); 97 98 return $names; 99 } 100 101 public function buildSavedQueryFromBuiltin($query_key) { 102 $query = $this->newSavedQuery(); 103 $query->setQueryKey($query_key); 104 105 switch ($query_key) { 106 case 'all': 107 return $query; 108 case 'owned': 109 return $query->setParameter( 110 'ownerPHIDs', 111 array( 112 $this->requireViewer()->getPHID(), 113 )); 114 case 'open': 115 return $query->setParameter( 116 'statuses', 117 array( 118 FundInitiative::STATUS_OPEN, 119 )); 120 } 121 122 return parent::buildSavedQueryFromBuiltin($query_key); 123 } 124 125 protected function getRequiredHandlePHIDsForResultList( 126 array $initiatives, 127 PhabricatorSavedQuery $query) { 128 129 $phids = array(); 130 foreach ($initiatives as $initiative) { 131 $phids[] = $initiative->getOwnerPHID(); 132 foreach ($initiative->getProjectPHIDs() as $project_phid) { 133 $phids[] = $project_phid; 134 } 135 } 136 137 return $phids; 138 } 139 140 protected function renderResultList( 141 array $initiatives, 142 PhabricatorSavedQuery $query, 143 array $handles) { 144 assert_instances_of($initiatives, 'FundInitiative'); 145 146 $viewer = $this->requireViewer(); 147 148 $list = id(new PHUIObjectItemListView()); 149 foreach ($initiatives as $initiative) { 150 $owner_handle = $handles[$initiative->getOwnerPHID()]; 151 152 $item = id(new PHUIObjectItemView()) 153 ->setObjectName($initiative->getMonogram()) 154 ->setHeader($initiative->getName()) 155 ->setHref('/'.$initiative->getMonogram()) 156 ->addByline(pht('Owner: %s', $owner_handle->renderLink())); 157 158 if ($initiative->isClosed()) { 159 $item->setDisabled(true); 160 } 161 162 $project_handles = array_select_keys( 163 $handles, 164 $initiative->getProjectPHIDs()); 165 if ($project_handles) { 166 $item->addAttribute( 167 id(new PHUIHandleTagListView()) 168 ->setLimit(4) 169 ->setSlim(true) 170 ->setHandles($project_handles)); 171 } 172 173 $list->addItem($item); 174 } 175 176 177 return $list; 178 } 179 180 }
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 |