2015-12-11 08:45:56 -08:00
|
|
|
<?php
|
|
|
|
|
|
|
|
final class PhabricatorSpacesSearchEngineExtension
|
|
|
|
extends PhabricatorSearchEngineExtension {
|
|
|
|
|
|
|
|
const EXTENSIONKEY = 'spaces';
|
|
|
|
|
|
|
|
public function isExtensionEnabled() {
|
|
|
|
return PhabricatorApplication::isClassInstalled(
|
|
|
|
'PhabricatorSpacesApplication');
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getExtensionName() {
|
|
|
|
return pht('Support for Spaces');
|
|
|
|
}
|
|
|
|
|
2015-12-13 04:12:34 -08:00
|
|
|
public function getExtensionOrder() {
|
2015-12-13 08:45:01 -08:00
|
|
|
return 4000;
|
2015-12-13 04:12:34 -08:00
|
|
|
}
|
|
|
|
|
2015-12-11 08:45:56 -08:00
|
|
|
public function supportsObject($object) {
|
|
|
|
return ($object instanceof PhabricatorSpacesInterface);
|
|
|
|
}
|
|
|
|
|
2015-12-13 04:12:34 -08:00
|
|
|
public function getSearchFields($object) {
|
|
|
|
$fields = array();
|
|
|
|
|
|
|
|
if (PhabricatorSpacesNamespaceQuery::getSpacesExist()) {
|
|
|
|
$fields[] = id(new PhabricatorSpacesSearchField())
|
|
|
|
->setKey('spacePHIDs')
|
|
|
|
->setConduitKey('spaces')
|
|
|
|
->setAliases(array('space', 'spaces'))
|
2015-12-13 06:52:37 -08:00
|
|
|
->setLabel(pht('Spaces'))
|
|
|
|
->setDescription(
|
|
|
|
pht('Search for objects in certain spaces.'));
|
2015-12-13 04:12:34 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
return $fields;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function applyConstraintsToQuery(
|
|
|
|
$object,
|
|
|
|
$query,
|
|
|
|
PhabricatorSavedQuery $saved,
|
|
|
|
array $map) {
|
|
|
|
|
|
|
|
if (!empty($map['spacePHIDs'])) {
|
|
|
|
$query->withSpacePHIDs($map['spacePHIDs']);
|
|
|
|
} else {
|
|
|
|
// If the user doesn't search for objects in specific spaces, we
|
|
|
|
// default to "all active spaces you have permission to view".
|
|
|
|
$query->withSpaceIsArchived(false);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-12-11 08:45:56 -08:00
|
|
|
public function getFieldSpecificationsForConduit($object) {
|
|
|
|
return array(
|
|
|
|
'spacePHID' => array(
|
|
|
|
'type' => 'phid?',
|
|
|
|
'description' => pht(
|
|
|
|
'PHID of the policy space this object is part of.'),
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getFieldValuesForConduit($object) {
|
|
|
|
return array(
|
|
|
|
'spacePHID' => $object->getSpacePHID(),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|