1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2025-01-23 21:18:19 +01:00
phorge-phorge/src/applications/drydock/query/DrydockLeaseSearchEngine.php
epriestley 64ed971039 Show recent active leases on Drydock resource detail
Summary: Ref T9252. This is the same as D14157, just for Resources and their leases.

Test Plan: Viewed a resource, saw only active leases, clicked "View All Leases", queried, clicked around, used crumbs.

Reviewers: chad

Reviewed By: chad

Maniphest Tasks: T9252

Differential Revision: https://secure.phabricator.com/D14158
2015-09-24 15:28:59 -07:00

105 lines
2.3 KiB
PHP

<?php
final class DrydockLeaseSearchEngine
extends PhabricatorApplicationSearchEngine {
private $resource;
public function setResource($resource) {
$this->resource = $resource;
return $this;
}
public function getResource() {
return $this->resource;
}
public function getResultTypeDescription() {
return pht('Drydock Leases');
}
public function getApplicationClassName() {
return 'PhabricatorDrydockApplication';
}
public function newQuery() {
$query = new DrydockLeaseQuery();
$resource = $this->getResource();
if ($resource) {
$query->withResourcePHIDs(array($resource->getPHID()));
}
return $query;
}
protected function buildQueryFromParameters(array $map) {
$query = $this->newQuery();
if ($map['statuses']) {
$query->withStatuses($map['statuses']);
}
return $query;
}
protected function buildCustomSearchFields() {
return array(
id(new PhabricatorSearchCheckboxesField())
->setLabel(pht('Statuses'))
->setKey('statuses')
->setOptions(DrydockLeaseStatus::getStatusMap()),
);
}
protected function getURI($path) {
$resource = $this->getResource();
if ($resource) {
$id = $resource->getID();
return "/drydock/resource/{$id}/leases/".$path;
} else {
return '/drydock/lease/'.$path;
}
}
protected function getBuiltinQueryNames() {
return array(
'active' => pht('Active Leases'),
'all' => pht('All Leases'),
);
}
public function buildSavedQueryFromBuiltin($query_key) {
$query = $this->newSavedQuery();
$query->setQueryKey($query_key);
switch ($query_key) {
case 'active':
return $query->setParameter(
'statuses',
array(
DrydockLeaseStatus::STATUS_PENDING,
DrydockLeaseStatus::STATUS_ACQUIRED,
DrydockLeaseStatus::STATUS_ACTIVE,
));
case 'all':
return $query;
}
return parent::buildSavedQueryFromBuiltin($query_key);
}
protected function renderResultList(
array $leases,
PhabricatorSavedQuery $saved,
array $handles) {
$list = id(new DrydockLeaseListView())
->setUser($this->requireViewer())
->setLeases($leases);
return id(new PhabricatorApplicationSearchResultView())
->setContent($list);
}
}