3 final class ReleephProductQuery
4 extends PhabricatorCursorPagedPolicyAwareQuery
{
9 private $repositoryPHIDs;
11 const ORDER_ID
= 'order-id';
12 const ORDER_NAME
= 'order-name';
14 public function withActive($active) {
15 $this->active
= $active;
19 public function setOrder($order) {
22 $this->setOrderVector(array('id'));
24 case self
::ORDER_NAME
:
25 $this->setOrderVector(array('name'));
28 throw new Exception(pht('Order "%s" not supported.', $order));
33 public function withIDs(array $ids) {
38 public function withPHIDs(array $phids) {
39 $this->phids
= $phids;
43 public function withRepositoryPHIDs(array $repository_phids) {
44 $this->repositoryPHIDs
= $repository_phids;
48 protected function loadPage() {
49 $table = new ReleephProject();
50 $conn_r = $table->establishConnection('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));
60 return $table->loadAllFromArray($rows);
63 protected function willFilterPage(array $projects) {
64 assert_instances_of($projects, 'ReleephProject');
66 $repository_phids = mpull($projects, 'getRepositoryPHID');
68 $repositories = id(new PhabricatorRepositoryQuery())
69 ->setViewer($this->getViewer())
70 ->withPHIDs($repository_phids)
72 $repositories = mpull($repositories, null, 'getPHID');
74 foreach ($projects as $key => $project) {
75 $repo = idx($repositories, $project->getRepositoryPHID());
77 unset($projects[$key]);
80 $project->attachRepository($repo);
86 protected function buildWhereClause(AphrontDatabaseConnection
$conn) {
89 if ($this->active
!== null) {
96 if ($this->ids
!== null) {
103 if ($this->phids
!== null) {
110 if ($this->repositoryPHIDs
!== null) {
113 'repositoryPHID IN (%Ls)',
114 $this->repositoryPHIDs
);
117 $where[] = $this->buildPagingClause($conn);
119 return $this->formatWhereClause($conn, $where);
122 public function getOrderableColumns() {
123 return parent
::getOrderableColumns() +
array(
133 protected function newPagingMapFromPartialObject($object) {
135 'id' => (int)$object->getID(),
136 'name' => $object->getName(),
140 public function getQueryApplicationClass() {
141 return 'PhabricatorReleephApplication';