From 0386ac9aa2945fac725104ab2ba51899c043e1e1 Mon Sep 17 00:00:00 2001 From: epriestley Date: Fri, 16 Dec 2011 13:44:10 -0800 Subject: [PATCH] projquery --- .../list/PhabricatorProjectListController.php | 7 +- .../query/project/PhabricatorProjectQuery.php | 84 +++++++++++++++++++ 2 files changed, 90 insertions(+), 1 deletion(-) create mode 100644 src/applications/project/query/project/PhabricatorProjectQuery.php diff --git a/src/applications/project/controller/list/PhabricatorProjectListController.php b/src/applications/project/controller/list/PhabricatorProjectListController.php index 25eaf353c7..8ac5e6f6d6 100644 --- a/src/applications/project/controller/list/PhabricatorProjectListController.php +++ b/src/applications/project/controller/list/PhabricatorProjectListController.php @@ -21,6 +21,9 @@ class PhabricatorProjectListController public function processRequest() { + $side_nav = new AphrontSideNavView(); + + $projects = id(new PhabricatorProject())->loadAllWhere( '1 = 1 ORDER BY id DESC limit 100'); $project_phids = mpull($projects, 'getPHID'); @@ -125,8 +128,10 @@ class PhabricatorProjectListController $panel->setHeader('Project'); $panel->setCreateButton('Create New Project', '/project/create/'); + $side_nav->appendChild($panel); + return $this->buildStandardPageResponse( - $panel, + $side_nav, array( 'title' => 'Projects', )); diff --git a/src/applications/project/query/project/PhabricatorProjectQuery.php b/src/applications/project/query/project/PhabricatorProjectQuery.php new file mode 100644 index 0000000000..5d8ed775a8 --- /dev/null +++ b/src/applications/project/query/project/PhabricatorProjectQuery.php @@ -0,0 +1,84 @@ +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); + } + +} \ No newline at end of file