Page Menu
Home
Phorge
Search
Configure Global Search
Log In
Files
F2991559
PhabricatorProjectLogicalViewerDatasource.php
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Award Token
Flag For Later
Advanced/Developer...
View Handle
View Hovercard
Size
2 KB
Referenced Files
None
Subscribers
None
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
::
class
;
}
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 current "
.
"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
)
->
addAttribute
(
pht
(
'Select projects current viewer is a member of.'
)
)
;
}
}
File Metadata
Details
Attached
Mime Type
text/x-php
Expires
Sun, Feb 23, 01:42 (1 d, 10 h ago)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
1180850
Default Alt Text
PhabricatorProjectLogicalViewerDatasource.php (2 KB)
Attached To
Mode
rP Phorge
Attached
Detach File
Event Timeline
Log In to Comment