Path: blob/master/src/applications/drydock/query/DrydockResourceSearchEngine.php
12256 views
<?php12final class DrydockResourceSearchEngine3extends PhabricatorApplicationSearchEngine {45private $blueprint;67public function setBlueprint(DrydockBlueprint $blueprint) {8$this->blueprint = $blueprint;9return $this;10}1112public function getBlueprint() {13return $this->blueprint;14}1516public function getResultTypeDescription() {17return pht('Drydock Resources');18}1920public function getApplicationClassName() {21return 'PhabricatorDrydockApplication';22}2324public function newQuery() {25$query = new DrydockResourceQuery();2627$blueprint = $this->getBlueprint();28if ($blueprint) {29$query->withBlueprintPHIDs(array($blueprint->getPHID()));30}3132return $query;33}3435protected function buildQueryFromParameters(array $map) {36$query = $this->newQuery();3738if ($map['statuses']) {39$query->withStatuses($map['statuses']);40}4142if ($map['blueprintPHIDs']) {43$query->withBlueprintPHIDs($map['blueprintPHIDs']);44}4546return $query;47}4849protected function buildCustomSearchFields() {50return array(51id(new PhabricatorSearchCheckboxesField())52->setLabel(pht('Statuses'))53->setKey('statuses')54->setOptions(DrydockResourceStatus::getStatusMap()),55id(new PhabricatorPHIDsSearchField())56->setLabel(pht('Blueprints'))57->setKey('blueprintPHIDs')58->setAliases(array('blueprintPHID', 'blueprints', 'blueprint'))59->setDescription(60pht('Search for resources generated by particular blueprints.')),61);62}6364protected function getURI($path) {65$blueprint = $this->getBlueprint();66if ($blueprint) {67$id = $blueprint->getID();68return "/drydock/blueprint/{$id}/resources/".$path;69} else {70return '/drydock/resource/'.$path;71}72}7374protected function getBuiltinQueryNames() {75return array(76'active' => pht('Active Resources'),77'all' => pht('All Resources'),78);79}8081public function buildSavedQueryFromBuiltin($query_key) {82$query = $this->newSavedQuery();83$query->setQueryKey($query_key);8485switch ($query_key) {86case 'active':87return $query->setParameter(88'statuses',89array(90DrydockResourceStatus::STATUS_PENDING,91DrydockResourceStatus::STATUS_ACTIVE,92));93case 'all':94return $query;95}9697return parent::buildSavedQueryFromBuiltin($query_key);98}99100protected function renderResultList(101array $resources,102PhabricatorSavedQuery $query,103array $handles) {104105$list = id(new DrydockResourceListView())106->setUser($this->requireViewer())107->setResources($resources);108109$result = new PhabricatorApplicationSearchResultView();110$result->setTable($list);111112return $result;113}114115}116117118