2011-01-24 03:09:16 +01:00
|
|
|
<?php
|
|
|
|
|
2012-03-10 00:46:25 +01:00
|
|
|
final class PhabricatorPeopleProfileController
|
|
|
|
extends PhabricatorPeopleController {
|
2011-01-24 03:09:16 +01:00
|
|
|
|
|
|
|
private $username;
|
|
|
|
|
2013-03-19 21:48:50 +01:00
|
|
|
public function shouldRequireAdmin() {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2011-01-24 03:09:16 +01:00
|
|
|
public function willProcessRequest(array $data) {
|
2011-06-18 10:13:56 +02:00
|
|
|
$this->username = idx($data, 'username');
|
2013-02-05 22:46:02 +01:00
|
|
|
}
|
|
|
|
|
2011-01-24 03:09:16 +01:00
|
|
|
public function processRequest() {
|
2011-02-20 02:33:53 +01:00
|
|
|
$viewer = $this->getRequest()->getUser();
|
|
|
|
|
2013-07-10 14:10:54 +02:00
|
|
|
$user = id(new PhabricatorPeopleQuery())
|
|
|
|
->setViewer($viewer)
|
|
|
|
->withUsernames(array($this->username))
|
|
|
|
->executeOne();
|
2011-01-24 03:09:16 +01:00
|
|
|
if (!$user) {
|
|
|
|
return new Aphront404Response();
|
|
|
|
}
|
|
|
|
|
2011-12-24 03:17:40 +01:00
|
|
|
require_celerity_resource('phabricator-profile-css');
|
|
|
|
|
2013-03-24 14:42:31 +01:00
|
|
|
$profile = $user->loadUserProfile();
|
2012-03-06 22:57:31 +01:00
|
|
|
$username = phutil_escape_uri($user->getUserName());
|
2011-02-20 03:28:41 +01:00
|
|
|
|
2012-04-28 02:44:10 +02:00
|
|
|
$picture = $user->loadProfileImageURI();
|
2011-12-24 03:17:40 +01:00
|
|
|
|
2013-07-10 01:23:22 +02:00
|
|
|
$header = id(new PhabricatorHeaderView())
|
|
|
|
->setHeader($user->getUserName().' ('.$user->getRealName().')')
|
|
|
|
->setSubheader($profile->getTitle())
|
|
|
|
->setImage($picture);
|
2011-12-24 03:17:40 +01:00
|
|
|
|
2013-07-10 01:23:45 +02:00
|
|
|
$actions = id(new PhabricatorActionListView())
|
2013-07-10 14:11:08 +02:00
|
|
|
->setObject($user)
|
2013-07-12 20:39:47 +02:00
|
|
|
->setObjectURI($this->getRequest()->getRequestURI())
|
2013-07-10 01:23:45 +02:00
|
|
|
->setUser($viewer);
|
2011-12-24 03:17:40 +01:00
|
|
|
|
2013-07-10 01:23:45 +02:00
|
|
|
$can_edit = ($user->getPHID() == $viewer->getPHID());
|
|
|
|
|
|
|
|
$actions->addAction(
|
|
|
|
id(new PhabricatorActionView())
|
|
|
|
->setIcon('edit')
|
|
|
|
->setName(pht('Edit Profile'))
|
|
|
|
->setHref($this->getApplicationURI('editprofile/'.$user->getID().'/'))
|
|
|
|
->setDisabled(!$can_edit)
|
|
|
|
->setWorkflow(!$can_edit));
|
2011-02-20 02:33:53 +01:00
|
|
|
|
2013-07-10 01:23:54 +02:00
|
|
|
$actions->addAction(
|
|
|
|
id(new PhabricatorActionView())
|
|
|
|
->setIcon('image')
|
|
|
|
->setName(pht('Edit Profile Picture'))
|
|
|
|
->setHref($this->getApplicationURI('picture/'.$user->getID().'/'))
|
|
|
|
->setDisabled(!$can_edit)
|
|
|
|
->setWorkflow(!$can_edit));
|
|
|
|
|
2012-01-17 01:54:05 +01:00
|
|
|
if ($viewer->getIsAdmin()) {
|
2013-07-10 01:23:45 +02:00
|
|
|
$actions->addAction(
|
|
|
|
id(new PhabricatorActionView())
|
|
|
|
->setIcon('blame')
|
|
|
|
->setName(pht('Administrate User'))
|
|
|
|
->setHref($this->getApplicationURI('edit/'.$user->getID().'/')));
|
2012-01-17 01:54:05 +01:00
|
|
|
}
|
|
|
|
|
2013-07-10 14:09:59 +02:00
|
|
|
$properties = $this->buildPropertyView($user);
|
|
|
|
|
2013-07-10 14:11:08 +02:00
|
|
|
$crumbs = $this->buildApplicationCrumbs();
|
|
|
|
$crumbs->addCrumb(
|
|
|
|
id(new PhabricatorCrumbView())
|
|
|
|
->setName($user->getUsername()));
|
|
|
|
$feed = $this->renderUserFeed($user);
|
2013-07-10 01:23:45 +02:00
|
|
|
|
2012-08-14 00:27:21 +02:00
|
|
|
return $this->buildApplicationPage(
|
2013-07-10 14:11:08 +02:00
|
|
|
array(
|
|
|
|
$crumbs,
|
|
|
|
$header,
|
|
|
|
$actions,
|
|
|
|
$properties,
|
|
|
|
$feed,
|
|
|
|
),
|
2011-02-20 02:33:53 +01:00
|
|
|
array(
|
2011-06-18 10:13:56 +02:00
|
|
|
'title' => $user->getUsername(),
|
2013-04-15 04:32:26 +02:00
|
|
|
'device' => true,
|
|
|
|
'dust' => true,
|
2011-02-20 02:33:53 +01:00
|
|
|
));
|
2011-06-18 10:13:56 +02:00
|
|
|
}
|
2011-02-20 02:33:53 +01:00
|
|
|
|
2013-07-10 14:09:59 +02:00
|
|
|
private function buildPropertyView(PhabricatorUser $user) {
|
|
|
|
$viewer = $this->getRequest()->getUser();
|
2011-12-24 03:17:40 +01:00
|
|
|
|
2013-07-10 14:09:59 +02:00
|
|
|
$view = id(new PhabricatorPropertyListView())
|
|
|
|
->setUser($viewer)
|
|
|
|
->setObject($user);
|
2011-02-20 03:28:41 +01:00
|
|
|
|
2013-07-10 14:09:59 +02:00
|
|
|
$fields = PhabricatorCustomField::getObjectFields(
|
|
|
|
$user,
|
|
|
|
PhabricatorCustomField::ROLE_VIEW);
|
2013-03-04 21:33:05 +01:00
|
|
|
|
2013-07-10 14:09:59 +02:00
|
|
|
foreach ($fields as $field) {
|
|
|
|
$field->setViewer($viewer);
|
|
|
|
}
|
|
|
|
|
|
|
|
$view->applyCustomFields($fields);
|
|
|
|
|
|
|
|
return $view;
|
2011-12-24 03:17:40 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
private function renderUserFeed(PhabricatorUser $user) {
|
2012-07-03 00:41:19 +02:00
|
|
|
$viewer = $this->getRequest()->getUser();
|
|
|
|
|
2011-12-24 03:17:40 +01:00
|
|
|
$query = new PhabricatorFeedQuery();
|
|
|
|
$query->setFilterPHIDs(
|
|
|
|
array(
|
|
|
|
$user->getPHID(),
|
|
|
|
));
|
2012-07-03 15:25:03 +02:00
|
|
|
$query->setLimit(100);
|
2012-07-03 00:41:19 +02:00
|
|
|
$query->setViewer($viewer);
|
2011-12-24 03:17:40 +01:00
|
|
|
$stories = $query->execute();
|
|
|
|
|
|
|
|
$builder = new PhabricatorFeedBuilder($stories);
|
2012-07-03 00:41:19 +02:00
|
|
|
$builder->setUser($viewer);
|
2011-12-24 03:17:40 +01:00
|
|
|
$view = $builder->buildView();
|
|
|
|
|
2013-02-13 23:50:15 +01:00
|
|
|
return hsprintf(
|
2013-04-15 22:07:54 +02:00
|
|
|
'<div class="profile-feed profile-wrap-responsive">
|
2013-04-15 04:32:26 +02:00
|
|
|
%s
|
2013-02-13 23:50:15 +01:00
|
|
|
</div>',
|
|
|
|
$view->render());
|
2011-01-24 03:09:16 +01:00
|
|
|
}
|
|
|
|
}
|