2011-07-11 17:54:22 +02:00
|
|
|
<?php
|
|
|
|
|
2011-09-14 17:02:31 +02:00
|
|
|
/**
|
|
|
|
* @group phriction
|
|
|
|
*/
|
2011-07-11 17:54:22 +02:00
|
|
|
abstract class PhrictionController extends PhabricatorController {
|
|
|
|
|
2013-07-28 03:26:42 +02:00
|
|
|
public function buildSideNavView($for_app = false) {
|
2013-01-11 20:39:22 +01:00
|
|
|
$user = $this->getRequest()->getUser();
|
|
|
|
|
|
|
|
$nav = new AphrontSideNavFilterView();
|
2013-07-28 03:26:42 +02:00
|
|
|
$nav->setBaseURI(new PhutilURI($this->getApplicationURI()));
|
2013-01-11 20:39:22 +01:00
|
|
|
|
|
|
|
if ($for_app) {
|
2013-07-28 03:26:42 +02:00
|
|
|
$nav->addFilter('create', pht('New Document'));
|
|
|
|
$nav->addFilter('/phriction/', pht('Index'));
|
2013-01-11 20:39:22 +01:00
|
|
|
}
|
|
|
|
|
2013-07-28 03:26:42 +02:00
|
|
|
id(new PhrictionSearchEngine())
|
|
|
|
->setViewer($user)
|
|
|
|
->addNavigationItems($nav->getMenu());
|
2013-01-11 20:39:22 +01:00
|
|
|
|
2013-07-28 03:26:42 +02:00
|
|
|
$nav->selectFilter(null);
|
2013-01-11 20:39:22 +01:00
|
|
|
|
|
|
|
return $nav;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function buildApplicationMenu() {
|
2013-07-28 03:26:42 +02:00
|
|
|
return $this->buildSideNavView(true)->getMenu();
|
2013-01-11 20:39:22 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public function buildApplicationCrumbs() {
|
|
|
|
$crumbs = parent::buildApplicationCrumbs();
|
|
|
|
|
2013-04-02 17:59:14 +02:00
|
|
|
if (get_class($this) != 'PhrictionListController') {
|
|
|
|
$crumbs->addAction(
|
2013-06-05 17:41:43 +02:00
|
|
|
id(new PHUIListItemView())
|
2013-04-12 00:05:50 +02:00
|
|
|
->setName(pht('Index'))
|
2013-04-02 17:59:14 +02:00
|
|
|
->setHref('/phriction/')
|
2014-05-12 19:08:32 +02:00
|
|
|
->setIcon('fa-home'));
|
2013-04-02 17:59:14 +02:00
|
|
|
}
|
|
|
|
|
2013-01-11 20:39:22 +01:00
|
|
|
$crumbs->addAction(
|
2013-06-05 17:41:43 +02:00
|
|
|
id(new PHUIListItemView())
|
2013-04-12 00:05:50 +02:00
|
|
|
->setName(pht('New Document'))
|
2013-03-07 17:12:00 +01:00
|
|
|
->setHref('/phriction/new/?slug='.$this->getDocumentSlug())
|
2013-01-11 20:58:31 +01:00
|
|
|
->setWorkflow(true)
|
2014-05-12 19:08:32 +02:00
|
|
|
->setIcon('fa-plus-square'));
|
2013-01-11 20:39:22 +01:00
|
|
|
|
|
|
|
return $crumbs;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function renderBreadcrumbs($slug) {
|
|
|
|
$ancestor_handles = array();
|
|
|
|
$ancestral_slugs = PhabricatorSlug::getAncestry($slug);
|
|
|
|
$ancestral_slugs[] = $slug;
|
|
|
|
if ($ancestral_slugs) {
|
|
|
|
$empty_slugs = array_fill_keys($ancestral_slugs, null);
|
2014-05-19 21:41:12 +02:00
|
|
|
$ancestors = id(new PhrictionDocumentQuery())
|
|
|
|
->setViewer($this->getRequest()->getUser())
|
|
|
|
->withSlugs($ancestral_slugs)
|
|
|
|
->execute();
|
2013-01-11 20:39:22 +01:00
|
|
|
$ancestors = mpull($ancestors, null, 'getSlug');
|
|
|
|
|
|
|
|
$ancestor_phids = mpull($ancestors, 'getPHID');
|
|
|
|
$handles = array();
|
|
|
|
if ($ancestor_phids) {
|
|
|
|
$handles = $this->loadViewerHandles($ancestor_phids);
|
|
|
|
}
|
|
|
|
|
|
|
|
$ancestor_handles = array();
|
|
|
|
foreach ($ancestral_slugs as $slug) {
|
|
|
|
if (isset($ancestors[$slug])) {
|
|
|
|
$ancestor_handles[] = $handles[$ancestors[$slug]->getPHID()];
|
|
|
|
} else {
|
|
|
|
$handle = new PhabricatorObjectHandle();
|
|
|
|
$handle->setName(PhabricatorSlug::getDefaultTitle($slug));
|
|
|
|
$handle->setURI(PhrictionDocument::getSlugURI($slug));
|
|
|
|
$ancestor_handles[] = $handle;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
$breadcrumbs = array();
|
|
|
|
foreach ($ancestor_handles as $ancestor_handle) {
|
|
|
|
$breadcrumbs[] = id(new PhabricatorCrumbView())
|
|
|
|
->setName($ancestor_handle->getName())
|
|
|
|
->setHref($ancestor_handle->getUri());
|
|
|
|
}
|
|
|
|
return $breadcrumbs;
|
|
|
|
}
|
|
|
|
|
2013-03-07 17:12:00 +01:00
|
|
|
protected function getDocumentSlug() {
|
|
|
|
return '';
|
|
|
|
}
|
|
|
|
|
2011-07-11 17:54:22 +02:00
|
|
|
}
|