2013-06-04 11:15:34 -07:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
final class DivinerBookController extends DivinerController {
|
|
|
|
|
|
|
|
|
|
private $bookName;
|
|
|
|
|
|
|
|
|
|
public function shouldAllowPublic() {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function willProcessRequest(array $data) {
|
|
|
|
|
$this->bookName = $data['book'];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function processRequest() {
|
|
|
|
|
$request = $this->getRequest();
|
|
|
|
|
$viewer = $request->getUser();
|
|
|
|
|
|
|
|
|
|
$book = id(new DivinerBookQuery())
|
|
|
|
|
->setViewer($viewer)
|
|
|
|
|
->withNames(array($this->bookName))
|
|
|
|
|
->executeOne();
|
|
|
|
|
|
|
|
|
|
if (!$book) {
|
|
|
|
|
return new Aphront404Response();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$crumbs = $this->buildApplicationCrumbs();
|
2015-01-30 09:17:17 -08:00
|
|
|
$crumbs->setBorder(true);
|
2013-06-04 11:15:34 -07:00
|
|
|
|
2013-12-18 17:47:34 -08:00
|
|
|
$crumbs->addTextCrumb(
|
|
|
|
|
$book->getShortTitle(),
|
|
|
|
|
'/book/'.$book->getName().'/');
|
2013-06-04 11:15:34 -07:00
|
|
|
|
2013-09-18 16:27:24 -07:00
|
|
|
$header = id(new PHUIHeaderView())
|
|
|
|
|
->setHeader($book->getTitle())
|
2013-09-19 11:56:58 -07:00
|
|
|
->setUser($viewer)
|
Add setEpoch for PHUIHeaderView, use in all Documents
Summary: Sets a consistent last update time in the header of PHUIDocuments, Legalpad, Diviner, Phriction. I'm not set on the exact language, just that there is consistency, feel free to suggest changes.
Test Plan:
Test Legalpad, Diviner, Phriction.
{F368270}
Reviewers: btrahan, epriestley
Reviewed By: epriestley
Subscribers: Korvin, epriestley
Differential Revision: https://secure.phabricator.com/D12384
2015-04-12 18:08:09 -07:00
|
|
|
->setPolicyObject($book)
|
|
|
|
|
->setEpoch($book->getDateModified());
|
2013-09-18 16:27:24 -07:00
|
|
|
|
2013-09-10 07:26:00 -07:00
|
|
|
$document = new PHUIDocumentView();
|
|
|
|
|
$document->setHeader($header);
|
2014-07-28 10:36:16 -07:00
|
|
|
$document->addClass('diviner-view');
|
2014-03-06 11:28:24 -08:00
|
|
|
$document->setFontKit(PHUIDocumentView::FONT_SOURCE_SANS);
|
2013-09-10 07:26:00 -07:00
|
|
|
|
2013-06-04 11:15:34 -07:00
|
|
|
$atoms = id(new DivinerAtomQuery())
|
|
|
|
|
->setViewer($viewer)
|
|
|
|
|
->withBookPHIDs(array($book->getPHID()))
|
|
|
|
|
->execute();
|
2014-03-10 17:59:13 -07:00
|
|
|
|
2013-06-04 11:15:34 -07:00
|
|
|
$atoms = msort($atoms, 'getSortKey');
|
|
|
|
|
|
|
|
|
|
$group_spec = $book->getConfig('groups');
|
|
|
|
|
if (!is_array($group_spec)) {
|
|
|
|
|
$group_spec = array();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$groups = mgroup($atoms, 'getGroupName');
|
|
|
|
|
$groups = array_select_keys($groups, array_keys($group_spec)) + $groups;
|
|
|
|
|
if (isset($groups[''])) {
|
|
|
|
|
$no_group = $groups[''];
|
|
|
|
|
unset($groups['']);
|
|
|
|
|
$groups[''] = $no_group;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$out = array();
|
|
|
|
|
foreach ($groups as $group => $atoms) {
|
2013-06-06 08:36:51 -07:00
|
|
|
$group_name = $book->getGroupName($group);
|
2014-03-10 17:59:13 -07:00
|
|
|
if (!strlen($group_name)) {
|
|
|
|
|
$group_name = pht('Free Radicals');
|
|
|
|
|
}
|
2013-09-10 07:26:00 -07:00
|
|
|
$section = id(new DivinerSectionView())
|
2014-03-10 17:59:13 -07:00
|
|
|
->setHeader($group_name);
|
2013-09-10 07:26:00 -07:00
|
|
|
$section->addContent($this->renderAtomList($atoms));
|
|
|
|
|
$out[] = $section;
|
2013-06-04 11:15:34 -07:00
|
|
|
}
|
2014-03-06 11:28:24 -08:00
|
|
|
|
|
|
|
|
$preface = $book->getPreface();
|
|
|
|
|
$preface_view = null;
|
|
|
|
|
if (strlen($preface)) {
|
|
|
|
|
$preface_view =
|
|
|
|
|
PhabricatorMarkupEngine::renderOneObject(
|
|
|
|
|
id(new PhabricatorMarkupOneOff())->setContent($preface),
|
|
|
|
|
'default',
|
|
|
|
|
$viewer);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$document->appendChild($preface_view);
|
2013-09-10 07:26:00 -07:00
|
|
|
$document->appendChild($out);
|
2013-06-04 11:15:34 -07:00
|
|
|
|
|
|
|
|
return $this->buildApplicationPage(
|
|
|
|
|
array(
|
|
|
|
|
$crumbs,
|
2013-09-10 07:26:00 -07:00
|
|
|
$document,
|
2013-06-04 11:15:34 -07:00
|
|
|
),
|
|
|
|
|
array(
|
|
|
|
|
'title' => $book->getTitle(),
|
|
|
|
|
));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|