Files
phabricator/src/applications/releeph/controller/project/ReleephProjectListController.php
epriestley ae1f0e3b1b Introduce ReleephProjectQuery
Summary:
Adds a policy-aware query class for selecting Releeph projects. This doesn't really change anything.

  - Make `ReleephProject` implment `PhabricatorPolicyInterface`, beginning the long journey to make it policy-aware.
  - Implement `ReleephProjectQuery`, for querying projects using cursor-based, policy-aware paging.
  - Use it on the list view, so we load only ~100 projects instead of all of them.
  - Tweaked some of the URI routing stuff to make it a little more consistent with common practices.

Ref T2714.

Test Plan:
{F36434}
{F36435}

Reviewers: edward

Reviewed By: edward

CC: aran

Maniphest Tasks: T2714

Differential Revision: https://secure.phabricator.com/D5390
2013-03-22 06:29:37 -07:00

96 lines
2.4 KiB
PHP

<?php
final class ReleephProjectListController extends PhabricatorController {
private $filter;
public function willProcessRequest(array $data) {
$this->filter = idx($data, 'filter', 'active');
}
public function processRequest() {
$request = $this->getRequest();
$user = $request->getUser();
$query = id(new ReleephProjectQuery())
->setViewer($user)
->setOrder(ReleephProjectQuery::ORDER_NAME);
switch ($this->filter) {
case 'inactive':
$query->withActive(0);
$is_active = false;
break;
case 'active':
$query->withActive(1);
$is_active = true;
break;
default:
throw new Exception("Unknown filter '{$this->filter}'!");
}
$pager = new AphrontCursorPagerView();
$pager->readFromRequest($request);
$releeph_projects = $query->executeWithCursorPager($pager);
$releeph_projects_set = new LiskDAOSet();
foreach ($releeph_projects as $releeph_project) {
$releeph_projects_set->addToSet($releeph_project);
}
$panel = new AphrontPanelView();
if ($is_active) {
$view_inactive_link = phutil_tag(
'a',
array(
'href' => '/releeph/project/inactive/',
),
'View inactive projects');
$panel
->setHeader(hsprintf(
'Active Releeph Projects &middot; %s', $view_inactive_link))
->appendChild(
id(new ReleephActiveProjectListView())
->setUser($this->getRequest()->getUser())
->setReleephProjects($releeph_projects));
} else {
$view_active_link = phutil_tag(
'a',
array(
'href' => '/releeph/project/'
),
'View active projects');
$panel
->setHeader(hsprintf(
'Inactive Releeph Projects &middot; %s', $view_active_link))
->appendChild(
id(new ReleephInactiveProjectListView())
->setUser($this->getRequest()->getUser())
->setReleephProjects($releeph_projects));
}
if ($is_active) {
$create_new_project_button = phutil_tag(
'a',
array(
'href' => '/releeph/project/create/',
'class' => 'green button',
),
'Create New Project');
$panel->addButton($create_new_project_button);
}
return $this->buildApplicationPage(
array(
$panel,
$pager,
),
array(
'title' => 'List Releeph Projects',
));
}
}