Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F72173591
PhabricatorProjectLogicalViewerDatasource.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
Mon, Jul 15, 03:20
Size
2 KB
Mime Type
text/x-php
Expires
Wed, Jul 17, 03:20 (1 d, 23 h)
Engine
blob
Format
Raw Data
Handle
19042329
Attached To
rPH Phabricator
PhabricatorProjectLogicalViewerDatasource.php
View Options
<?php
final
class
PhabricatorProjectLogicalViewerDatasource
extends
PhabricatorTypeaheadDatasource
{
public
function
getBrowseTitle
()
{
return
pht
(
'Browse Viewer Projects'
);
}
public
function
getPlaceholderText
()
{
return
pht
(
'Type viewerprojects()...'
);
}
public
function
getDatasourceApplicationClass
()
{
return
'PhabricatorProjectApplication'
;
}
public
function
getDatasourceFunctions
()
{
return
array
(
'viewerprojects'
=>
array
(
'name'
=>
pht
(
"Current Viewer's Projects"
),
'summary'
=>
pht
(
"Find results in any of the current viewer's projects."
),
'description'
=>
pht
(
"This function matches results in any of the current viewing "
.
"user's projects:"
.
"
\n\n
"
.
"> viewerprojects()"
.
"
\n\n
"
.
"This normally means //your// projects, but if you save a query "
.
"using this function and send it to someone else, it will mean "
.
"//their// projects when they run it (they become the currnet "
.
"viewer). This can be useful for building dashboard panels."
),
),
);
}
public
function
loadResults
()
{
if
(
$this
->
getViewer
()->
getPHID
())
{
$results
=
array
(
$this
->
renderViewerProjectsFunctionToken
());
}
else
{
$results
=
array
();
}
return
$this
->
filterResultsAgainstTokens
(
$results
);
}
protected
function
canEvaluateFunction
(
$function
)
{
if
(!
$this
->
getViewer
()->
getPHID
())
{
return
false
;
}
return
parent
::
canEvaluateFunction
(
$function
);
}
protected
function
evaluateFunction
(
$function
,
array
$argv_list
)
{
$viewer
=
$this
->
getViewer
();
$projects
=
id
(
new
PhabricatorProjectQuery
())
->
setViewer
(
$viewer
)
->
withMemberPHIDs
(
array
(
$viewer
->
getPHID
()))
->
execute
();
$phids
=
mpull
(
$projects
,
'getPHID'
);
$results
=
array
();
if
(
$phids
)
{
foreach
(
$phids
as
$phid
)
{
$results
[]
=
new
PhabricatorQueryConstraint
(
PhabricatorQueryConstraint
::
OPERATOR_OR
,
$phid
);
}
}
else
{
$results
[]
=
new
PhabricatorQueryConstraint
(
PhabricatorQueryConstraint
::
OPERATOR_EMPTY
,
null
);
}
return
$results
;
}
public
function
renderFunctionTokens
(
$function
,
array
$argv_list
)
{
$tokens
=
array
();
foreach
(
$argv_list
as
$argv
)
{
$tokens
[]
=
PhabricatorTypeaheadTokenView
::
newFromTypeaheadResult
(
$this
->
renderViewerProjectsFunctionToken
());
}
return
$tokens
;
}
private
function
renderViewerProjectsFunctionToken
()
{
return
$this
->
newFunctionResult
()
->
setName
(
pht
(
'Current Viewer
\'
s Projects'
))
->
setPHID
(
'viewerprojects()'
)
->
setIcon
(
'fa-asterisk'
)
->
setUnique
(
true
);
}
}
Event Timeline
Log In to Comment