Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F77551209
AlmanacServiceSearchEngine.php
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Subscribers
None
File Metadata
Details
File Info
Storage
Attached
Created
Thu, Aug 15, 03:24
Size
3 KB
Mime Type
text/x-php
Expires
Sat, Aug 17, 03:24 (2 d)
Engine
blob
Format
Raw Data
Handle
19882239
Attached To
rPH Phabricator
AlmanacServiceSearchEngine.php
View Options
<?php
final
class
AlmanacServiceSearchEngine
extends
PhabricatorApplicationSearchEngine
{
public
function
getResultTypeDescription
()
{
return
pht
(
'Almanac Services'
);
}
public
function
getApplicationClassName
()
{
return
'PhabricatorAlmanacApplication'
;
}
public
function
newQuery
()
{
return
new
AlmanacServiceQuery
();
}
public
function
newResultObject
()
{
return
new
AlmanacService
();
}
protected
function
buildQueryFromParameters
(
array
$map
)
{
$query
=
$this
->
newQuery
();
if
(
$map
[
'match'
]
!==
null
)
{
$query
->
withNameNgrams
(
$map
[
'match'
]);
}
if
(
$map
[
'names'
])
{
$query
->
withNames
(
$map
[
'names'
]);
}
if
(
$map
[
'devicePHIDs'
])
{
$query
->
withDevicePHIDs
(
$map
[
'devicePHIDs'
]);
}
if
(
$map
[
'serviceTypes'
])
{
$query
->
withServiceTypes
(
$map
[
'serviceTypes'
]);
}
return
$query
;
}
protected
function
buildCustomSearchFields
()
{
return
array
(
id
(
new
PhabricatorSearchTextField
())
->
setLabel
(
pht
(
'Name Contains'
))
->
setKey
(
'match'
)
->
setDescription
(
pht
(
'Search for services by name substring.'
)),
id
(
new
PhabricatorSearchStringListField
())
->
setLabel
(
pht
(
'Exact Names'
))
->
setKey
(
'names'
)
->
setDescription
(
pht
(
'Search for services with specific names.'
)),
id
(
new
PhabricatorSearchDatasourceField
())
->
setLabel
(
pht
(
'Service Types'
))
->
setKey
(
'serviceTypes'
)
->
setDescription
(
pht
(
'Find services by type.'
))
->
setDatasource
(
id
(
new
AlmanacServiceTypeDatasource
())),
id
(
new
PhabricatorPHIDsSearchField
())
->
setLabel
(
pht
(
'Devices'
))
->
setKey
(
'devicePHIDs'
)
->
setDescription
(
pht
(
'Search for services bound to particular devices.'
)),
);
}
protected
function
getURI
(
$path
)
{
return
'/almanac/service/'
.
$path
;
}
protected
function
getBuiltinQueryNames
()
{
$names
=
array
(
'all'
=>
pht
(
'All Services'
),
);
return
$names
;
}
public
function
buildSavedQueryFromBuiltin
(
$query_key
)
{
$query
=
$this
->
newSavedQuery
();
$query
->
setQueryKey
(
$query_key
);
switch
(
$query_key
)
{
case
'all'
:
return
$query
;
}
return
parent
::
buildSavedQueryFromBuiltin
(
$query_key
);
}
protected
function
renderResultList
(
array
$services
,
PhabricatorSavedQuery
$query
,
array
$handles
)
{
assert_instances_of
(
$services
,
'AlmanacService'
);
$viewer
=
$this
->
requireViewer
();
$list
=
new
PHUIObjectItemListView
();
$list
->
setUser
(
$viewer
);
foreach
(
$services
as
$service
)
{
$item
=
id
(
new
PHUIObjectItemView
())
->
setObjectName
(
pht
(
'Service %d'
,
$service
->
getID
()))
->
setHeader
(
$service
->
getName
())
->
setHref
(
$service
->
getURI
())
->
setObject
(
$service
)
->
addIcon
(
$service
->
getServiceImplementation
()->
getServiceTypeIcon
(),
$service
->
getServiceImplementation
()->
getServiceTypeShortName
());
$list
->
addItem
(
$item
);
}
$result
=
new
PhabricatorApplicationSearchResultView
();
$result
->
setObjectList
(
$list
);
$result
->
setNoDataString
(
pht
(
'No Almanac Services found.'
));
return
$result
;
}
}
Event Timeline
Log In to Comment