Path: blob/master/src/applications/diviner/controller/DivinerBookController.php
12256 views
<?php12final class DivinerBookController extends DivinerController {34public function shouldAllowPublic() {5return true;6}78public function handleRequest(AphrontRequest $request) {9$viewer = $request->getViewer();1011$book_name = $request->getURIData('book');1213$book = id(new DivinerBookQuery())14->setViewer($viewer)15->withNames(array($book_name))16->needRepositories(true)17->executeOne();1819if (!$book) {20return new Aphront404Response();21}2223$actions = $this->buildActionView($viewer, $book);2425$crumbs = $this->buildApplicationCrumbs();26$crumbs->setBorder(true);27$crumbs->addTextCrumb(28$book->getShortTitle(),29'/book/'.$book->getName().'/');3031$header = id(new PHUIHeaderView())32->setHeader($book->getTitle())33->setUser($viewer)34->setPolicyObject($book)35->setEpoch($book->getDateModified())36->setActionList($actions);3738// TODO: This could probably look better.39if ($book->getRepositoryPHID()) {40$header->addTag(41id(new PHUITagView())42->setType(PHUITagView::TYPE_STATE)43->setBackgroundColor(PHUITagView::COLOR_BLUE)44->setName($book->getRepository()->getMonogram()));45}4647$document = new PHUIDocumentView();48$document->setHeader($header);49$document->addClass('diviner-view');5051$atoms = id(new DivinerAtomQuery())52->setViewer($viewer)53->withBookPHIDs(array($book->getPHID()))54->withGhosts(false)55->withIsDocumentable(true)56->execute();5758$atoms = msort($atoms, 'getSortKey');5960$group_spec = $book->getConfig('groups');61if (!is_array($group_spec)) {62$group_spec = array();63}6465$groups = mgroup($atoms, 'getGroupName');66$groups = array_select_keys($groups, array_keys($group_spec)) + $groups;67if (isset($groups[''])) {68$no_group = $groups[''];69unset($groups['']);70$groups[''] = $no_group;71}7273$out = array();74foreach ($groups as $group => $atoms) {75$group_name = $book->getGroupName($group);76if (!strlen($group_name)) {77$group_name = pht('Free Radicals');78}79$section = id(new DivinerSectionView())80->setHeader($group_name);81$section->addContent($this->renderAtomList($atoms));82$out[] = $section;83}8485$preface = $book->getPreface();86$preface_view = null;87if (strlen($preface)) {88$preface_view = new PHUIRemarkupView($viewer, $preface);89}9091$document->appendChild($preface_view);92$document->appendChild($out);9394return $this->newPage()95->setTitle($book->getTitle())96->setCrumbs($crumbs)97->appendChild(array(98$document,99));100}101102private function buildActionView(103PhabricatorUser $user,104DivinerLiveBook $book) {105106$can_edit = PhabricatorPolicyFilter::hasCapability(107$user,108$book,109PhabricatorPolicyCapability::CAN_EDIT);110111$action_view = id(new PhabricatorActionListView())112->setUser($user)113->setObject($book);114115$action_view->addAction(116id(new PhabricatorActionView())117->setName(pht('Edit Book'))118->setIcon('fa-pencil')119->setHref('/book/'.$book->getName().'/edit/')120->setDisabled(!$can_edit));121122return $action_view;123}124125}126127128