Path: blob/master/src/applications/legalpad/query/LegalpadDocumentSignatureQuery.php
13450 views
<?php12final class LegalpadDocumentSignatureQuery3extends PhabricatorCursorPagedPolicyAwareQuery {45private $ids;6private $documentPHIDs;7private $signerPHIDs;8private $documentVersions;9private $secretKeys;10private $nameContains;11private $emailContains;1213public function withIDs(array $ids) {14$this->ids = $ids;15return $this;16}1718public function withDocumentPHIDs(array $phids) {19$this->documentPHIDs = $phids;20return $this;21}2223public function withSignerPHIDs(array $phids) {24$this->signerPHIDs = $phids;25return $this;26}2728public function withDocumentVersions(array $versions) {29$this->documentVersions = $versions;30return $this;31}3233public function withSecretKeys(array $keys) {34$this->secretKeys = $keys;35return $this;36}3738public function withNameContains($text) {39$this->nameContains = $text;40return $this;41}4243public function withEmailContains($text) {44$this->emailContains = $text;45return $this;46}4748protected function loadPage() {49$table = new LegalpadDocumentSignature();50$conn_r = $table->establishConnection('r');5152$data = queryfx_all(53$conn_r,54'SELECT * FROM %T %Q %Q %Q',55$table->getTableName(),56$this->buildWhereClause($conn_r),57$this->buildOrderClause($conn_r),58$this->buildLimitClause($conn_r));5960$signatures = $table->loadAllFromArray($data);6162return $signatures;63}6465protected function willFilterPage(array $signatures) {66$document_phids = mpull($signatures, 'getDocumentPHID');6768$documents = id(new LegalpadDocumentQuery())69->setParentQuery($this)70->setViewer($this->getViewer())71->withPHIDs($document_phids)72->execute();73$documents = mpull($documents, null, 'getPHID');7475foreach ($signatures as $key => $signature) {76$document_phid = $signature->getDocumentPHID();77$document = idx($documents, $document_phid);78if ($document) {79$signature->attachDocument($document);80} else {81unset($signatures[$key]);82}83}8485return $signatures;86}8788protected function buildWhereClause(AphrontDatabaseConnection $conn) {89$where = array();9091$where[] = $this->buildPagingClause($conn);9293if ($this->ids !== null) {94$where[] = qsprintf(95$conn,96'id IN (%Ld)',97$this->ids);98}99100if ($this->documentPHIDs !== null) {101$where[] = qsprintf(102$conn,103'documentPHID IN (%Ls)',104$this->documentPHIDs);105}106107if ($this->signerPHIDs !== null) {108$where[] = qsprintf(109$conn,110'signerPHID IN (%Ls)',111$this->signerPHIDs);112}113114if ($this->documentVersions !== null) {115$where[] = qsprintf(116$conn,117'documentVersion IN (%Ld)',118$this->documentVersions);119}120121if ($this->secretKeys !== null) {122$where[] = qsprintf(123$conn,124'secretKey IN (%Ls)',125$this->secretKeys);126}127128if ($this->nameContains !== null) {129$where[] = qsprintf(130$conn,131'signerName LIKE %~',132$this->nameContains);133}134135if ($this->emailContains !== null) {136$where[] = qsprintf(137$conn,138'signerEmail LIKE %~',139$this->emailContains);140}141142return $this->formatWhereClause($conn, $where);143}144145public function getQueryApplicationClass() {146return 'PhabricatorLegalpadApplication';147}148149}150151152