3 final class PhabricatorPhurlURLSearchEngine
4 extends PhabricatorApplicationSearchEngine
{
6 public function getResultTypeDescription() {
7 return pht('Phurl URLs');
10 public function getApplicationClassName() {
11 return 'PhabricatorPhurlApplication';
14 public function newQuery() {
15 return new PhabricatorPhurlURLQuery();
18 protected function shouldShowOrderField() {
22 protected function buildCustomSearchFields() {
24 id(new PhabricatorSearchDatasourceField())
25 ->setLabel(pht('Created By'))
26 ->setKey('authorPHIDs')
27 ->setDatasource(new PhabricatorPeopleUserFunctionDatasource()),
28 id(new PhabricatorSearchTextField())
29 ->setLabel(pht('Name Contains'))
31 ->setDescription(pht('Search for Phurl URLs by name substring.')),
32 id(new PhabricatorSearchStringListField())
33 ->setLabel(pht('Aliases'))
35 ->setDescription(pht('Search for Phurl URLs by alias.')),
36 id(new PhabricatorSearchStringListField())
37 ->setLabel(pht('Long URLs'))
40 pht('Search for Phurl URLs by the non-shortened URL.')),
44 protected function buildQueryFromParameters(array $map) {
45 $query = $this->newQuery();
47 if ($map['authorPHIDs']) {
48 $query->withAuthorPHIDs($map['authorPHIDs']);
51 if ($map['name'] !== null) {
52 $query->withNameNgrams($map['name']);
55 if ($map['aliases']) {
56 $query->withAliases($map['aliases']);
59 if ($map['longurls']) {
60 $query->withLongURLs($map['longurls']);
66 protected function getURI($path) {
67 return '/phurl/'.$path;
70 protected function getBuiltinQueryNames() {
72 'all' => pht('All URLs'),
73 'authored' => pht('Authored'),
79 public function buildSavedQueryFromBuiltin($query_key) {
80 $query = $this->newSavedQuery();
81 $query->setQueryKey($query_key);
82 $viewer = $this->requireViewer();
86 return $query->setParameter('authorPHIDs', array($viewer->getPHID()));
91 return parent
::buildSavedQueryFromBuiltin($query_key);
94 protected function renderResultList(
96 PhabricatorSavedQuery
$query,
99 assert_instances_of($urls, 'PhabricatorPhurlURL');
100 $viewer = $this->requireViewer();
101 $list = new PHUIObjectItemListView();
102 $handles = $viewer->loadHandles(mpull($urls, 'getAuthorPHID'));
104 foreach ($urls as $url) {
105 $name = $url->getName();
107 $item = id(new PHUIObjectItemView())
110 ->setObjectName('U'.$url->getID())
112 ->setHref('/U'.$url->getID())
113 ->addAttribute($url->getAlias())
114 ->addAttribute($url->getLongURL());
116 $list->addItem($item);
119 $result = new PhabricatorApplicationSearchResultView();
120 $result->setObjectList($list);
121 $result->setNoDataString(pht('No URLs found.'));
126 protected function getNewUserBody() {
127 $create_uri = id(new PhabricatorPhurlURLEditEngine())
130 $create_button = id(new PHUIButtonView())
132 ->setText(pht('Shorten a URL'))
133 ->setHref($create_uri)
134 ->setColor(PHUIButtonView
::GREEN
);
136 $icon = $this->getApplication()->getIcon();
137 $app_name = $this->getApplication()->getName();
138 $view = id(new PHUIBigInfoView())
140 ->setTitle(pht('Welcome to %s', $app_name))
142 pht('Create reusable, memorable, shorter URLs for easy accessibility.'))
143 ->addAction($create_button);