Path: blob/master/src/applications/meta/query/PhabricatorAppSearchEngine.php
12256 views
<?php12final class PhabricatorAppSearchEngine3extends PhabricatorApplicationSearchEngine {45public function getResultTypeDescription() {6return pht('Applications');7}89public function getApplicationClassName() {10return 'PhabricatorApplicationsApplication';11}1213public function getPageSize(PhabricatorSavedQuery $saved) {14return INF;15}1617public function buildSavedQueryFromRequest(AphrontRequest $request) {18$saved = new PhabricatorSavedQuery();1920$saved->setParameter('name', $request->getStr('name'));2122$saved->setParameter(23'installed',24$this->readBoolFromRequest($request, 'installed'));25$saved->setParameter(26'prototypes',27$this->readBoolFromRequest($request, 'prototypes'));28$saved->setParameter(29'firstParty',30$this->readBoolFromRequest($request, 'firstParty'));31$saved->setParameter(32'launchable',33$this->readBoolFromRequest($request, 'launchable'));34$saved->setParameter(35'appemails',36$this->readBoolFromRequest($request, 'appemails'));3738return $saved;39}4041public function buildQueryFromSavedQuery(PhabricatorSavedQuery $saved) {42$query = id(new PhabricatorApplicationQuery())43->setOrder(PhabricatorApplicationQuery::ORDER_NAME)44->withUnlisted(false);4546$name = $saved->getParameter('name');47if ($name !== null && strlen($name)) {48$query->withNameContains($name);49}5051$installed = $saved->getParameter('installed');52if ($installed !== null) {53$query->withInstalled($installed);54}5556$prototypes = $saved->getParameter('prototypes');5758if ($prototypes === null) {59// NOTE: This is the old name of the 'prototypes' option, see T6084.60$prototypes = $saved->getParameter('beta');61$saved->setParameter('prototypes', $prototypes);62}6364if ($prototypes !== null) {65$query->withPrototypes($prototypes);66}6768$first_party = $saved->getParameter('firstParty');69if ($first_party !== null) {70$query->withFirstParty($first_party);71}7273$launchable = $saved->getParameter('launchable');74if ($launchable !== null) {75$query->withLaunchable($launchable);76}7778$appemails = $saved->getParameter('appemails');79if ($appemails !== null) {80$query->withApplicationEmailSupport($appemails);81}8283return $query;84}8586public function buildSearchForm(87AphrontFormView $form,88PhabricatorSavedQuery $saved) {8990$form91->appendChild(92id(new AphrontFormTextControl())93->setLabel(pht('Name Contains'))94->setName('name')95->setValue($saved->getParameter('name')))96->appendChild(97id(new AphrontFormSelectControl())98->setLabel(pht('Installed'))99->setName('installed')100->setValue($this->getBoolFromQuery($saved, 'installed'))101->setOptions(102array(103'' => pht('Show All Applications'),104'true' => pht('Show Installed Applications'),105'false' => pht('Show Uninstalled Applications'),106)))107->appendChild(108id(new AphrontFormSelectControl())109->setLabel(pht('Prototypes'))110->setName('prototypes')111->setValue($this->getBoolFromQuery($saved, 'prototypes'))112->setOptions(113array(114'' => pht('Show All Applications'),115'true' => pht('Show Prototype Applications'),116'false' => pht('Show Released Applications'),117)))118->appendChild(119id(new AphrontFormSelectControl())120->setLabel(pht('Provenance'))121->setName('firstParty')122->setValue($this->getBoolFromQuery($saved, 'firstParty'))123->setOptions(124array(125'' => pht('Show All Applications'),126'true' => pht('Show First-Party Applications'),127'false' => pht('Show Third-Party Applications'),128)))129->appendChild(130id(new AphrontFormSelectControl())131->setLabel(pht('Launchable'))132->setName('launchable')133->setValue($this->getBoolFromQuery($saved, 'launchable'))134->setOptions(135array(136'' => pht('Show All Applications'),137'true' => pht('Show Launchable Applications'),138'false' => pht('Show Non-Launchable Applications'),139)))140->appendChild(141id(new AphrontFormSelectControl())142->setLabel(pht('Application Emails'))143->setName('appemails')144->setValue($this->getBoolFromQuery($saved, 'appemails'))145->setOptions(146array(147'' => pht('Show All Applications'),148'true' => pht('Show Applications w/ App Email Support'),149'false' => pht('Show Applications w/o App Email Support'),150)));151}152153protected function getURI($path) {154return '/applications/'.$path;155}156157protected function getBuiltinQueryNames() {158return array(159'launcher' => pht('Launcher'),160'all' => pht('All Applications'),161);162}163164public function buildSavedQueryFromBuiltin($query_key) {165$query = $this->newSavedQuery();166$query->setQueryKey($query_key);167168switch ($query_key) {169case 'launcher':170return $query171->setParameter('installed', true)172->setParameter('launchable', true);173case 'all':174return $query;175}176177return parent::buildSavedQueryFromBuiltin($query_key);178}179180protected function renderResultList(181array $all_applications,182PhabricatorSavedQuery $query,183array $handle) {184assert_instances_of($all_applications, 'PhabricatorApplication');185186$all_applications = msort($all_applications, 'getName');187188if ($query->getQueryKey() == 'launcher') {189$groups = mgroup($all_applications, 'getApplicationGroup');190} else {191$groups = array($all_applications);192}193194$group_names = PhabricatorApplication::getApplicationGroups();195$groups = array_select_keys($groups, array_keys($group_names)) + $groups;196197$results = array();198foreach ($groups as $group => $applications) {199if (count($groups) > 1) {200$results[] = phutil_tag(201'h1',202array(203'class' => 'phui-oi-list-header',204),205idx($group_names, $group, $group));206}207208$list = new PHUIObjectItemListView();209210foreach ($applications as $application) {211$icon = $application->getIcon();212if (!$icon) {213$icon = 'application';214}215216$description = $application->getShortDescription();217218$configure = id(new PHUIButtonView())219->setTag('a')220->setIcon('fa-gears')221->setHref('/applications/view/'.get_class($application).'/')222->setText(pht('Configure'))223->setColor(PHUIButtonView::GREY);224225$name = $application->getName();226227$item = id(new PHUIObjectItemView())228->setHeader($name)229->setImageIcon($icon)230->setSideColumn($configure);231232if (!$application->isFirstParty()) {233$tag = id(new PHUITagView())234->setName(pht('Extension'))235->setIcon('fa-puzzle-piece')236->setColor(PHUITagView::COLOR_BLUE)237->setType(PHUITagView::TYPE_SHADE)238->setSlimShady(true);239$item->addAttribute($tag);240}241242if ($application->isPrototype()) {243$prototype_tag = id(new PHUITagView())244->setName(pht('Prototype'))245->setIcon('fa-exclamation-circle')246->setColor(PHUITagView::COLOR_ORANGE)247->setType(PHUITagView::TYPE_SHADE)248->setSlimShady(true);249$item->addAttribute($prototype_tag);250}251252$item->addAttribute($description);253254if ($application->getBaseURI() && $application->isInstalled()) {255$item->setHref($application->getBaseURI());256}257258if (!$application->isInstalled()) {259$item->addAttribute(pht('Uninstalled'));260$item->setDisabled(true);261}262263$list->addItem($item);264}265266$results[] = $list;267}268269$result = new PhabricatorApplicationSearchResultView();270$result->setContent($results);271272return $result;273}274275}276277278