Path: blob/master/src/applications/legalpad/controller/LegalpadDocumentManageController.php
13458 views
<?php12final class LegalpadDocumentManageController extends LegalpadController {34public function handleRequest(AphrontRequest $request) {5$viewer = $request->getViewer();6$id = $request->getURIData('id');78// NOTE: We require CAN_EDIT to view this page.910$document = id(new LegalpadDocumentQuery())11->setViewer($viewer)12->withIDs(array($id))13->needDocumentBodies(true)14->needContributors(true)15->requireCapabilities(16array(17PhabricatorPolicyCapability::CAN_VIEW,18PhabricatorPolicyCapability::CAN_EDIT,19))20->executeOne();21if (!$document) {22return new Aphront404Response();23}2425$subscribers = PhabricatorSubscribersQuery::loadSubscribersForPHID(26$document->getPHID());2728$document_body = $document->getDocumentBody();2930$engine = id(new PhabricatorMarkupEngine())31->setViewer($viewer);32$engine->addObject(33$document_body,34LegalpadDocumentBody::MARKUP_FIELD_TEXT);35$timeline = $this->buildTransactionTimeline(36$document,37new LegalpadTransactionQuery(),38$engine);39$timeline->setQuoteRef($document->getMonogram());4041$title = $document_body->getTitle();4243$header = id(new PHUIHeaderView())44->setHeader($title)45->setUser($viewer)46->setPolicyObject($document)47->setHeaderIcon('fa-gavel');4849$curtain = $this->buildCurtainView($document);50$properties = $this->buildPropertyView($document, $engine);51$document_view = $this->buildDocumentView($document, $engine);5253$comment_form = $this->buildCommentView($document, $timeline);5455$crumbs = $this->buildApplicationCrumbs();56$crumbs->addTextCrumb(57$document->getMonogram(),58'/'.$document->getMonogram());59$crumbs->addTextCrumb(pht('Manage'));60$crumbs->setBorder(true);616263$view = id(new PHUITwoColumnView())64->setHeader($header)65->setCurtain($curtain)66->setMainColumn(array(67$properties,68$document_view,69$timeline,70$comment_form,71));7273return $this->newPage()74->setTitle($title)75->setCrumbs($crumbs)76->setPageObjectPHIDs(array($document->getPHID()))77->appendChild($view);78}7980private function buildDocumentView(81LegalpadDocument $document,82PhabricatorMarkupEngine $engine) {8384$viewer = $this->getViewer();8586$view = id(new PHUIPropertyListView())87->setUser($viewer);88$document_body = $document->getDocumentBody();89$document_text = $engine->getOutput(90$document_body, LegalpadDocumentBody::MARKUP_FIELD_TEXT);9192$preamble_box = null;93if (strlen($document->getPreamble())) {94$preamble_text = new PHUIRemarkupView($viewer, $document->getPreamble());95$view->addTextContent($preamble_text);96$view->addSectionHeader('');97$view->addTextContent($document_text);98} else {99$view->addTextContent($document_text);100}101102return id(new PHUIObjectBoxView())103->setHeaderText(pht('DOCUMENT'))104->addPropertyList($view)105->setBackground(PHUIObjectBoxView::BLUE_PROPERTY);106}107108private function buildCurtainView(LegalpadDocument $document) {109$viewer = $this->getViewer();110111$curtain = $this->newCurtainView($document);112113$can_edit = PhabricatorPolicyFilter::hasCapability(114$viewer,115$document,116PhabricatorPolicyCapability::CAN_EDIT);117118$doc_id = $document->getID();119120$curtain->addAction(121id(new PhabricatorActionView())122->setIcon('fa-pencil-square')123->setName(pht('View/Sign Document'))124->setHref('/'.$document->getMonogram()));125126$curtain->addAction(127id(new PhabricatorActionView())128->setIcon('fa-pencil')129->setName(pht('Edit Document'))130->setHref($this->getApplicationURI('/edit/'.$doc_id.'/'))131->setDisabled(!$can_edit)132->setWorkflow(!$can_edit));133134$curtain->addAction(135id(new PhabricatorActionView())136->setIcon('fa-terminal')137->setName(pht('View Signatures'))138->setHref($this->getApplicationURI('/signatures/'.$doc_id.'/')));139140return $curtain;141}142143private function buildPropertyView(144LegalpadDocument $document,145PhabricatorMarkupEngine $engine) {146147$viewer = $this->getViewer();148149$properties = id(new PHUIPropertyListView())150->setUser($viewer);151152$properties->addProperty(153pht('Signature Type'),154$document->getSignatureTypeName());155156$properties->addProperty(157pht('Last Updated'),158phabricator_datetime($document->getDateModified(), $viewer));159160$properties->addProperty(161pht('Updated By'),162$viewer->renderHandle($document->getDocumentBody()->getCreatorPHID()));163164$properties->addProperty(165pht('Versions'),166$document->getVersions());167168if ($document->getContributors()) {169$properties->addProperty(170pht('Contributors'),171$viewer172->renderHandleList($document->getContributors())173->setAsInline(true));174}175176return id(new PHUIObjectBoxView())177->setHeaderText(pht('Properties'))178->addPropertyList($properties)179->setBackground(PHUIObjectBoxView::BLUE_PROPERTY);180}181182private function buildCommentView(LegalpadDocument $document, $timeline) {183$viewer = $this->getViewer();184$box = id(new LegalpadDocumentEditEngine())185->setViewer($viewer)186->buildEditEngineCommentView($document)187->setTransactionTimeline($timeline);188189return $box;190}191192}193194195