Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F93283686
PhabricatorC4sHomeFeed.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
Wed, Nov 27, 14:53
Size
3 KB
Mime Type
text/x-php
Expires
Fri, Nov 29, 14:53 (1 d, 21 h)
Engine
blob
Format
Raw Data
Handle
22607611
Attached To
rPH Phabricator
PhabricatorC4sHomeFeed.php
View Options
<?php
final
class
PhabricatorC4sHomeFeed
extends
PhabricatorController
{
public
function
shouldAllowPublic
()
{
return
true
;
}
public
function
handleRequest
(
AphrontRequest
$request
)
{
require_celerity_resource
(
'phabricator-dashboard-css'
);
$content
=
$this
->
getFeedContent
(
$request
);
return
id
(
new
AphrontAjaxResponse
())
->
setContent
(
array
(
'panelMarkup'
=>
hsprintf
(
'%s'
,
$content
),
));
}
private
function
getFeedContent
(
$request
)
{
// hack to have global in the request
$global
=
$request
->
getBool
(
'dashboardID'
,
true
);
$viewer
=
$this
->
getViewer
();
$limit
=
$global
?
30
:
12
;
$phids
=
array
();
$epoch_min
=
time
()
-
7
*
24
*
3600
;
// 7 days
$epoch_max
=
time
();
if
(!
$global
)
{
//User
$phids
+=
array
(
$viewer
->
getPHID
());
// Projects
$projects
=
id
(
new
PhabricatorProjectQuery
())
->
setViewer
(
$viewer
)
->
withMemberPHIDs
(
array
(
$viewer
->
getPHID
()))
->
execute
();
$project_phids
=
mpull
(
$projects
,
'getPHID'
);
$phids
+=
array_fuse
(
$project_phids
);
// Repositories (created by user)
$repo_transaction
=
id
(
new
PhabricatorRepositoryTransactionQuery
())
->
setViewer
(
$viewer
)
->
withAuthorPHIDs
(
array
(
$viewer
->
getPHID
()))
->
withTransactionTypes
(
array
(
PhabricatorTransactions
::
TYPE_CREATE
))
->
needComments
(
false
)
->
needHandles
(
false
)
->
execute
();
$repo
=
array_fuse
(
mpull
(
$repo_transaction
,
'getObjectPHID'
));
// Repositories (in project user is member of)
if
(!
empty
(
$projects
))
{
$any
=
array
();
foreach
(
$project_phids
as
$phid
)
{
$any
[]
=
'any('
.
$phid
.
')'
;
}
$datasource
=
id
(
new
PhabricatorProjectLogicalDatasource
())
->
setViewer
(
$viewer
);
$constraints
=
$datasource
->
evaluateTokens
(
$any
);
$query
=
id
(
new
PhabricatorRepositoryQuery
())
->
setViewer
(
$viewer
)
->
withEdgeLogicConstraints
(
PhabricatorProjectObjectHasProjectEdgeType
::
EDGECONST
,
$constraints
)
->
execute
();
$repo
+=
array_fuse
(
mpull
(
$query
,
'getPHID'
));
}
// Commits for selected Repositories
if
(!
empty
(
$repo
))
{
$commits
=
id
(
new
DiffusionCommitQuery
())
->
setViewer
(
$viewer
)
->
withRepositoryPHIDs
(
$repo
)
->
withEpochRange
(
$epoch_min
,
$epoch_max
)
->
execute
();
$phids
+=
array_fuse
(
mpull
(
$commits
,
'getPHID'
));
}
// Phriction pages
if
(!
empty
(
$projects
))
{
$slugs
=
array
();
foreach
(
$projects
as
$p
)
{
$slugs
[]
=
PhabricatorProjectWikiCreate
::
getAllSlugs
(
$p
);
}
$wiki
=
id
(
new
PhrictionDocumentQuery
())
->
setViewer
(
$viewer
)
->
withSlugsPrefix
(
$slugs
)
->
withStatuses
(
array
(
PhrictionDocumentStatus
::
STATUS_EXISTS
))
->
execute
();
$phids
+=
array_fuse
(
mpull
(
$wiki
,
'getPHID'
));
}
}
// Build Feed stories
$stories
=
id
(
new
PhabricatorFeedQuery
())
->
setViewer
(
$viewer
)
->
withFilterPHIDs
(
$phids
)
->
withEpochInRange
(
$epoch_min
,
$epoch_max
)
->
setLimit
(
$limit
)
->
execute
();
$view
=
id
(
new
PhabricatorFeedBuilder
(
$stories
))
->
setUser
(
$viewer
)
->
buildView
();
return
$view
;
}
}
Event Timeline
Log In to Comment