[ Index ] |
PHP Cross Reference of Phabricator |
[Summary view] [Print] [Text view]
1 <?php 2 3 final class DivinerBookController extends DivinerController { 4 5 private $bookName; 6 7 public function shouldAllowPublic() { 8 return true; 9 } 10 11 public function willProcessRequest(array $data) { 12 $this->bookName = $data['book']; 13 } 14 15 public function processRequest() { 16 $request = $this->getRequest(); 17 $viewer = $request->getUser(); 18 19 $book = id(new DivinerBookQuery()) 20 ->setViewer($viewer) 21 ->withNames(array($this->bookName)) 22 ->executeOne(); 23 24 if (!$book) { 25 return new Aphront404Response(); 26 } 27 28 $crumbs = $this->buildApplicationCrumbs(); 29 30 $crumbs->addTextCrumb( 31 $book->getShortTitle(), 32 '/book/'.$book->getName().'/'); 33 34 $header = id(new PHUIHeaderView()) 35 ->setHeader($book->getTitle()) 36 ->setUser($viewer) 37 ->setPolicyObject($book); 38 39 $document = new PHUIDocumentView(); 40 $document->setHeader($header); 41 $document->addClass('diviner-view'); 42 43 $document->setFontKit(PHUIDocumentView::FONT_SOURCE_SANS); 44 45 $properties = $this->buildPropertyList($book); 46 47 $atoms = id(new DivinerAtomQuery()) 48 ->setViewer($viewer) 49 ->withBookPHIDs(array($book->getPHID())) 50 ->execute(); 51 52 $atoms = msort($atoms, 'getSortKey'); 53 54 $group_spec = $book->getConfig('groups'); 55 if (!is_array($group_spec)) { 56 $group_spec = array(); 57 } 58 59 $groups = mgroup($atoms, 'getGroupName'); 60 $groups = array_select_keys($groups, array_keys($group_spec)) + $groups; 61 if (isset($groups[''])) { 62 $no_group = $groups['']; 63 unset($groups['']); 64 $groups[''] = $no_group; 65 } 66 67 $out = array(); 68 foreach ($groups as $group => $atoms) { 69 $group_name = $book->getGroupName($group); 70 if (!strlen($group_name)) { 71 $group_name = pht('Free Radicals'); 72 } 73 $section = id(new DivinerSectionView()) 74 ->setHeader($group_name); 75 $section->addContent($this->renderAtomList($atoms)); 76 $out[] = $section; 77 } 78 79 $preface = $book->getPreface(); 80 $preface_view = null; 81 if (strlen($preface)) { 82 $preface_view = 83 PhabricatorMarkupEngine::renderOneObject( 84 id(new PhabricatorMarkupOneOff())->setContent($preface), 85 'default', 86 $viewer); 87 } 88 89 $document->appendChild($properties); 90 $document->appendChild($preface_view); 91 $document->appendChild($out); 92 93 return $this->buildApplicationPage( 94 array( 95 $crumbs, 96 $document, 97 ), 98 array( 99 'title' => $book->getTitle(), 100 )); 101 } 102 103 private function buildPropertyList(DivinerLiveBook $book) { 104 $viewer = $this->getRequest()->getUser(); 105 $view = id(new PHUIPropertyListView()) 106 ->setUser($viewer); 107 108 $policies = PhabricatorPolicyQuery::renderPolicyDescriptions( 109 $viewer, 110 $book); 111 112 $view->addProperty( 113 pht('Updated'), 114 phabricator_datetime($book->getDateModified(), $viewer)); 115 116 return $view; 117 } 118 119 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Sun Nov 30 09:20:46 2014 | Cross-referenced by PHPXref 0.7.1 |