2014-01-17 20:40:26 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
final class LegalpadDocumentSignatureQuery
|
|
|
|
extends PhabricatorCursorPagedPolicyAwareQuery {
|
|
|
|
|
|
|
|
private $ids;
|
|
|
|
private $documentPHIDs;
|
|
|
|
private $signerPHIDs;
|
|
|
|
private $documentVersions;
|
|
|
|
private $secretKeys;
|
2014-06-29 16:51:03 +02:00
|
|
|
private $nameContains;
|
|
|
|
private $emailContains;
|
2014-01-17 20:40:26 +01:00
|
|
|
|
|
|
|
public function withIDs(array $ids) {
|
|
|
|
$this->ids = $ids;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function withDocumentPHIDs(array $phids) {
|
|
|
|
$this->documentPHIDs = $phids;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function withSignerPHIDs(array $phids) {
|
|
|
|
$this->signerPHIDs = $phids;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function withDocumentVersions(array $versions) {
|
|
|
|
$this->documentVersions = $versions;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function withSecretKeys(array $keys) {
|
|
|
|
$this->secretKeys = $keys;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
2014-06-29 16:51:03 +02:00
|
|
|
public function withNameContains($text) {
|
|
|
|
$this->nameContains = $text;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function withEmailContains($text) {
|
|
|
|
$this->emailContains = $text;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
2014-01-17 20:40:26 +01:00
|
|
|
protected function loadPage() {
|
|
|
|
$table = new LegalpadDocumentSignature();
|
|
|
|
$conn_r = $table->establishConnection('r');
|
|
|
|
|
|
|
|
$data = queryfx_all(
|
|
|
|
$conn_r,
|
|
|
|
'SELECT * FROM %T %Q %Q %Q',
|
|
|
|
$table->getTableName(),
|
|
|
|
$this->buildWhereClause($conn_r),
|
|
|
|
$this->buildOrderClause($conn_r),
|
|
|
|
$this->buildLimitClause($conn_r));
|
|
|
|
|
2014-06-29 01:36:15 +02:00
|
|
|
$signatures = $table->loadAllFromArray($data);
|
2014-01-17 20:40:26 +01:00
|
|
|
|
2014-06-29 01:36:15 +02:00
|
|
|
return $signatures;
|
|
|
|
}
|
|
|
|
|
|
|
|
protected function willFilterPage(array $signatures) {
|
|
|
|
$document_phids = mpull($signatures, 'getDocumentPHID');
|
|
|
|
|
|
|
|
$documents = id(new LegalpadDocumentQuery())
|
|
|
|
->setParentQuery($this)
|
|
|
|
->setViewer($this->getViewer())
|
|
|
|
->withPHIDs($document_phids)
|
|
|
|
->execute();
|
|
|
|
$documents = mpull($documents, null, 'getPHID');
|
|
|
|
|
|
|
|
foreach ($signatures as $key => $signature) {
|
|
|
|
$document_phid = $signature->getDocumentPHID();
|
|
|
|
$document = idx($documents, $document_phid);
|
|
|
|
if ($document) {
|
|
|
|
$signature->attachDocument($document);
|
|
|
|
} else {
|
|
|
|
unset($signatures[$key]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return $signatures;
|
2014-01-17 20:40:26 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
protected function buildWhereClause($conn_r) {
|
|
|
|
$where = array();
|
|
|
|
|
|
|
|
$where[] = $this->buildPagingClause($conn_r);
|
|
|
|
|
2014-06-29 01:36:15 +02:00
|
|
|
if ($this->ids !== null) {
|
2014-01-17 20:40:26 +01:00
|
|
|
$where[] = qsprintf(
|
|
|
|
$conn_r,
|
|
|
|
'id IN (%Ld)',
|
|
|
|
$this->ids);
|
|
|
|
}
|
|
|
|
|
2014-06-29 01:36:15 +02:00
|
|
|
if ($this->documentPHIDs !== null) {
|
2014-01-17 20:40:26 +01:00
|
|
|
$where[] = qsprintf(
|
|
|
|
$conn_r,
|
|
|
|
'documentPHID IN (%Ls)',
|
|
|
|
$this->documentPHIDs);
|
|
|
|
}
|
|
|
|
|
2014-06-29 01:36:15 +02:00
|
|
|
if ($this->signerPHIDs !== null) {
|
2014-01-17 20:40:26 +01:00
|
|
|
$where[] = qsprintf(
|
|
|
|
$conn_r,
|
|
|
|
'signerPHID IN (%Ls)',
|
|
|
|
$this->signerPHIDs);
|
|
|
|
}
|
|
|
|
|
2014-06-29 01:36:15 +02:00
|
|
|
if ($this->documentVersions !== null) {
|
2014-01-17 20:40:26 +01:00
|
|
|
$where[] = qsprintf(
|
|
|
|
$conn_r,
|
|
|
|
'documentVersion IN (%Ld)',
|
|
|
|
$this->documentVersions);
|
|
|
|
}
|
|
|
|
|
2014-06-29 01:36:15 +02:00
|
|
|
if ($this->secretKeys !== null) {
|
2014-01-17 20:40:26 +01:00
|
|
|
$where[] = qsprintf(
|
|
|
|
$conn_r,
|
|
|
|
'secretKey IN (%Ls)',
|
|
|
|
$this->secretKeys);
|
|
|
|
}
|
|
|
|
|
2014-06-29 16:51:03 +02:00
|
|
|
if ($this->nameContains !== null) {
|
|
|
|
$where[] = qsprintf(
|
|
|
|
$conn_r,
|
|
|
|
'signerName LIKE %~',
|
|
|
|
$this->nameContains);
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($this->emailContains !== null) {
|
|
|
|
$where[] = qsprintf(
|
|
|
|
$conn_r,
|
|
|
|
'signerEmail LIKE %~',
|
|
|
|
$this->emailContains);
|
|
|
|
}
|
|
|
|
|
2014-01-17 20:40:26 +01:00
|
|
|
return $this->formatWhereClause($where);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getQueryApplicationClass() {
|
2014-07-23 02:03:09 +02:00
|
|
|
return 'PhabricatorLegalpadApplication';
|
2014-01-17 20:40:26 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|