Page MenuHomec4science

PhabricatorRepositoryAuthor.php
No OneTemporary

File Metadata

Created
Sun, Nov 24, 09:53

PhabricatorRepositoryAuthor.php

<?php
final class PhabricatorRepositoryAuthor
extends PhabricatorController {
public function handleRequest(AphrontRequest $request) {
$data = $request->getRequestData();
$viewer = $request->getViewer();
$author = idx($data, 'authorPHID', $viewer->getPHID());
$author_user = id(new PhabricatorUser())
->loadOneWhere('phid = %s', $author);
if(!$author_user) {
return new Aphront404Response();
}
$title = pht('Repositories for %s', $author_user->getFullName());
// Repositories
$repo_transaction = id(new PhabricatorRepositoryTransactionQuery())
->setViewer($viewer)
->withAuthorPHIDs(array($author))
->withTransactionTypes(array(PhabricatorTransactions::TYPE_CREATE))
->execute();
if(!empty($repo_transaction)) {
$repo_phids = mpull($repo_transaction, 'getObjectPHID');
$repo = id(new PhabricatorRepositoryQuery())
->setViewer($viewer)
->withPHIDs($repo_phids)
->withStatus(PhabricatorRepositoryQuery::STATUS_OPEN)
->execute();
}
$list = new PHUIObjectItemListView();
if (!empty($repo)) {
foreach($repo as $r){
$item = id(new PHUIObjectItemView())
->setUser($viewer)
->setObject($r)
->setHeader($r->getName())
->setObjectName($r->getMonogram())
->setHref($r->getURI());
$list->addItem($item);
}
} else {
$error = id(new PHUIBoxView())
->addClass('mlb')
->appendChild(pht('User does not have any repository.'));
$list = id(new PHUIInfoView())
->setSeverity(PHUIInfoView::SEVERITY_NODATA)
->appendChild($error);
}
// UI
$crumbs = $this->buildApplicationCrumbs();
$crumbs->addCrumb(
id(new PHUICrumbView())
->setHref('/p/' . $author_user->getUsername())
->setName($author_user->getUsername())
);
$crumbs->addCrumb(
id(new PHUICrumbView())
->setName(pht('Repositories'))
);
$header = id(new PHUIHeaderView())
->setHeader($title)
->setHeaderIcon('fa-code');
$view = id(new PHUIObjectBoxView())
->setHeader($header);
$view->setObjectList($list);
return $this->newPage()
->setTitle($title)
->setCrumbs($crumbs)
->appendChild($view);
}
protected function buildApplicationCrumbs() {
$view = new PHUICrumbsView();
$view->addCrumb(
id(new PHUICrumbView())
->setHref('/people/')
->setName(pht('People'))
->setIcon('fa-users')
);
return $view;
}
}

Event Timeline