Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F90460856
PholioMockSearchEngine.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
Fri, Nov 1, 21:29
Size
3 KB
Mime Type
text/x-php
Expires
Sun, Nov 3, 21:29 (1 d, 23 h)
Engine
blob
Format
Raw Data
Handle
22075520
Attached To
rPH Phabricator
PholioMockSearchEngine.php
View Options
<?php
final
class
PholioMockSearchEngine
extends
PhabricatorApplicationSearchEngine
{
public
function
getResultTypeDescription
()
{
return
pht
(
'Pholio Mocks'
);
}
public
function
getApplicationClassName
()
{
return
'PhabricatorPholioApplication'
;
}
public
function
newQuery
()
{
return
id
(
new
PholioMockQuery
())
->
needCoverFiles
(
true
)
->
needImages
(
true
)
->
needTokenCounts
(
true
);
}
protected
function
buildCustomSearchFields
()
{
return
array
(
id
(
new
PhabricatorUsersSearchField
())
->
setKey
(
'authorPHIDs'
)
->
setAliases
(
array
(
'authors'
))
->
setLabel
(
pht
(
'Authors'
)),
id
(
new
PhabricatorSearchCheckboxesField
())
->
setKey
(
'statuses'
)
->
setLabel
(
pht
(
'Status'
))
->
setOptions
(
id
(
new
PholioMock
())
->
getStatuses
()),
);
}
protected
function
buildQueryFromParameters
(
array
$map
)
{
$query
=
$this
->
newQuery
();
if
(
$map
[
'authorPHIDs'
])
{
$query
->
withAuthorPHIDs
(
$map
[
'authorPHIDs'
]);
}
if
(
$map
[
'statuses'
])
{
$query
->
withStatuses
(
$map
[
'statuses'
]);
}
return
$query
;
}
protected
function
getURI
(
$path
)
{
return
'/pholio/'
.
$path
;
}
protected
function
getBuiltinQueryNames
()
{
$names
=
array
(
'open'
=>
pht
(
'Open Mocks'
),
'all'
=>
pht
(
'All Mocks'
),
);
if
(
$this
->
requireViewer
()->
isLoggedIn
())
{
$names
[
'authored'
]
=
pht
(
'Authored'
);
}
return
$names
;
}
public
function
buildSavedQueryFromBuiltin
(
$query_key
)
{
$query
=
$this
->
newSavedQuery
();
$query
->
setQueryKey
(
$query_key
);
switch
(
$query_key
)
{
case
'open'
:
return
$query
->
setParameter
(
'statuses'
,
array
(
'open'
));
case
'all'
:
return
$query
;
case
'authored'
:
return
$query
->
setParameter
(
'authorPHIDs'
,
array
(
$this
->
requireViewer
()->
getPHID
()));
}
return
parent
::
buildSavedQueryFromBuiltin
(
$query_key
);
}
protected
function
renderResultList
(
array
$mocks
,
PhabricatorSavedQuery
$query
,
array
$handles
)
{
assert_instances_of
(
$mocks
,
'PholioMock'
);
$viewer
=
$this
->
requireViewer
();
$handles
=
$viewer
->
loadHandles
(
mpull
(
$mocks
,
'getAuthorPHID'
));
$xform
=
PhabricatorFileTransform
::
getTransformByKey
(
PhabricatorFileThumbnailTransform
::
TRANSFORM_PINBOARD
);
$board
=
new
PHUIPinboardView
();
foreach
(
$mocks
as
$mock
)
{
$image
=
$mock
->
getCoverFile
();
$image_uri
=
$image
->
getURIForTransform
(
$xform
);
list
(
$x
,
$y
)
=
$xform
->
getTransformedDimensions
(
$image
);
$header
=
'M'
.
$mock
->
getID
().
' '
.
$mock
->
getName
();
$item
=
id
(
new
PHUIPinboardItemView
())
->
setUser
(
$viewer
)
->
setHeader
(
$header
)
->
setObject
(
$mock
)
->
setURI
(
'/M'
.
$mock
->
getID
())
->
setImageURI
(
$image_uri
)
->
setImageSize
(
$x
,
$y
)
->
setDisabled
(
$mock
->
isClosed
())
->
addIconCount
(
'fa-picture-o'
,
count
(
$mock
->
getImages
()))
->
addIconCount
(
'fa-trophy'
,
$mock
->
getTokenCount
());
if
(
$mock
->
getAuthorPHID
())
{
$author_handle
=
$handles
[
$mock
->
getAuthorPHID
()];
$datetime
=
phabricator_date
(
$mock
->
getDateCreated
(),
$viewer
);
$item
->
appendChild
(
pht
(
'By %s on %s'
,
$author_handle
->
renderLink
(),
$datetime
));
}
$board
->
addItem
(
$item
);
}
$result
=
new
PhabricatorApplicationSearchResultView
();
$result
->
setContent
(
$board
);
return
$result
;
}
}
Event Timeline
Log In to Comment