[ Index ] |
PHP Cross Reference of Phabricator |
[Summary view] [Print] [Text view]
1 <?php 2 3 final class LegalpadDocumentSignatureSearchEngine 4 extends PhabricatorApplicationSearchEngine { 5 6 private $document; 7 8 public function getResultTypeDescription() { 9 return pht('Legalpad Signatures'); 10 } 11 12 public function getApplicationClassName() { 13 return 'PhabricatorLegalpadApplication'; 14 } 15 16 public function setDocument(LegalpadDocument $document) { 17 $this->document = $document; 18 return $this; 19 } 20 21 public function buildSavedQueryFromRequest(AphrontRequest $request) { 22 $saved = new PhabricatorSavedQuery(); 23 24 $saved->setParameter( 25 'signerPHIDs', 26 $this->readUsersFromRequest($request, 'signers')); 27 28 $saved->setParameter( 29 'documentPHIDs', 30 $this->readPHIDsFromRequest( 31 $request, 32 'documents', 33 array( 34 PhabricatorLegalpadDocumentPHIDType::TYPECONST, 35 ))); 36 37 $saved->setParameter('nameContains', $request->getStr('nameContains')); 38 $saved->setParameter('emailContains', $request->getStr('emailContains')); 39 40 return $saved; 41 } 42 43 public function buildQueryFromSavedQuery(PhabricatorSavedQuery $saved) { 44 $query = id(new LegalpadDocumentSignatureQuery()); 45 46 $signer_phids = $saved->getParameter('signerPHIDs', array()); 47 if ($signer_phids) { 48 $query->withSignerPHIDs($signer_phids); 49 } 50 51 if ($this->document) { 52 $query->withDocumentPHIDs(array($this->document->getPHID())); 53 } else { 54 $document_phids = $saved->getParameter('documentPHIDs', array()); 55 if ($document_phids) { 56 $query->withDocumentPHIDs($document_phids); 57 } 58 } 59 60 $name_contains = $saved->getParameter('nameContains'); 61 if (strlen($name_contains)) { 62 $query->withNameContains($name_contains); 63 } 64 65 $email_contains = $saved->getParameter('emailContains'); 66 if (strlen($email_contains)) { 67 $query->withEmailContains($email_contains); 68 } 69 70 return $query; 71 } 72 73 public function buildSearchForm( 74 AphrontFormView $form, 75 PhabricatorSavedQuery $saved_query) { 76 77 $document_phids = $saved_query->getParameter('documentPHIDs', array()); 78 $signer_phids = $saved_query->getParameter('signerPHIDs', array()); 79 80 $phids = array_merge($document_phids, $signer_phids); 81 $handles = id(new PhabricatorHandleQuery()) 82 ->setViewer($this->requireViewer()) 83 ->withPHIDs($phids) 84 ->execute(); 85 86 if (!$this->document) { 87 $form 88 ->appendChild( 89 id(new AphrontFormTokenizerControl()) 90 ->setDatasource(new LegalpadDocumentDatasource()) 91 ->setName('documents') 92 ->setLabel(pht('Documents')) 93 ->setValue(array_select_keys($handles, $document_phids))); 94 } 95 96 $name_contains = $saved_query->getParameter('nameContains', ''); 97 $email_contains = $saved_query->getParameter('emailContains', ''); 98 99 $form 100 ->appendChild( 101 id(new AphrontFormTokenizerControl()) 102 ->setDatasource(new PhabricatorPeopleDatasource()) 103 ->setName('signers') 104 ->setLabel(pht('Signers')) 105 ->setValue(array_select_keys($handles, $signer_phids))) 106 ->appendChild( 107 id(new AphrontFormTextControl()) 108 ->setLabel(pht('Name Contains')) 109 ->setName('nameContains') 110 ->setValue($name_contains)) 111 ->appendChild( 112 id(new AphrontFormTextControl()) 113 ->setLabel(pht('Email Contains')) 114 ->setName('emailContains') 115 ->setValue($email_contains)); 116 } 117 118 protected function getURI($path) { 119 if ($this->document) { 120 return '/legalpad/signatures/'.$this->document->getID().'/'.$path; 121 } else { 122 return '/legalpad/signatures/'.$path; 123 } 124 } 125 126 public function getBuiltinQueryNames() { 127 $names = array( 128 'all' => pht('All Signatures'), 129 ); 130 131 return $names; 132 } 133 134 public function buildSavedQueryFromBuiltin($query_key) { 135 136 $query = $this->newSavedQuery(); 137 $query->setQueryKey($query_key); 138 139 switch ($query_key) { 140 case 'all': 141 return $query; 142 } 143 144 return parent::buildSavedQueryFromBuiltin($query_key); 145 } 146 147 protected function getRequiredHandlePHIDsForResultList( 148 array $signatures, 149 PhabricatorSavedQuery $query) { 150 151 return array_merge( 152 mpull($signatures, 'getSignerPHID'), 153 mpull($signatures, 'getDocumentPHID')); 154 } 155 156 protected function renderResultList( 157 array $signatures, 158 PhabricatorSavedQuery $query, 159 array $handles) { 160 assert_instances_of($signatures, 'LegalpadDocumentSignature'); 161 162 $viewer = $this->requireViewer(); 163 164 Javelin::initBehavior('phabricator-tooltips'); 165 166 $sig_good = $this->renderIcon( 167 'fa-check', 168 null, 169 pht('Verified, Current')); 170 171 $sig_corp = $this->renderIcon( 172 'fa-building-o', 173 null, 174 pht('Verified, Corporate')); 175 176 $sig_old = $this->renderIcon( 177 'fa-clock-o', 178 'orange', 179 pht('Signed Older Version')); 180 181 $sig_unverified = $this->renderIcon( 182 'fa-envelope', 183 'red', 184 pht('Unverified Email')); 185 186 $sig_exemption = $this->renderIcon( 187 'fa-asterisk', 188 'indigo', 189 pht('Exemption')); 190 191 id(new PHUIIconView()) 192 ->setIconFont('fa-envelope', 'red') 193 ->addSigil('has-tooltip') 194 ->setMetadata(array('tip' => pht('Unverified Email'))); 195 196 $type_corporate = LegalpadDocument::SIGNATURE_TYPE_CORPORATION; 197 198 $rows = array(); 199 foreach ($signatures as $signature) { 200 $name = $signature->getSignerName(); 201 $email = $signature->getSignerEmail(); 202 203 $document = $signature->getDocument(); 204 205 if ($signature->getIsExemption()) { 206 $sig_icon = $sig_exemption; 207 } else if (!$signature->isVerified()) { 208 $sig_icon = $sig_unverified; 209 } else if ($signature->getDocumentVersion() != $document->getVersions()) { 210 $sig_icon = $sig_old; 211 } else if ($signature->getSignatureType() == $type_corporate) { 212 $sig_icon = $sig_corp; 213 } else { 214 $sig_icon = $sig_good; 215 } 216 217 $signature_href = $this->getApplicationURI( 218 'signature/'.$signature->getID().'/'); 219 220 $sig_icon = javelin_tag( 221 'a', 222 array( 223 'href' => $signature_href, 224 'sigil' => 'workflow', 225 ), 226 $sig_icon); 227 228 $signer_phid = $signature->getSignerPHID(); 229 230 $rows[] = array( 231 $sig_icon, 232 $handles[$document->getPHID()]->renderLink(), 233 $signer_phid 234 ? $handles[$signer_phid]->renderLink() 235 : null, 236 $name, 237 phutil_tag( 238 'a', 239 array( 240 'href' => 'mailto:'.$email, 241 ), 242 $email), 243 phabricator_datetime($signature->getDateCreated(), $viewer), 244 ); 245 } 246 247 $table = id(new AphrontTableView($rows)) 248 ->setNoDataString(pht('No signatures match the query.')) 249 ->setHeaders( 250 array( 251 '', 252 pht('Document'), 253 pht('Account'), 254 pht('Name'), 255 pht('Email'), 256 pht('Signed'), 257 )) 258 ->setColumnVisibility( 259 array( 260 true, 261 262 // Only show the "Document" column if we aren't scoped to a 263 // particular document. 264 !$this->document, 265 )) 266 ->setColumnClasses( 267 array( 268 '', 269 '', 270 '', 271 '', 272 'wide', 273 'right', 274 )); 275 276 $header = id(new PHUIHeaderView()) 277 ->setHeader(pht('Signatures')); 278 279 if ($this->document) { 280 $document_id = $this->document->getID(); 281 282 $header->addActionLink( 283 id(new PHUIButtonView()) 284 ->setText(pht('Add Signature Exemption')) 285 ->setTag('a') 286 ->setHref($this->getApplicationURI('addsignature/'.$document_id.'/')) 287 ->setWorkflow(true) 288 ->setIcon(id(new PHUIIconView())->setIconFont('fa-pencil'))); 289 } 290 291 $box = id(new PHUIObjectBoxView()) 292 ->setHeader($header) 293 ->appendChild($table); 294 295 if (!$this->document) { 296 $policy_notice = id(new AphrontErrorView()) 297 ->setSeverity(AphrontErrorView::SEVERITY_NOTICE) 298 ->setErrors( 299 array( 300 pht( 301 'NOTE: You can only see your own signatures and signatures on '. 302 'documents you have permission to edit.'), 303 )); 304 $box->setErrorView($policy_notice); 305 } 306 307 return $box; 308 } 309 310 private function renderIcon($icon, $color, $title) { 311 Javelin::initBehavior('phabricator-tooltips'); 312 313 return array( 314 id(new PHUIIconView()) 315 ->setIconFont($icon, $color) 316 ->addSigil('has-tooltip') 317 ->setMetadata(array('tip' => $title)), 318 javelin_tag( 319 'span', 320 array( 321 'aural' => true, 322 ), 323 $title), 324 ); 325 } 326 327 }
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 |