1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-12-19 03:50:54 +01:00

projquery

This commit is contained in:
epriestley 2011-12-16 13:44:10 -08:00
parent 43fc7820e9
commit 0386ac9aa2
2 changed files with 90 additions and 1 deletions

View file

@ -21,6 +21,9 @@ class PhabricatorProjectListController
public function processRequest() { public function processRequest() {
$side_nav = new AphrontSideNavView();
$projects = id(new PhabricatorProject())->loadAllWhere( $projects = id(new PhabricatorProject())->loadAllWhere(
'1 = 1 ORDER BY id DESC limit 100'); '1 = 1 ORDER BY id DESC limit 100');
$project_phids = mpull($projects, 'getPHID'); $project_phids = mpull($projects, 'getPHID');
@ -125,8 +128,10 @@ class PhabricatorProjectListController
$panel->setHeader('Project'); $panel->setHeader('Project');
$panel->setCreateButton('Create New Project', '/project/create/'); $panel->setCreateButton('Create New Project', '/project/create/');
$side_nav->appendChild($panel);
return $this->buildStandardPageResponse( return $this->buildStandardPageResponse(
$panel, $side_nav,
array( array(
'title' => 'Projects', 'title' => 'Projects',
)); ));

View file

@ -0,0 +1,84 @@
<?php
final class PhabricatorProjectQuery {
private $owners;
private $members;
private $limit;
private $offset;
public function setLimit($limit) {
$this->limit = $limit;
return $this;
}
public function setOffset($offset) {
$this->offset = $offset;
return $this;
}
public function setOwners(array $owners) {
$this->owners = $owners;
return $this;
}
public function setMembers(array $members) {
$this->members = $members;
return $this;
}
public function execute() {
$table = id(new PhabricatorProject());
$conn_r = $table->establishConnection('r');
$joins = $this->buildJoinsClause($conn_r);
$limit = null;
if ($this->limit) {
$limit = qsprintf(
$conn_r,
'LIMIT %d, %d',
$offset,
$limit);
} else if ($this->offset) {
$limit = qsprintf(
$conn_r,
'LIMIT %d, %d',
$offset,
PHP_INT_MAX);
}
$data = queryfx_all(
$conn_r,
'SELECT * FROM %T p %Q %Q',
$table->getTableName();
$joins,
$limit);
}
private function buildJoinsClause($conn_r) {
$affil_table = new PhabricatorProjectAffiliation();
$joins = array();
if ($this->owners) {
$joins[] = qsprintf(
'JOIN %T owner ON owner.projectPHID = p.phid AND owner.isOwner = 1
AND owner.userPHID in (%Ls)',
$affil_table->getTableName(),
$this->owners);
}
if ($this->members) {
$joins[] = qsprintf(
'JOIN %T member ON member.projectPHID = p.phid AND member.status != %s
AND member.userPHID in (%Ls)',
$affil_table->getTableName(),
'former',
$this->members);
}
return implode(' ', $joins);
}
}