Path: blob/master/src/applications/dashboard/query/PhabricatorDashboardSearchEngine.php
12242 views
<?php12final class PhabricatorDashboardSearchEngine3extends PhabricatorApplicationSearchEngine {45public function getResultTypeDescription() {6return pht('Dashboards');7}89public function getApplicationClassName() {10return 'PhabricatorDashboardApplication';11}1213public function newQuery() {14return id(new PhabricatorDashboardQuery());15}1617public function canUseInPanelContext() {18return false;19}2021protected function buildCustomSearchFields() {22return array(23id(new PhabricatorSearchDatasourceField())24->setLabel(pht('Authored By'))25->setKey('authorPHIDs')26->setDatasource(new PhabricatorPeopleUserFunctionDatasource()),27id(new PhabricatorSearchCheckboxesField())28->setKey('statuses')29->setLabel(pht('Status'))30->setOptions(PhabricatorDashboard::getStatusNameMap()),31id(new PhabricatorSearchCheckboxesField())32->setKey('editable')33->setLabel(pht('Editable'))34->setOptions(array('editable' => null)),35);36}3738protected function getURI($path) {39return '/dashboard/'.$path;40}4142protected function getBuiltinQueryNames() {43$names = array();4445if ($this->requireViewer()->isLoggedIn()) {46$names['authored'] = pht('Authored');47}4849$names['open'] = pht('Active Dashboards');50$names['all'] = pht('All Dashboards');5152return $names;53}5455public function buildSavedQueryFromBuiltin($query_key) {56$query = $this->newSavedQuery();57$query->setQueryKey($query_key);58$viewer = $this->requireViewer();5960switch ($query_key) {61case 'all':62return $query;63case 'authored':64return $query->setParameter(65'authorPHIDs',66array(67$viewer->getPHID(),68));69case 'open':70return $query->setParameter(71'statuses',72array(73PhabricatorDashboard::STATUS_ACTIVE,74));75}7677return parent::buildSavedQueryFromBuiltin($query_key);78}7980protected function buildQueryFromParameters(array $map) {81$query = $this->newQuery();8283if ($map['statuses']) {84$query->withStatuses($map['statuses']);85}8687if ($map['authorPHIDs']) {88$query->withAuthorPHIDs($map['authorPHIDs']);89}9091if ($map['editable'] !== null) {92$query->withCanEdit($map['editable']);93}9495return $query;96}9798protected function renderResultList(99array $dashboards,100PhabricatorSavedQuery $query,101array $handles) {102103$viewer = $this->requireViewer();104105$phids = array();106foreach ($dashboards as $dashboard) {107$author_phid = $dashboard->getAuthorPHID();108if ($author_phid) {109$phids[] = $author_phid;110}111}112113$handles = $viewer->loadHandles($phids);114115if ($dashboards) {116$edge_query = id(new PhabricatorEdgeQuery())117->withSourcePHIDs(mpull($dashboards, 'getPHID'))118->withEdgeTypes(119array(120PhabricatorProjectObjectHasProjectEdgeType::EDGECONST,121));122123$edge_query->execute();124}125126$list = id(new PHUIObjectItemListView())127->setViewer($viewer);128129foreach ($dashboards as $dashboard) {130$item = id(new PHUIObjectItemView())131->setViewer($viewer)132->setObjectName($dashboard->getObjectName())133->setHeader($dashboard->getName())134->setHref($dashboard->getURI())135->setObject($dashboard);136137if ($dashboard->isArchived()) {138$item->setDisabled(true);139$bg_color = 'bg-grey';140} else {141$bg_color = 'bg-dark';142}143144$icon = id(new PHUIIconView())145->setIcon($dashboard->getIcon())146->setBackground($bg_color);147$item->setImageIcon($icon);148$item->setEpoch($dashboard->getDateModified());149150$author_phid = $dashboard->getAuthorPHID();151$author_name = $handles[$author_phid]->renderLink();152$item->addByline(pht('Author: %s', $author_name));153154$phid = $dashboard->getPHID();155$project_phids = $edge_query->getDestinationPHIDs(array($phid));156$project_handles = $viewer->loadHandles($project_phids);157158$item->addAttribute(159id(new PHUIHandleTagListView())160->setLimit(4)161->setNoDataString(pht('No Tags'))162->setSlim(true)163->setHandles($project_handles));164165$list->addItem($item);166}167168$result = new PhabricatorApplicationSearchResultView();169$result->setObjectList($list);170$result->setNoDataString(pht('No dashboards found.'));171172return $result;173}174175}176177178