[ Index ]

PHP Cross Reference of Phabricator

title

Body

[close]

/src/applications/legalpad/query/ -> LegalpadDocumentSignatureQuery.php (source)

   1  <?php
   2  
   3  final class LegalpadDocumentSignatureQuery
   4    extends PhabricatorCursorPagedPolicyAwareQuery {
   5  
   6    private $ids;
   7    private $documentPHIDs;
   8    private $signerPHIDs;
   9    private $documentVersions;
  10    private $secretKeys;
  11    private $nameContains;
  12    private $emailContains;
  13  
  14    public function withIDs(array $ids) {
  15      $this->ids = $ids;
  16      return $this;
  17    }
  18  
  19    public function withDocumentPHIDs(array $phids) {
  20      $this->documentPHIDs = $phids;
  21      return $this;
  22    }
  23  
  24    public function withSignerPHIDs(array $phids) {
  25      $this->signerPHIDs = $phids;
  26      return $this;
  27    }
  28  
  29    public function withDocumentVersions(array $versions) {
  30      $this->documentVersions = $versions;
  31      return $this;
  32    }
  33  
  34    public function withSecretKeys(array $keys) {
  35      $this->secretKeys = $keys;
  36      return $this;
  37    }
  38  
  39    public function withNameContains($text) {
  40      $this->nameContains = $text;
  41      return $this;
  42    }
  43  
  44    public function withEmailContains($text) {
  45      $this->emailContains = $text;
  46      return $this;
  47    }
  48  
  49    protected function loadPage() {
  50      $table = new LegalpadDocumentSignature();
  51      $conn_r = $table->establishConnection('r');
  52  
  53      $data = queryfx_all(
  54        $conn_r,
  55        'SELECT * FROM %T %Q %Q %Q',
  56        $table->getTableName(),
  57        $this->buildWhereClause($conn_r),
  58        $this->buildOrderClause($conn_r),
  59        $this->buildLimitClause($conn_r));
  60  
  61      $signatures = $table->loadAllFromArray($data);
  62  
  63      return $signatures;
  64    }
  65  
  66    protected function willFilterPage(array $signatures) {
  67      $document_phids = mpull($signatures, 'getDocumentPHID');
  68  
  69      $documents = id(new LegalpadDocumentQuery())
  70        ->setParentQuery($this)
  71        ->setViewer($this->getViewer())
  72        ->withPHIDs($document_phids)
  73        ->execute();
  74      $documents = mpull($documents, null, 'getPHID');
  75  
  76      foreach ($signatures as $key => $signature) {
  77        $document_phid = $signature->getDocumentPHID();
  78        $document = idx($documents, $document_phid);
  79        if ($document) {
  80          $signature->attachDocument($document);
  81        } else {
  82          unset($signatures[$key]);
  83        }
  84      }
  85  
  86      return $signatures;
  87    }
  88  
  89    protected function buildWhereClause($conn_r) {
  90      $where = array();
  91  
  92      $where[] = $this->buildPagingClause($conn_r);
  93  
  94      if ($this->ids !== null) {
  95        $where[] = qsprintf(
  96          $conn_r,
  97          'id IN (%Ld)',
  98          $this->ids);
  99      }
 100  
 101      if ($this->documentPHIDs !== null) {
 102        $where[] = qsprintf(
 103          $conn_r,
 104          'documentPHID IN (%Ls)',
 105          $this->documentPHIDs);
 106      }
 107  
 108      if ($this->signerPHIDs !== null) {
 109        $where[] = qsprintf(
 110          $conn_r,
 111          'signerPHID IN (%Ls)',
 112          $this->signerPHIDs);
 113      }
 114  
 115      if ($this->documentVersions !== null) {
 116        $where[] = qsprintf(
 117          $conn_r,
 118          'documentVersion IN (%Ld)',
 119          $this->documentVersions);
 120      }
 121  
 122      if ($this->secretKeys !== null) {
 123        $where[] = qsprintf(
 124          $conn_r,
 125          'secretKey IN (%Ls)',
 126          $this->secretKeys);
 127      }
 128  
 129      if ($this->nameContains !== null) {
 130        $where[] = qsprintf(
 131          $conn_r,
 132          'signerName LIKE %~',
 133          $this->nameContains);
 134      }
 135  
 136      if ($this->emailContains !== null) {
 137        $where[] = qsprintf(
 138          $conn_r,
 139          'signerEmail LIKE %~',
 140          $this->emailContains);
 141      }
 142  
 143      return $this->formatWhereClause($where);
 144    }
 145  
 146    public function getQueryApplicationClass() {
 147      return 'PhabricatorLegalpadApplication';
 148    }
 149  
 150  }


Generated: Sun Nov 30 09:20:46 2014 Cross-referenced by PHPXref 0.7.1