Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F97215222
PhabricatorProjectProfileController.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, Jan 3, 12:50
Size
14 KB
Mime Type
text/x-php
Expires
Sun, Jan 5, 12:50 (2 d)
Engine
blob
Format
Raw Data
Handle
23356390
Attached To
rPH Phabricator
PhabricatorProjectProfileController.php
View Options
<?php
final
class
PhabricatorProjectProfileController
extends
PhabricatorProjectController
{
public
function
shouldAllowPublic
()
{
return
true
;
}
public
function
handleRequest
(
AphrontRequest
$request
)
{
$response
=
$this
->
loadProject
();
if
(
$response
)
{
return
$response
;
}
$viewer
=
$request
->
getUser
();
$project
=
$this
->
getProject
();
$id
=
$project
->
getID
();
$picture
=
$project
->
getProfileImageURI
();
$icon
=
$project
->
getDisplayIconIcon
();
$icon_name
=
$project
->
getDisplayIconName
();
$tag
=
id
(
new
PHUITagView
())
->
setIcon
(
$icon
)
->
setName
(
$icon_name
)
->
addClass
(
'project-view-header-tag'
)
->
setType
(
PHUITagView
::
TYPE_SHADE
);
$header
=
id
(
new
PHUIHeaderView
())
->
setHeader
(
array
(
$project
->
getDisplayName
(),
$tag
))
->
setUser
(
$viewer
)
->
setPolicyObject
(
$project
)
->
setProfileHeader
(
true
);
if
(
$project
->
getStatus
()
==
PhabricatorProjectStatus
::
STATUS_ACTIVE
)
{
$header
->
setStatus
(
'fa-check'
,
'bluegrey'
,
pht
(
'Active'
));
}
else
{
$header
->
setStatus
(
'fa-ban'
,
'red'
,
pht
(
'Archived'
));
}
$can_edit
=
PhabricatorPolicyFilter
::
hasCapability
(
$viewer
,
$project
,
PhabricatorPolicyCapability
::
CAN_EDIT
);
if
(
$can_edit
)
{
$header
->
setImageEditURL
(
$this
->
getApplicationURI
(
"picture/{$id}/"
));
}
$properties
=
$this
->
buildPropertyListView
(
$project
);
$watch_action
=
$this
->
renderWatchAction
(
$project
);
$header
->
addActionLink
(
$watch_action
);
// c4science custo
// Create and list Phriction pages, repositories and
// Jenkins Job linked to this project
$wiki_action
=
$this
->
renderWikiAction
(
$project
);
$header
->
addActionLink
(
$wiki_action
);
$have_jenkins
=
PhabricatorApplication
::
isClassInstalledForViewer
(
'PhabricatorJenkinsJobApplication'
,
$viewer
);
if
(
$can_edit
&&
$have_jenkins
){
$job_action
=
$this
->
renderJobAction
(
$project
);
$header
->
addActionLink
(
$job_action
);
}
$repo_list
=
$this
->
buildRepoList
(
$project
);
$jobs_list
=
$this
->
buildJobsList
(
$project
);
$wiki_list
=
$this
->
buildWikiList
(
$project
);
// end of c4science custo
$milestone_list
=
$this
->
buildMilestoneList
(
$project
);
$subproject_list
=
$this
->
buildSubprojectList
(
$project
);
$member_list
=
id
(
new
PhabricatorProjectMemberListView
())
->
setUser
(
$viewer
)
->
setProject
(
$project
)
->
setLimit
(
5
)
->
setBackground
(
PHUIObjectBoxView
::
BLUE_PROPERTY
)
->
setUserPHIDs
(
$project
->
getMemberPHIDs
());
// c4science custo
// $watcher_list = id(new PhabricatorProjectWatcherListView())
// ->setUser($viewer)
// ->setProject($project)
// ->setLimit(5)
// ->setBackground(PHUIObjectBoxView::BLUE_PROPERTY)
// ->setUserPHIDs($project->getWatcherPHIDs());
$nav
=
$this
->
getProfileMenu
();
$nav
->
selectFilter
(
PhabricatorProject
::
ITEM_PROFILE
);
$stories
=
id
(
new
PhabricatorFeedQuery
())
->
setViewer
(
$viewer
)
->
withFilterPHIDs
(
array
(
$project
->
getPHID
(),
))
->
setLimit
(
50
)
->
execute
();
$view_all
=
id
(
new
PHUIButtonView
())
->
setTag
(
'a'
)
->
setIcon
(
id
(
new
PHUIIconView
())
->
setIcon
(
'fa-list-ul'
))
->
setText
(
pht
(
'View All'
))
->
setHref
(
'/feed/?projectPHIDs='
.
$project
->
getPHID
());
$feed_header
=
id
(
new
PHUIHeaderView
())
->
setHeader
(
pht
(
'Recent Activity'
))
->
addActionLink
(
$view_all
);
$feed
=
$this
->
renderStories
(
$stories
);
$feed
=
id
(
new
PHUIObjectBoxView
())
->
setHeader
(
$feed_header
)
->
addClass
(
'project-view-feed'
)
->
appendChild
(
$feed
);
require_celerity_resource
(
'project-view-css'
);
$home
=
id
(
new
PHUITwoColumnView
())
->
setHeader
(
$header
)
->
addClass
(
'project-view-home'
)
->
addClass
(
'project-view-people-home'
)
->
setMainColumn
(
array
(
$properties
,
$feed
,
))
->
setSideColumn
(
array
(
$repo_list
,
// c4s custo
$jobs_list
,
// c4s custo
$wiki_list
,
// c4s custo
$milestone_list
,
$subproject_list
,
$member_list
,
// $watcher_list, // c4s custo
));
$crumbs
=
$this
->
buildApplicationCrumbs
();
$crumbs
->
setBorder
(
true
);
return
$this
->
newPage
()
->
setNavigation
(
$nav
)
->
setCrumbs
(
$crumbs
)
->
setTitle
(
$project
->
getDisplayName
())
->
setPageObjectPHIDs
(
array
(
$project
->
getPHID
()))
->
appendChild
(
$home
);
}
private
function
buildPropertyListView
(
PhabricatorProject
$project
)
{
$request
=
$this
->
getRequest
();
$viewer
=
$request
->
getUser
();
$view
=
id
(
new
PHUIPropertyListView
())
->
setUser
(
$viewer
)
->
setObject
(
$project
);
$field_list
=
PhabricatorCustomField
::
getObjectFields
(
$project
,
PhabricatorCustomField
::
ROLE_VIEW
);
$field_list
->
appendFieldsToPropertyList
(
$project
,
$viewer
,
$view
);
if
(!
$view
->
hasAnyProperties
())
{
return
null
;
}
$header
=
id
(
new
PHUIHeaderView
())
->
setHeader
(
pht
(
'Details'
));
$view
=
id
(
new
PHUIObjectBoxView
())
->
setHeader
(
$header
)
->
appendChild
(
$view
)
->
setBackground
(
PHUIObjectBoxView
::
BLUE_PROPERTY
)
->
addClass
(
'project-view-properties'
);
return
$view
;
}
private
function
renderStories
(
array
$stories
)
{
assert_instances_of
(
$stories
,
'PhabricatorFeedStory'
);
$builder
=
new
PhabricatorFeedBuilder
(
$stories
);
$builder
->
setUser
(
$this
->
getRequest
()->
getUser
());
$builder
->
setShowHovercards
(
true
);
$view
=
$builder
->
buildView
();
return
$view
;
}
private
function
renderWatchAction
(
PhabricatorProject
$project
)
{
$viewer
=
$this
->
getViewer
();
$id
=
$project
->
getID
();
if
(!
$viewer
->
isLoggedIn
())
{
$is_watcher
=
false
;
$is_ancestor
=
false
;
}
else
{
$viewer_phid
=
$viewer
->
getPHID
();
$is_watcher
=
$project
->
isUserWatcher
(
$viewer_phid
);
$is_ancestor
=
$project
->
isUserAncestorWatcher
(
$viewer_phid
);
}
if
(
$is_ancestor
&&
!
$is_watcher
)
{
$watch_icon
=
'fa-eye'
;
$watch_text
=
pht
(
'Watching Ancestor'
);
$watch_href
=
"/project/watch/{$id}/?via=profile"
;
$watch_disabled
=
true
;
}
else
if
(!
$is_watcher
)
{
$watch_icon
=
'fa-eye'
;
$watch_text
=
pht
(
'Watch Project'
);
$watch_href
=
"/project/watch/{$id}/?via=profile"
;
$watch_disabled
=
false
;
}
else
{
$watch_icon
=
'fa-eye-slash'
;
$watch_text
=
pht
(
'Unwatch Project'
);
$watch_href
=
"/project/unwatch/{$id}/?via=profile"
;
$watch_disabled
=
false
;
}
$watch_icon
=
id
(
new
PHUIIconView
())
->
setIcon
(
$watch_icon
);
return
id
(
new
PHUIButtonView
())
->
setTag
(
'a'
)
->
setWorkflow
(
true
)
->
setIcon
(
$watch_icon
)
->
setText
(
$watch_text
)
->
setHref
(
$watch_href
)
->
setDisabled
(
$watch_disabled
);
}
// c4science custo
private
function
renderWikiAction
(
PhabricatorProject
$project
)
{
$id
=
$project
->
getID
();
$wiki_icon
=
id
(
new
PHUIIconView
())->
setIcon
(
'fa-book'
);
$wiki_text
=
pht
(
'Create wiki page'
);
$wiki_href
=
"/project/wiki/create/{$id}/?via=profile"
;
return
id
(
new
PHUIButtonView
())
->
setTag
(
'a'
)
->
setWorkflow
(
true
)
->
setIcon
(
$wiki_icon
)
->
setText
(
$wiki_text
)
->
setHref
(
$wiki_href
);
}
// c4science custo
private
function
renderJobAction
(
PhabricatorProject
$project
)
{
$phid
=
$project
->
getPHID
();
$job_icon
=
id
(
new
PHUIIconView
())->
setIcon
(
'fa-tasks'
);
$job_text
=
pht
(
'Create Jenkins Job'
);
$job_href
=
"/jobs/create/?with_project={$phid}"
;
return
id
(
new
PHUIButtonView
())
->
setTag
(
'a'
)
->
setWorkflow
(
true
)
->
setIcon
(
$job_icon
)
->
setText
(
$job_text
)
->
setHref
(
$job_href
);
}
// c4science custo
private
function
getHasWiki
(
PhabricatorProject
$project
)
{
$viewer
=
$this
->
getViewer
();
$slug
=
PhabricatorProjectWikiCreate
::
getAllSlugs
(
$project
);
return
id
(
new
PhrictionDocumentQuery
())
->
setViewer
(
$viewer
)
->
withStatus
(
PhrictionDocumentQuery
::
STATUS_OPEN
)
->
withSlugPrefix
(
$slug
)
->
setLimit
(
1
)
->
execute
();
}
// c4science custo
private
function
buildWikiList
(
PhabricatorProject
$project
)
{
if
(!
$this
->
getHasWiki
(
$project
))
{
return
null
;
}
$viewer
=
$this
->
getViewer
();
$id
=
$project
->
getID
();
$slug
=
PhabricatorProjectWikiCreate
::
getAllSlugs
(
$project
);
$query
=
id
(
new
PhrictionDocumentQuery
())
->
setViewer
(
$viewer
)
->
needContent
(
true
)
->
withStatus
(
PhrictionDocumentQuery
::
STATUS_OPEN
)
->
withSlugPrefix
(
$slug
)
->
setLimit
(
5
)
->
execute
();
$wiki_list
=
new
PHUIObjectItemListView
();
foreach
(
$query
as
$w
){
$wiki_list
->
addItem
(
id
(
new
PHUIObjectItemView
())
->
setHeader
(
$w
->
getContent
()->
getTitle
())
->
addAttribute
(
$w
->
getSlug
())
->
setHref
(
$w
->
getSlugURI
(
$w
->
getSlug
())));
}
$view_all
=
id
(
new
PHUIButtonView
())
->
setTag
(
'a'
)
->
setIcon
(
id
(
new
PHUIIconView
())
->
setIcon
(
'fa-list-ul'
))
->
setText
(
pht
(
'View All'
))
->
setHref
(
"/project/wiki/view/{$id}/"
);
$header
=
id
(
new
PHUIHeaderView
())
->
setHeader
(
pht
(
'Wiki pages'
))
->
addActionLink
(
$view_all
);
return
id
(
new
PHUIObjectBoxView
())
->
setHeader
(
$header
)
->
setBackground
(
PHUIObjectBoxView
::
BLUE_PROPERTY
)
->
setObjectList
(
$wiki_list
);
}
// c4science custo
private
function
buildJobsList
(
PhabricatorProject
$project
)
{
$viewer
=
$this
->
getViewer
();
$have_jenkins
=
PhabricatorApplication
::
isClassInstalledForViewer
(
'PhabricatorJenkinsJobApplication'
,
$viewer
);
if
(!
$have_jenkins
)
{
return
;
}
$query
=
id
(
new
PhabricatorJenkinsJobQuery
())
->
setViewer
(
$viewer
)
->
withProjects
(
array
(
$project
->
getPHID
()))
->
execute
();
if
(!
$query
)
{
return
null
;
}
$jobs_list
=
PhabricatorJenkinsJobController
::
createObjectList
(
$viewer
,
$project
->
getPHID
(),
null
);
$header
=
id
(
new
PHUIHeaderView
())
->
setHeader
(
pht
(
'Jobs'
));
return
id
(
new
PHUIObjectBoxView
())
->
setHeader
(
$header
)
->
setBackground
(
PHUIObjectBoxView
::
BLUE_PROPERTY
)
->
setObjectList
(
$jobs_list
);
}
// c4science custo
private
function
buildRepoList
(
PhabricatorProject
$project
)
{
$viewer
=
$this
->
getViewer
();
$datasource
=
id
(
new
PhabricatorProjectLogicalDatasource
())
->
setViewer
(
$viewer
);
$constraints
=
$datasource
->
evaluateTokens
(
array
(
$project
->
getPHID
()));
$query
=
id
(
new
PhabricatorRepositoryQuery
())
->
setViewer
(
$viewer
)
->
needProjectPHIDs
(
true
)
->
withStatus
(
PhabricatorRepositoryQuery
::
STATUS_OPEN
)
->
setOrder
(
'committed'
)
->
setLimit
(
5
)
->
withEdgeLogicConstraints
(
PhabricatorProjectObjectHasProjectEdgeType
::
EDGECONST
,
$constraints
)
->
execute
();
if
(!
$query
){
return
null
;
}
$repo_list
=
new
PHUIObjectItemListView
();
foreach
(
$query
as
$r
){
$repo_list
->
addItem
(
id
(
new
PHUIObjectItemView
())
->
setHeader
(
$r
->
getName
())
->
addAttribute
(
$r
->
getDisplayName
())
->
setHref
(
$r
->
getURI
())
);
}
$view_all
=
id
(
new
PHUIButtonView
())
->
setTag
(
'a'
)
->
setIcon
(
id
(
new
PHUIIconView
())
->
setIcon
(
'fa-list-ul'
))
->
setText
(
pht
(
'View All'
))
->
setHref
(
"/diffusion/?status=open&projectPHIDs="
.
$project
->
getPHID
()
.
'#R'
);
$header
=
id
(
new
PHUIHeaderView
())
->
setHeader
(
pht
(
'Repositories'
))
->
addActionLink
(
$view_all
);
return
id
(
new
PHUIObjectBoxView
())
->
setHeader
(
$header
)
->
setBackground
(
PHUIObjectBoxView
::
BLUE_PROPERTY
)
->
setObjectList
(
$repo_list
);
}
private
function
buildMilestoneList
(
PhabricatorProject
$project
)
{
if
(!
$project
->
getHasMilestones
())
{
return
null
;
}
$viewer
=
$this
->
getViewer
();
$id
=
$project
->
getID
();
$milestones
=
id
(
new
PhabricatorProjectQuery
())
->
setViewer
(
$viewer
)
->
withParentProjectPHIDs
(
array
(
$project
->
getPHID
()))
->
needImages
(
true
)
->
withIsMilestone
(
true
)
->
withStatuses
(
array
(
PhabricatorProjectStatus
::
STATUS_ACTIVE
,
))
->
setOrderVector
(
array
(
'milestoneNumber'
,
'id'
))
->
execute
();
if
(!
$milestones
)
{
return
null
;
}
$milestone_list
=
id
(
new
PhabricatorProjectListView
())
->
setUser
(
$viewer
)
->
setProjects
(
$milestones
)
->
renderList
();
$view_all
=
id
(
new
PHUIButtonView
())
->
setTag
(
'a'
)
->
setIcon
(
id
(
new
PHUIIconView
())
->
setIcon
(
'fa-list-ul'
))
->
setText
(
pht
(
'View All'
))
->
setHref
(
"/project/subprojects/{$id}/"
);
$header
=
id
(
new
PHUIHeaderView
())
->
setHeader
(
pht
(
'Milestones'
))
->
addActionLink
(
$view_all
);
return
id
(
new
PHUIObjectBoxView
())
->
setHeader
(
$header
)
->
setBackground
(
PHUIObjectBoxView
::
BLUE_PROPERTY
)
->
setObjectList
(
$milestone_list
);
}
private
function
buildSubprojectList
(
PhabricatorProject
$project
)
{
if
(!
$project
->
getHasSubprojects
())
{
return
null
;
}
$viewer
=
$this
->
getViewer
();
$id
=
$project
->
getID
();
$limit
=
25
;
$subprojects
=
id
(
new
PhabricatorProjectQuery
())
->
setViewer
(
$viewer
)
->
withParentProjectPHIDs
(
array
(
$project
->
getPHID
()))
->
needImages
(
true
)
->
withStatuses
(
array
(
PhabricatorProjectStatus
::
STATUS_ACTIVE
,
))
->
withIsMilestone
(
false
)
->
setLimit
(
$limit
)
->
execute
();
if
(!
$subprojects
)
{
return
null
;
}
$subproject_list
=
id
(
new
PhabricatorProjectListView
())
->
setUser
(
$viewer
)
->
setProjects
(
$subprojects
)
->
renderList
();
$view_all
=
id
(
new
PHUIButtonView
())
->
setTag
(
'a'
)
->
setIcon
(
id
(
new
PHUIIconView
())
->
setIcon
(
'fa-list-ul'
))
->
setText
(
pht
(
'View All'
))
->
setHref
(
"/project/subprojects/{$id}/"
);
$header
=
id
(
new
PHUIHeaderView
())
->
setHeader
(
pht
(
'Subprojects'
))
->
addActionLink
(
$view_all
);
return
id
(
new
PHUIObjectBoxView
())
->
setHeader
(
$header
)
->
setBackground
(
PHUIObjectBoxView
::
BLUE_PROPERTY
)
->
setObjectList
(
$subproject_list
);
}
}
Event Timeline
Log In to Comment