2016-01-14 15:47:06 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
final class PhabricatorPeopleProfileViewController
|
|
|
|
extends PhabricatorPeopleProfileController {
|
|
|
|
|
|
|
|
public function shouldAllowPublic() {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function handleRequest(AphrontRequest $request) {
|
|
|
|
$viewer = $this->getViewer();
|
|
|
|
$username = $request->getURIData('username');
|
|
|
|
|
|
|
|
$user = id(new PhabricatorPeopleQuery())
|
|
|
|
->setViewer($viewer)
|
|
|
|
->withUsernames(array($username))
|
|
|
|
->needBadges(true)
|
|
|
|
->needProfileImage(true)
|
|
|
|
->needAvailability(true)
|
|
|
|
->executeOne();
|
|
|
|
if (!$user) {
|
|
|
|
return new Aphront404Response();
|
|
|
|
}
|
|
|
|
|
|
|
|
$this->setUser($user);
|
|
|
|
|
|
|
|
$profile = $user->loadUserProfile();
|
|
|
|
$picture = $user->getProfileImageURI();
|
|
|
|
|
2016-01-24 14:43:57 +01:00
|
|
|
$profile_icon = PhabricatorPeopleIconSet::getIconIcon($profile->getIcon());
|
|
|
|
$profile_icon = id(new PHUIIconView())
|
2016-01-28 05:38:01 +01:00
|
|
|
->setIcon($profile_icon);
|
2016-01-24 14:43:57 +01:00
|
|
|
$profile_title = $profile->getDisplayTitle();
|
|
|
|
|
2016-01-14 15:47:06 +01:00
|
|
|
$header = id(new PHUIHeaderView())
|
|
|
|
->setHeader($user->getFullName())
|
2016-01-24 14:43:57 +01:00
|
|
|
->setSubheader(array($profile_icon, $profile_title))
|
2016-01-25 02:04:55 +01:00
|
|
|
->setImage($picture)
|
|
|
|
->setProfileHeader(true);
|
2016-01-14 15:47:06 +01:00
|
|
|
|
2016-01-25 02:04:55 +01:00
|
|
|
$can_edit = PhabricatorPolicyFilter::hasCapability(
|
|
|
|
$viewer,
|
|
|
|
$user,
|
|
|
|
PhabricatorPolicyCapability::CAN_EDIT);
|
2016-01-14 15:47:06 +01:00
|
|
|
|
2016-01-25 02:04:55 +01:00
|
|
|
if ($can_edit) {
|
|
|
|
$id = $user->getID();
|
|
|
|
$header->setImageEditURL($this->getApplicationURI("picture/{$id}/"));
|
2016-01-14 15:47:06 +01:00
|
|
|
}
|
|
|
|
|
2016-01-25 02:04:55 +01:00
|
|
|
$properties = $this->buildPropertyView($user);
|
2016-01-14 15:47:06 +01:00
|
|
|
$name = $user->getUsername();
|
|
|
|
|
2016-01-25 02:04:55 +01:00
|
|
|
$feed = $this->buildPeopleFeed($user, $viewer);
|
|
|
|
$feed = phutil_tag_div('project-view-feed', $feed);
|
2016-01-14 15:47:06 +01:00
|
|
|
|
2016-02-04 03:22:34 +01:00
|
|
|
$projects = $this->buildProjectsView($user);
|
2016-01-14 15:47:06 +01:00
|
|
|
$badges = $this->buildBadgesView($user);
|
|
|
|
|
2016-02-04 03:22:34 +01:00
|
|
|
$columns = id(new PHUITwoColumnView())
|
|
|
|
->addClass('project-view-badges')
|
|
|
|
->setMainColumn(
|
|
|
|
array(
|
|
|
|
$properties,
|
|
|
|
$feed,
|
|
|
|
))
|
|
|
|
->setSideColumn(
|
|
|
|
array(
|
|
|
|
$projects,
|
|
|
|
$badges,
|
|
|
|
));
|
2016-01-25 02:04:55 +01:00
|
|
|
|
2016-01-14 15:47:06 +01:00
|
|
|
$nav = $this->getProfileMenu();
|
|
|
|
$nav->selectFilter(PhabricatorPeopleProfilePanelEngine::PANEL_PROFILE);
|
|
|
|
|
|
|
|
$crumbs = $this->buildApplicationCrumbs();
|
2016-01-25 02:04:55 +01:00
|
|
|
$crumbs->setBorder(true);
|
|
|
|
|
|
|
|
require_celerity_resource('project-view-css');
|
|
|
|
$home = phutil_tag(
|
|
|
|
'div',
|
|
|
|
array(
|
|
|
|
'class' => 'project-view-home',
|
|
|
|
),
|
|
|
|
array(
|
|
|
|
$header,
|
|
|
|
$columns,
|
|
|
|
));
|
2016-01-14 15:47:06 +01:00
|
|
|
|
|
|
|
return $this->newPage()
|
|
|
|
->setTitle($user->getUsername())
|
|
|
|
->setNavigation($nav)
|
|
|
|
->setCrumbs($crumbs)
|
|
|
|
->appendChild(
|
|
|
|
array(
|
2016-01-25 02:04:55 +01:00
|
|
|
$home,
|
2016-01-14 15:47:06 +01:00
|
|
|
));
|
|
|
|
}
|
|
|
|
|
|
|
|
private function buildPropertyView(
|
2016-01-25 02:04:55 +01:00
|
|
|
PhabricatorUser $user) {
|
2016-01-14 15:47:06 +01:00
|
|
|
|
|
|
|
$viewer = $this->getRequest()->getUser();
|
|
|
|
$view = id(new PHUIPropertyListView())
|
|
|
|
->setUser($viewer)
|
2016-01-25 02:04:55 +01:00
|
|
|
->setObject($user);
|
2016-01-14 15:47:06 +01:00
|
|
|
|
|
|
|
$field_list = PhabricatorCustomField::getObjectFields(
|
|
|
|
$user,
|
|
|
|
PhabricatorCustomField::ROLE_VIEW);
|
|
|
|
$field_list->appendFieldsToPropertyList($user, $viewer, $view);
|
|
|
|
|
2016-02-01 00:16:51 +01:00
|
|
|
if (!$view->hasAnyProperties()) {
|
2016-01-25 02:04:55 +01:00
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
$view = id(new PHUIBoxView())
|
|
|
|
->setColor(PHUIBoxView::GREY)
|
|
|
|
->appendChild($view)
|
|
|
|
->addClass('project-view-properties');
|
|
|
|
|
2016-01-14 15:47:06 +01:00
|
|
|
return $view;
|
|
|
|
}
|
|
|
|
|
2016-02-04 03:22:34 +01:00
|
|
|
private function buildProjectsView(
|
|
|
|
PhabricatorUser $user) {
|
|
|
|
|
|
|
|
$viewer = $this->getViewer();
|
|
|
|
$projects = id(new PhabricatorProjectQuery())
|
|
|
|
->setViewer($viewer)
|
|
|
|
->withMemberPHIDs(array($user->getPHID()))
|
|
|
|
->needImages(true)
|
2016-02-06 21:40:31 +01:00
|
|
|
->withStatuses(
|
|
|
|
array(
|
|
|
|
PhabricatorProjectStatus::STATUS_ACTIVE,
|
|
|
|
))
|
2016-02-04 03:22:34 +01:00
|
|
|
->execute();
|
|
|
|
|
|
|
|
$header = id(new PHUIHeaderView())
|
|
|
|
->setHeader(pht('Projects'));
|
|
|
|
|
|
|
|
if (!empty($projects)) {
|
|
|
|
$limit = 5;
|
|
|
|
$render_phids = array_slice($projects, 0, $limit);
|
|
|
|
$list = id(new PhabricatorProjectListView())
|
|
|
|
->setUser($viewer)
|
|
|
|
->setProjects($render_phids);
|
|
|
|
|
|
|
|
if (count($projects) > $limit) {
|
|
|
|
$header_text = pht(
|
|
|
|
'Projects (%s)',
|
|
|
|
phutil_count($projects));
|
|
|
|
|
|
|
|
$header = id(new PHUIHeaderView())
|
|
|
|
->setHeader($header_text)
|
|
|
|
->addActionLink(
|
|
|
|
id(new PHUIButtonView())
|
|
|
|
->setTag('a')
|
|
|
|
->setIcon('fa-list-ul')
|
|
|
|
->setText(pht('View All'))
|
|
|
|
->setHref('/project/?member='.$user->getPHID()));
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
} else {
|
|
|
|
$error = id(new PHUIBoxView())
|
|
|
|
->addClass('mlb')
|
|
|
|
->appendChild(pht('User does not belong to any projects.'));
|
|
|
|
$list = id(new PHUIInfoView())
|
|
|
|
->setSeverity(PHUIInfoView::SEVERITY_NODATA)
|
|
|
|
->appendChild($error);
|
|
|
|
}
|
|
|
|
|
|
|
|
$box = id(new PHUIObjectBoxView())
|
|
|
|
->setHeader($header)
|
|
|
|
->appendChild($list)
|
|
|
|
->setBackground(PHUIBoxView::GREY);
|
|
|
|
|
|
|
|
return $box;
|
|
|
|
}
|
|
|
|
|
2016-02-04 16:13:47 +01:00
|
|
|
private function buildBadgesView(PhabricatorUser $user) {
|
2016-01-14 15:47:06 +01:00
|
|
|
|
|
|
|
$viewer = $this->getViewer();
|
|
|
|
$class = 'PhabricatorBadgesApplication';
|
|
|
|
|
2016-02-04 16:13:47 +01:00
|
|
|
if (!PhabricatorApplication::isClassInstalledForViewer($class, $viewer)) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
$badge_phids = $user->getBadgePHIDs();
|
|
|
|
if ($badge_phids) {
|
|
|
|
$badges = id(new PhabricatorBadgesQuery())
|
|
|
|
->setViewer($viewer)
|
|
|
|
->withPHIDs($badge_phids)
|
|
|
|
->withStatuses(array(PhabricatorBadgesBadge::STATUS_ACTIVE))
|
|
|
|
->execute();
|
|
|
|
|
|
|
|
$flex = new PHUIBadgeBoxView();
|
|
|
|
foreach ($badges as $badge) {
|
|
|
|
$item = id(new PHUIBadgeView())
|
|
|
|
->setIcon($badge->getIcon())
|
|
|
|
->setHeader($badge->getName())
|
|
|
|
->setSubhead($badge->getFlavor())
|
|
|
|
->setQuality($badge->getQuality());
|
|
|
|
$flex->addItem($item);
|
2016-01-14 15:47:06 +01:00
|
|
|
}
|
2016-02-04 16:13:47 +01:00
|
|
|
|
|
|
|
} else {
|
|
|
|
$error = id(new PHUIBoxView())
|
|
|
|
->addClass('mlb')
|
|
|
|
->appendChild(pht('User does not have any badges.'));
|
|
|
|
$flex = id(new PHUIInfoView())
|
|
|
|
->setSeverity(PHUIInfoView::SEVERITY_NODATA)
|
|
|
|
->appendChild($error);
|
2016-01-24 16:07:17 +01:00
|
|
|
}
|
|
|
|
|
2016-02-04 03:22:34 +01:00
|
|
|
$box = id(new PHUIObjectBoxView())
|
|
|
|
->setHeaderText(pht('Badges'))
|
|
|
|
->appendChild($flex)
|
|
|
|
->setBackground(PHUIBoxView::GREY);
|
|
|
|
|
2016-01-14 15:47:06 +01:00
|
|
|
return $box;
|
|
|
|
}
|
|
|
|
|
|
|
|
private function buildPeopleFeed(
|
|
|
|
PhabricatorUser $user,
|
|
|
|
$viewer) {
|
|
|
|
|
|
|
|
$query = new PhabricatorFeedQuery();
|
|
|
|
$query->setFilterPHIDs(
|
|
|
|
array(
|
|
|
|
$user->getPHID(),
|
|
|
|
));
|
|
|
|
$query->setLimit(100);
|
|
|
|
$query->setViewer($viewer);
|
|
|
|
$stories = $query->execute();
|
|
|
|
|
|
|
|
$builder = new PhabricatorFeedBuilder($stories);
|
|
|
|
$builder->setUser($viewer);
|
|
|
|
$builder->setShowHovercards(true);
|
|
|
|
$builder->setNoDataString(pht('To begin on such a grand journey, '.
|
|
|
|
'requires but just a single step.'));
|
|
|
|
$view = $builder->buildView();
|
|
|
|
|
2016-01-25 02:04:55 +01:00
|
|
|
return $view->render();
|
2016-01-14 15:47:06 +01:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|