Changeset View
Changeset View
Standalone View
Standalone View
src/applications/diviner/controller/DivinerBookController.php
| <?php | <?php | ||||
| final class DivinerBookController extends DivinerController { | final class DivinerBookController extends DivinerController { | ||||
| private $bookName; | |||||
| public function shouldAllowPublic() { | public function shouldAllowPublic() { | ||||
| return true; | return true; | ||||
| } | } | ||||
| public function willProcessRequest(array $data) { | public function handleRequest(AphrontRequest $request) { | ||||
| $this->bookName = $data['book']; | $viewer = $request->getViewer(); | ||||
| } | |||||
| public function processRequest() { | $book_name = $request->getURIData('book'); | ||||
| $request = $this->getRequest(); | |||||
| $viewer = $request->getUser(); | |||||
| $book = id(new DivinerBookQuery()) | $book = id(new DivinerBookQuery()) | ||||
| ->setViewer($viewer) | ->setViewer($viewer) | ||||
| ->withNames(array($this->bookName)) | ->withNames(array($book_name)) | ||||
| ->executeOne(); | ->executeOne(); | ||||
| if (!$book) { | if (!$book) { | ||||
| return new Aphront404Response(); | return new Aphront404Response(); | ||||
| } | } | ||||
| $actions = $this->buildActionView($viewer, $book); | |||||
| $crumbs = $this->buildApplicationCrumbs(); | $crumbs = $this->buildApplicationCrumbs(); | ||||
| $crumbs->setBorder(true); | $crumbs->setBorder(true); | ||||
| $crumbs->addTextCrumb( | $crumbs->addTextCrumb( | ||||
| $book->getShortTitle(), | $book->getShortTitle(), | ||||
| '/book/'.$book->getName().'/'); | '/book/'.$book->getName().'/'); | ||||
| $action_button = id(new PHUIButtonView()) | |||||
| ->setTag('a') | |||||
| ->setText(pht('Actions')) | |||||
| ->setHref('#') | |||||
| ->setIconFont('fa-bars') | |||||
| ->addClass('phui-mobile-menu') | |||||
| ->setDropdownMenu($actions); | |||||
| $header = id(new PHUIHeaderView()) | $header = id(new PHUIHeaderView()) | ||||
| ->setHeader($book->getTitle()) | ->setHeader($book->getTitle()) | ||||
| ->setUser($viewer) | ->setUser($viewer) | ||||
| ->setPolicyObject($book) | ->setPolicyObject($book) | ||||
| ->setEpoch($book->getDateModified()); | ->setEpoch($book->getDateModified()) | ||||
| ->addActionLink($action_button); | |||||
| $document = new PHUIDocumentView(); | $document = new PHUIDocumentView(); | ||||
| $document->setHeader($header); | $document->setHeader($header); | ||||
| $document->addClass('diviner-view'); | $document->addClass('diviner-view'); | ||||
| $document->setFontKit(PHUIDocumentView::FONT_SOURCE_SANS); | $document->setFontKit(PHUIDocumentView::FONT_SOURCE_SANS); | ||||
| $atoms = id(new DivinerAtomQuery()) | $atoms = id(new DivinerAtomQuery()) | ||||
| ->setViewer($viewer) | ->setViewer($viewer) | ||||
| ▲ Show 20 Lines • Show All 47 Lines • ▼ Show 20 Lines | return $this->buildApplicationPage( | ||||
| $crumbs, | $crumbs, | ||||
| $document, | $document, | ||||
| ), | ), | ||||
| array( | array( | ||||
| 'title' => $book->getTitle(), | 'title' => $book->getTitle(), | ||||
| )); | )); | ||||
| } | } | ||||
| private function buildActionView( | |||||
| PhabricatorUser $user, | |||||
| DivinerLiveBook $book) { | |||||
| $can_edit = PhabricatorPolicyFilter::hasCapability( | |||||
| $user, | |||||
| $book, | |||||
| PhabricatorPolicyCapability::CAN_EDIT); | |||||
| $action_view = id(new PhabricatorActionListView()) | |||||
| ->setUser($user) | |||||
| ->setObject($book) | |||||
| ->setObjectURI($this->getRequest()->getRequestURI()); | |||||
| $action_view->addAction( | |||||
| id(new PhabricatorActionView()) | |||||
| ->setName(pht('Edit Book')) | |||||
| ->setIcon('fa-pencil') | |||||
| ->setHref('/book/'.$book->getName().'/edit/') | |||||
joshuaspence: I feel like this gets repeated alot... maybe this should be a method on `DivinerLiveBook`? | |||||
| ->setDisabled(!$can_edit)); | |||||
| return $action_view; | |||||
| } | |||||
| } | } | ||||
I feel like this gets repeated alot... maybe this should be a method on DivinerLiveBook?