diff --git a/src/applications/project/controller/PhabricatorProjectListController.php b/src/applications/project/controller/PhabricatorProjectListController.php index 535f62e9e5..4dab336181 100644 --- a/src/applications/project/controller/PhabricatorProjectListController.php +++ b/src/applications/project/controller/PhabricatorProjectListController.php @@ -1,186 +1,180 @@ filter = idx($data, 'filter'); } public function processRequest() { $request = $this->getRequest(); $nav = new AphrontSideNavFilterView(); $nav ->setBaseURI(new PhutilURI('/project/filter/')) ->addLabel('User') ->addFilter('active', 'Active') - ->addFilter('owned', 'Owned') ->addSpacer() ->addLabel('All') ->addFilter('all', 'All Projects') ->addFilter('allactive','Active Projects'); $this->filter = $nav->selectFilter($this->filter, 'active'); $pager = new AphrontPagerView(); $pager->setPageSize(250); $pager->setURI($request->getRequestURI(), 'page'); $pager->setOffset($request->getInt('page')); $query = new PhabricatorProjectQuery(); $query->setOffset($pager->getOffset()); $query->setLimit($pager->getPageSize() + 1); $view_phid = $request->getUser()->getPHID(); $status_filter = PhabricatorProjectQuery::STATUS_ANY; switch ($this->filter) { case 'active': $table_header = 'Your Projects'; $query->setMembers(array($view_phid)); $query->withStatus(PhabricatorProjectQuery::STATUS_ACTIVE); break; - case 'owned': - $table_header = 'Owned Projects'; - $query->setOwners(array($view_phid)); - $query->withStatus($status_filter); - break; case 'allactive': $status_filter = PhabricatorProjectQuery::STATUS_ACTIVE; $table_header = 'Active Projects'; // fallthrough case 'all': $table_header = 'All Projects'; $query->withStatus($status_filter); break; } $projects = $query->execute(); $projects = $pager->sliceResults($projects); $project_phids = mpull($projects, 'getPHID'); $profiles = array(); if ($projects) { $profiles = id(new PhabricatorProjectProfile())->loadAllWhere( 'projectPHID in (%Ls)', $project_phids); $profiles = mpull($profiles, null, 'getProjectPHID'); } $affil_groups = array(); if ($projects) { $affil_groups = PhabricatorProjectAffiliation::loadAllForProjectPHIDs( $project_phids); } $tasks = array(); $groups = array(); if ($project_phids) { $query = id(new ManiphestTaskQuery()) ->withProjects($project_phids) ->withAnyProject(true) ->withStatus(ManiphestTaskQuery::STATUS_OPEN) ->setLimit(PHP_INT_MAX); $tasks = $query->execute(); foreach ($tasks as $task) { foreach ($task->getProjectPHIDs() as $phid) { $groups[$phid][] = $task; } } } $rows = array(); foreach ($projects as $project) { $phid = $project->getPHID(); $profile = idx($profiles, $phid); $affiliations = $affil_groups[$phid]; $group = idx($groups, $phid, array()); $task_count = count($group); $population = count($affiliations); if ($profile) { $blurb = $profile->getBlurb(); $blurb = phutil_utf8_shorten($blurb, 64); } else { $blurb = null; } $rows[] = array( phutil_render_tag( 'a', array( 'href' => '/project/view/'.$project->getID().'/', ), phutil_escape_html($project->getName())), phutil_escape_html( PhabricatorProjectStatus::getNameForStatus($project->getStatus())), phutil_escape_html($blurb), phutil_escape_html($population), phutil_render_tag( 'a', array( 'href' => '/maniphest/view/all/?projects='.$phid, ), phutil_escape_html($task_count)), ); } $table = new AphrontTableView($rows); $table->setHeaders( array( 'Project', 'Status', 'Description', 'Population', 'Open Tasks', )); $table->setColumnClasses( array( 'pri', '', 'wide', '', '' )); $panel = new AphrontPanelView(); $panel->setHeader($table_header); $panel->setCreateButton('Create New Project', '/project/create/'); $panel->appendChild($table); $panel->appendChild($pager); $nav->appendChild($panel); return $this->buildStandardPageResponse( $nav, array( 'title' => 'Projects', )); } } diff --git a/src/applications/project/query/PhabricatorProjectQuery.php b/src/applications/project/query/PhabricatorProjectQuery.php index 58464fdd42..b1d7e65f45 100644 --- a/src/applications/project/query/PhabricatorProjectQuery.php +++ b/src/applications/project/query/PhabricatorProjectQuery.php @@ -1,212 +1,197 @@ ids = $ids; return $this; } public function withPHIDs(array $phids) { $this->phids = $phids; return $this; } public function withStatus($status) { $this->status = $status; return $this; } 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 needMembers($need_members) { $this->needMembers = $need_members; return $this; } public function execute() { $table = id(new PhabricatorProject()); $conn_r = $table->establishConnection('r'); $where = $this->buildWhereClause($conn_r); $joins = $this->buildJoinsClause($conn_r); $limit = ''; if ($this->limit) { $limit = qsprintf( $conn_r, 'LIMIT %d, %d', $this->offset, $this->limit); } else if ($this->offset) { $limit = qsprintf( $conn_r, 'LIMIT %d, %d', $this->offset, PHP_INT_MAX); } $order = 'ORDER BY name'; $data = queryfx_all( $conn_r, 'SELECT p.* FROM %T p %Q %Q %Q %Q', $table->getTableName(), $joins, $where, $order, $limit); $projects = $table->loadAllFromArray($data); if ($projects && $this->needMembers) { $members = PhabricatorProjectAffiliation::loadAllForProjectPHIDs( mpull($projects, 'getPHID')); foreach ($projects as $project) { $project->attachAffiliations( array_values(idx($members, $project->getPHID(), array()))); } } return $projects; } private function buildWhereClause($conn_r) { $where = array(); if ($this->status != self::STATUS_ANY) { switch ($this->status) { case self::STATUS_OPEN: $where[] = qsprintf( $conn_r, 'status IN (%Ld)', array( PhabricatorProjectStatus::STATUS_ACTIVE, )); break; case self::STATUS_CLOSED: $where[] = qsprintf( $conn_r, 'status IN (%Ld)', array( PhabricatorProjectStatus::STATUS_ARCHIVED, )); break; case self::STATUS_ACTIVE: $where[] = qsprintf( $conn_r, 'status = %d', PhabricatorProjectStatus::STATUS_ACTIVE); break; case self::STATUS_ARCHIVED: $where[] = qsprintf( $conn_r, 'status = %d', PhabricatorProjectStatus::STATUS_ARCHIVED); break; default: throw new Exception( "Unknown project status '{$this->status}'!"); } } if ($this->ids) { $where[] = qsprintf( $conn_r, 'id IN (%Ld)', $this->ids); } if ($this->phids) { $where[] = qsprintf( $conn_r, 'phid IN (%Ls)', $this->phids); } if ($where) { $where = 'WHERE ('.implode(') AND (', $where).')'; } else { $where = ''; } return $where; } private function buildJoinsClause($conn_r) { $affil_table = new PhabricatorProjectAffiliation(); $joins = array(); - if ($this->owners) { - $joins[] = qsprintf( - $conn_r, - '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( $conn_r, 'JOIN %T member ON member.projectPHID = p.phid AND member.userPHID in (%Ls)', $affil_table->getTableName(), $this->members); } return implode(' ', $joins); } }