Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F83161965
DiffusionTaggedRepositoriesFunctionDatasource.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
Sun, Sep 15, 12:52
Size
3 KB
Mime Type
text/x-php
Expires
Tue, Sep 17, 12:52 (1 d, 23 h)
Engine
blob
Format
Raw Data
Handle
20791190
Attached To
rPH Phabricator
DiffusionTaggedRepositoriesFunctionDatasource.php
View Options
<?php
final
class
DiffusionTaggedRepositoriesFunctionDatasource
extends
PhabricatorTypeaheadCompositeDatasource
{
public
function
getBrowseTitle
()
{
return
pht
(
'Browse Repositories'
);
}
public
function
getPlaceholderText
()
{
return
pht
(
'Type tagged(<project>)...'
);
}
public
function
getDatasourceApplicationClass
()
{
return
'PhabricatorProjectApplication'
;
}
public
function
getComponentDatasources
()
{
return
array
(
new
PhabricatorProjectDatasource
(),
);
}
public
function
getDatasourceFunctions
()
{
return
array
(
'tagged'
=>
array
(
'name'
=>
pht
(
'Repositories: ...'
),
'arguments'
=>
pht
(
'project'
),
'summary'
=>
pht
(
'Find results for repositories of a project.'
),
'description'
=>
pht
(
'This function allows you to find results for any of the `.
`repositories of a project:'
.
"
\n\n
"
.
'> tagged(engineering)'
),
),
);
}
protected
function
didLoadResults
(
array
$results
)
{
foreach
(
$results
as
$result
)
{
$result
->
setTokenType
(
PhabricatorTypeaheadTokenView
::
TYPE_FUNCTION
)
->
setColor
(
null
)
->
setPHID
(
'tagged('
.
$result
->
getPHID
().
')'
)
->
setDisplayName
(
pht
(
'Tagged: %s'
,
$result
->
getDisplayName
()))
->
setName
(
'tagged '
.
$result
->
getName
())
->
resetAttributes
()
->
addAttribute
(
pht
(
'Function'
))
->
addAttribute
(
pht
(
'Select repositories tagged with this project.'
));
}
return
$results
;
}
protected
function
evaluateFunction
(
$function
,
array
$argv_list
)
{
$phids
=
array
();
foreach
(
$argv_list
as
$argv
)
{
$phids
[]
=
head
(
$argv
);
}
$repositories
=
id
(
new
PhabricatorRepositoryQuery
())
->
setViewer
(
$this
->
getViewer
())
->
withEdgeLogicPHIDs
(
PhabricatorProjectObjectHasProjectEdgeType
::
EDGECONST
,
PhabricatorQueryConstraint
::
OPERATOR_OR
,
$phids
)
->
execute
();
$results
=
array
();
foreach
(
$repositories
as
$repository
)
{
$results
[]
=
$repository
->
getPHID
();
}
if
(!
$results
)
{
// TODO: This is a little hacky, but if you query for "tagged(x)" and
// there are no such repositories, we want to match nothing. If we
// just return `array()`, that gets evaluated as "no constraint" and
// we match everything. This works correctly for now, but should be
// replaced with some more elegant/general approach eventually.
$results
[]
=
PhabricatorPHIDConstants
::
PHID_VOID
;
}
return
$results
;
}
public
function
renderFunctionTokens
(
$function
,
array
$argv_list
)
{
$phids
=
array
();
foreach
(
$argv_list
as
$argv
)
{
$phids
[]
=
head
(
$argv
);
}
$tokens
=
$this
->
renderTokens
(
$phids
);
foreach
(
$tokens
as
$token
)
{
// Remove any project color on this token.
$token
->
setColor
(
null
);
if
(
$token
->
isInvalid
())
{
$token
->
setValue
(
pht
(
'Repositories: Invalid Project'
));
}
else
{
$token
->
setTokenType
(
PhabricatorTypeaheadTokenView
::
TYPE_FUNCTION
)
->
setKey
(
'tagged('
.
$token
->
getKey
().
')'
)
->
setValue
(
pht
(
'Tagged: %s'
,
$token
->
getValue
()));
}
}
return
$tokens
;
}
}
Event Timeline
Log In to Comment