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 {
|
|
|
|
|
|
|
|
public function buildStandardPageResponse($view, array $data) {
|
|
|
|
|
|
|
|
$page = $this->buildStandardPageView();
|
|
|
|
|
2013-02-08 18:54:27 +01:00
|
|
|
$page->setApplicationName(pht('Phriction'));
|
2011-07-11 21:34:53 +02:00
|
|
|
$page->setBaseURI('/w/');
|
2011-07-11 17:54:22 +02:00
|
|
|
$page->setTitle(idx($data, 'title'));
|
|
|
|
$page->setGlyph("\xE2\x9A\xA1");
|
|
|
|
|
|
|
|
$page->appendChild($view);
|
2012-02-15 02:00:12 +01:00
|
|
|
$page->setSearchDefaultScope(PhabricatorSearchScope::SCOPE_WIKI);
|
2011-07-11 17:54:22 +02:00
|
|
|
|
|
|
|
$response = new AphrontWebpageResponse();
|
|
|
|
return $response->setContent($page->render());
|
|
|
|
}
|
2013-01-11 20:39:22 +01:00
|
|
|
|
|
|
|
public function buildSideNavView($filter = null, $for_app = false) {
|
|
|
|
$user = $this->getRequest()->getUser();
|
|
|
|
|
|
|
|
$nav = new AphrontSideNavFilterView();
|
|
|
|
$nav->setBaseURI(new PhutilURI('/phriction/list/'));
|
|
|
|
|
|
|
|
if ($for_app) {
|
|
|
|
$nav->addFilter('', pht('Root Document'), '/w/');
|
2013-04-12 00:05:50 +02:00
|
|
|
$nav->addFilter('', pht('New Document'), '/phriction/new');
|
2013-01-11 20:39:22 +01:00
|
|
|
}
|
|
|
|
|
2013-02-08 18:54:27 +01:00
|
|
|
$nav->addLabel(pht('Filters'));
|
2013-01-11 20:39:22 +01:00
|
|
|
$nav->addFilter('active', pht('Active Documents'));
|
|
|
|
$nav->addFilter('all', pht('All Documents'));
|
|
|
|
$nav->addFilter('updates', pht('Recently Updated'));
|
|
|
|
|
|
|
|
$nav->selectFilter($filter, 'active');
|
|
|
|
|
|
|
|
return $nav;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function buildApplicationMenu() {
|
|
|
|
return $this->buildSideNavView(null, true)->getMenu();
|
|
|
|
}
|
|
|
|
|
|
|
|
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/')
|
|
|
|
->setIcon('transcript'));
|
|
|
|
}
|
|
|
|
|
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)
|
2013-01-11 20:39:22 +01:00
|
|
|
->setIcon('create'));
|
|
|
|
|
|
|
|
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);
|
|
|
|
$ancestors = id(new PhrictionDocument())->loadAllWhere(
|
|
|
|
'slug IN (%Ls)',
|
|
|
|
$ancestral_slugs);
|
|
|
|
$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
|
|
|
}
|