id = idx($data, 'id');
$this->page = idx($data, 'page');
}
public function processRequest() {
$request = $this->getRequest();
$user = $request->getUser();
$uri = $request->getRequestURI();
$project = id(new PhabricatorProject())->load($this->id);
if (!$project) {
return new Aphront404Response();
}
$profile = $project->loadProfile();
if (!$profile) {
$profile = new PhabricatorProjectProfile();
}
$src_phid = $profile->getProfileImagePHID();
if (!$src_phid) {
$src_phid = $user->getProfileImagePHID();
}
$picture = PhabricatorFileURI::getViewURIForPHID($src_phid);
$pages = array(
/*
'
Active Documents
',
'tasks' => 'Maniphest Tasks',
'revisions' => 'Differential Revisions',
'
',
'Workflow
',
'goals' => 'Goals',
'statistics' => 'Statistics',
'
', */
'Information
',
'edit' => 'Edit Project',
'affiliation' => 'Edit Affiliation',
);
if (empty($pages[$this->page])) {
$this->page = 'action';
}
switch ($this->page) {
default:
$content = $this->renderBasicInformation($project, $profile);
break;
}
$profile = new PhabricatorProfileView();
$profile->setProfilePicture($picture);
$profile->setProfileNames($project->getName());
foreach ($pages as $page => $name) {
if (is_integer($page)) {
$profile->addProfileItem(
phutil_render_tag(
'span',
array(),
$name));
} else {
$uri->setPath('/project/'.$page.'/'.$project->getID().'/');
$profile->addProfileItem(
phutil_render_tag(
'a',
array(
'href' => $uri,
'class' => ($this->page == $page)
? 'phabricator-profile-item-selected'
: null,
),
phutil_escape_html($name)));
}
}
$profile->appendChild($content);
return $this->buildStandardPageResponse(
$profile,
array(
'title' => $project->getName(),
));
}
//----------------------------------------------------------------------------
// Helper functions
private function renderBasicInformation($project, $profile) {
$blurb = nonempty(
$profile->getBlurb(),
'//Nothing is known about this elusive project.//');
$engine = PhabricatorMarkupEngine::newProfileMarkupEngine();
$blurb = $engine->markupText($blurb);
$affiliations = $project->loadAffiliations();
$phids = array_merge(
array($project->getAuthorPHID()),
$project->getSubprojectPHIDs(),
mpull($affiliations, 'getUserPHID')
);
$phids = array_unique($phids);
$handles = id(new PhabricatorObjectHandleData($phids))
->loadHandles();
$affiliated = array();
foreach ($affiliations as $affiliation) {
$user = $handles[$affiliation->getUserPHID()]->renderLink();
$role = phutil_escape_html($affiliation->getRole());
$status = null;
if ($affiliation->getStatus() == 'former') {
$role = 'Former '.$role.'';
}
$affiliated[] = ''.$user.' — '.$role.$status.'';
}
if ($affiliated) {
$affiliated = ''.implode("\n", $affiliated).'
';
} else {
$affiliated = 'No one is affiliated with this project.
';
}
if ($project->getSubprojectPHIDs()) {
$table = $this->renderSubprojectTable(
$handles,
$project->getSubprojectPHIDs());
$subproject_list = $table->render();
} else {
$subproject_list =
'There are no projects attached for such specie.
';
}
$viewer = $this->getRequest()->getUser();
$timestamp = phabricator_datetime($project->getDateCreated(), $viewer);
$status = PhabricatorProjectStatus::getNameForStatus(
$project->getStatus());
$content =
'
Creator |
'.$handles[$project->getAuthorPHID()]->renderLink().' |
Status |
'.phutil_escape_html($status).' |
Created |
'.$timestamp.' |
PHID |
'.phutil_escape_html($project->getPHID()).' |
Blurb |
'.$blurb.' |
';
$content .=
''.
''.
'
'.
$affiliated.
'
'.
'
';
$content .= ''.
''.
'
'.
$subproject_list.
'
'.
'
';
$query = id(new ManiphestTaskQuery())
->withProjects(array($project->getPHID()))
->withStatus(ManiphestTaskQuery::STATUS_OPEN)
->setOrderBy(ManiphestTaskQuery::ORDER_PRIORITY)
->setLimit(10)
->setCalculateRows(true);
$tasks = $query->execute();
$count = $query->getRowCount();
$phids = mpull($tasks, 'getOwnerPHID');
$phids = array_filter($phids);
$handles = id(new PhabricatorObjectHandleData($phids))
->loadHandles();
$task_views = array();
foreach ($tasks as $task) {
$view = id(new ManiphestTaskSummaryView())
->setTask($task)
->setHandles($handles)
->setUser($this->getRequest()->getUser());
$task_views[] = $view->render();
}
if (empty($tasks)) {
$task_views = 'No open tasks.';
} else {
$task_views = implode('', $task_views);
}
$open = number_format($count);
$more_link = phutil_render_tag(
'a',
array(
'href' => '/maniphest/view/all/?projects='.$project->getPHID(),
),
"View All Open Tasks \xC2\xBB");
$content .=
'
'.
'
'.
$task_views.
'
'.
$more_link.
'
'.
'
';
return $content;
}
private function renderSubprojectTable(
PhabricatorObjectHandleData $handles,
$subprojects_phids) {
$rows = array();
foreach ($subprojects_phids as $subproject_phid) {
$phid = $handles[$subproject_phid]->getPHID();
$rows[] = array(
phutil_escape_html($handles[$phid]->getFullName()),
phutil_render_tag(
'a',
array(
'class' => 'small grey button',
'href' => $handles[$phid]->getURI(),
),
'View Project Profile'),
);
}
$table = new AphrontTableView($rows);
$table->setHeaders(
array(
'Name',
'',
));
$table->setColumnClasses(
array(
'pri',
'action right',
));
return $table;
}
}