Differential D12026 Diff 28957 src/applications/transactions/query/PhabricatorApplicationTransactionCommentQuery.php
Changeset View
Changeset View
Standalone View
Standalone View
src/applications/transactions/query/PhabricatorApplicationTransactionCommentQuery.php
| <?php | <?php | ||||
| final class PhabricatorApplicationTransactionCommentQuery | abstract class PhabricatorApplicationTransactionCommentQuery | ||||
| extends PhabricatorCursorPagedPolicyAwareQuery { | extends PhabricatorCursorPagedPolicyAwareQuery { | ||||
| private $template; | private $ids; | ||||
| private $authorPHIDs; | |||||
| private $phids; | private $phids; | ||||
| private $transactionPHIDs; | private $transactionPHIDs; | ||||
| private $isDeleted; | |||||
| abstract protected function getTemplate(); | |||||
| public function setTemplate( | public function withIDs(array $ids) { | ||||
| PhabricatorApplicationTransactionComment $template) { | $this->ids = $ids; | ||||
| $this->template = $template; | |||||
| return $this; | return $this; | ||||
| } | } | ||||
| public function withPHIDs(array $phids) { | public function withPHIDs(array $phids) { | ||||
| $this->phids = $phids; | $this->phids = $phids; | ||||
| return $this; | return $this; | ||||
| } | } | ||||
| public function withTransactionPHIDs(array $transaction_phids) { | public function withTransactionPHIDs(array $transaction_phids) { | ||||
| $this->transactionPHIDs = $transaction_phids; | $this->transactionPHIDs = $transaction_phids; | ||||
| return $this; | return $this; | ||||
| } | } | ||||
| public function withAuthorPHIDs(array $phids) { | |||||
| $this->authorPHIDs = $phids; | |||||
| return $this; | |||||
| } | |||||
| public function withDeleted($deleted) { | |||||
| $this->isDeleted = $deleted; | |||||
| return $this; | |||||
| } | |||||
| protected function loadPage() { | protected function loadPage() { | ||||
| $table = $this->template; | $table = $this->getTemplate(); | ||||
| $conn_r = $table->establishConnection('r'); | $conn_r = $table->establishConnection('r'); | ||||
| $data = queryfx_all( | $data = queryfx_all( | ||||
| $conn_r, | $conn_r, | ||||
| 'SELECT * FROM %T xc %Q %Q %Q', | 'SELECT * FROM %T xcomment %Q %Q %Q', | ||||
| $table->getTableName(), | $table->getTableName(), | ||||
| $this->buildWhereClause($conn_r), | $this->buildWhereClause($conn_r), | ||||
| $this->buildOrderClause($conn_r), | $this->buildOrderClause($conn_r), | ||||
| $this->buildLimitClause($conn_r)); | $this->buildLimitClause($conn_r)); | ||||
| return $table->loadAllFromArray($data); | return $table->loadAllFromArray($data); | ||||
| } | } | ||||
| private function buildWhereClause(AphrontDatabaseConnection $conn_r) { | protected function buildWhereClause(AphrontDatabaseConnection $conn_r) { | ||||
| $where = array(); | $where = array(); | ||||
| if ($this->phids) { | if ($this->ids !== null) { | ||||
| $where[] = qsprintf( | |||||
| $conn_r, | |||||
| 'xcomment.id IN (%Ld)', | |||||
| $this->ids); | |||||
| } | |||||
| if ($this->phids !== null) { | |||||
| $where[] = qsprintf( | $where[] = qsprintf( | ||||
| $conn_r, | $conn_r, | ||||
| 'phid IN (%Ls)', | 'xcomment.phid IN (%Ls)', | ||||
| $this->phids); | $this->phids); | ||||
| } | } | ||||
| if ($this->transactionPHIDs) { | if ($this->authorPHIDs !== null) { | ||||
| $where[] = qsprintf( | |||||
| $conn_r, | |||||
| 'xcomment.authorPHID IN (%Ls)', | |||||
| $this->authorPHIDs); | |||||
| } | |||||
| if ($this->transactionPHIDs !== null) { | |||||
| $where[] = qsprintf( | $where[] = qsprintf( | ||||
| $conn_r, | $conn_r, | ||||
| 'transactionPHID IN (%Ls)', | 'xcomment.transactionPHID IN (%Ls)', | ||||
| $this->transactionPHIDs); | $this->transactionPHIDs); | ||||
| } | } | ||||
| if ($this->isDeleted !== null) { | |||||
| $where[] = qsprintf( | |||||
| $conn_r, | |||||
| 'xcomment.isDeleted = %d', | |||||
| (int)$this->isDeleted); | |||||
| } | |||||
| return $this->formatWhereClause($where); | return $this->formatWhereClause($where); | ||||
| } | } | ||||
| public function getQueryApplicationClass() { | public function getQueryApplicationClass() { | ||||
| // TODO: Figure out the app via the template? | // TODO: Figure out the app via the template? | ||||
| return null; | return null; | ||||
| } | } | ||||
| } | } | ||||