public function processRequest() { $projects = id(new PhabricatorProject())->loadAllWhere('1 = 1 ORDER BY id DESC limit 100'); $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); } $author_phids = mpull($projects, 'getAuthorPHID'); $handles = id(new PhabricatorObjectHandleData($author_phids))->loadHandles(); $query = id(new ManiphestTaskQuery())->withProjects($project_phids)->withAnyProject(true)->withStatus(ManiphestTaskQuery::STATUS_OPEN)->setLimit(PHP_INT_MAX); $tasks = $query->execute(); $groups = array(); foreach ($tasks as $task) { foreach ($task->getProjectPHIDs() as $phid) { $groups[$phid][] = $task; } } $rows = array(); foreach ($projects as $project) { $phid = $project->getPHID(); $profile = $profiles[$phid]; $affiliations = $affil_groups[$phid]; $group = idx($groups, $phid, array()); $task_count = count($group); $population = count($affiliations); $status = PhabricatorProjectStatus::getNameForStatus($project->getStatus()); $blurb = $profile->getBlurb(); $blurb = phutil_utf8_shorten($blurb, $columns = 100); $rows[] = array(phutil_escape_html($project->getName()), phutil_escape_html($blurb), $handles[$project->getAuthorPHID()]->renderLink(), phutil_escape_html($population), phutil_escape_html($status), phutil_render_tag('a', array('href' => '/maniphest/view/all/?projects=' . $phid), phutil_escape_html($task_count)), phutil_render_tag('a', array('class' => 'small grey button', 'href' => '/project/view/' . $project->getID() . '/'), 'View Project Profile')); } $table = new AphrontTableView($rows); $table->setHeaders(array('Project', 'Description', 'Mastermind', 'Population', 'Status', 'Open Tasks', '')); $table->setColumnClasses(array('pri', 'wide', '', 'right', '', 'right', 'action')); $panel = new AphrontPanelView(); $panel->appendChild($table); $panel->setHeader('Project'); $panel->setCreateButton('Create New Project', '/project/create/'); return $this->buildStandardPageResponse($panel, array('title' => 'Projects')); }
public function loadAffiliations() { $affils = PhabricatorProjectAffiliation::loadAllForProjectPHIDs(array($this->getPHID())); return $affils[$this->getPHID()]; }
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'); $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(); switch ($this->filter) { case 'active': $table_header = 'Active Projects'; $query->setMembers(array($view_phid)); break; case 'owned': $table_header = 'Owned Projects'; $query->setOwners(array($view_phid)); break; case 'all': $table_header = 'All Projects'; 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 = $profiles[$phid]; $affiliations = $affil_groups[$phid]; $group = idx($groups, $phid, array()); $task_count = count($group); $population = count($affiliations); $blurb = $profile->getBlurb(); $blurb = phutil_utf8_shorten($blurb, 64); $rows[] = array(phutil_render_tag('a', array('href' => '/project/view/' . $project->getID() . '/'), phutil_escape_html($project->getName())), 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', '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')); }
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; }