Something went wrong. Try again.
@recaptime-dev's working patches + fork for Phorge, a community fork of Phabricator. (Upstream dev and stable branches are at upstream/main and upstream/stable respectively.) hq.recaptime.dev/wiki/Phorge
phorge phabricator
Something went wrong. Try again.
5.5 kB · 193 lines
PHP
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194<?php
final class LegalpadDocumentManageController extends LegalpadController {
public function handleRequest(AphrontRequest $request) { $viewer = $request->getViewer(); $id = $request->getURIData('id');
// NOTE: We require CAN_EDIT to view this page.
$document = id(new LegalpadDocumentQuery()) ->setViewer($viewer) ->withIDs(array($id)) ->needDocumentBodies(true) ->needContributors(true) ->requireCapabilities( array( PhabricatorPolicyCapability::CAN_VIEW, PhabricatorPolicyCapability::CAN_EDIT, )) ->executeOne(); if (!$document) { return new Aphront404Response(); }
$subscribers = PhabricatorSubscribersQuery::loadSubscribersForPHID( $document->getPHID());
$document_body = $document->getDocumentBody();
$engine = id(new PhabricatorMarkupEngine()) ->setViewer($viewer); $engine->addObject( $document_body, LegalpadDocumentBody::MARKUP_FIELD_TEXT); $timeline = $this->buildTransactionTimeline( $document, new LegalpadTransactionQuery(), $engine); $timeline->setQuoteRef($document->getMonogram());
$title = $document_body->getTitle();
$header = id(new PHUIHeaderView()) ->setHeader($title) ->setViewer($viewer) ->setPolicyObject($document) ->setHeaderIcon('fa-gavel');
$curtain = $this->buildCurtainView($document); $properties = $this->buildPropertyView($document, $engine); $document_view = $this->buildDocumentView($document, $engine);
$comment_form = $this->buildCommentView($document, $timeline);
$crumbs = $this->buildApplicationCrumbs(); $crumbs->addTextCrumb( $document->getMonogram(), '/'.$document->getMonogram()); $crumbs->addTextCrumb(pht('Manage')); $crumbs->setBorder(true);
$view = id(new PHUITwoColumnView()) ->setHeader($header) ->setCurtain($curtain) ->setMainColumn(array( $properties, $document_view, $timeline, $comment_form, ));
return $this->newPage() ->setTitle($title) ->setCrumbs($crumbs) ->setPageObjectPHIDs(array($document->getPHID())) ->appendChild($view); }
private function buildDocumentView( LegalpadDocument $document, PhabricatorMarkupEngine $engine) {
$viewer = $this->getViewer();
$view = id(new PHUIPropertyListView()) ->setViewer($viewer); $document_body = $document->getDocumentBody(); $document_text = $engine->getOutput( $document_body, LegalpadDocumentBody::MARKUP_FIELD_TEXT);
$preamble_box = null; if (strlen($document->getPreamble())) { $preamble_text = new PHUIRemarkupView($viewer, $document->getPreamble()); $view->addTextContent($preamble_text); $view->addSectionHeader(''); $view->addTextContent($document_text); } else { $view->addTextContent($document_text); }
return id(new PHUIObjectBoxView()) ->setHeaderText(pht('DOCUMENT')) ->addPropertyList($view) ->setBackground(PHUIObjectBoxView::BLUE_PROPERTY); }
private function buildCurtainView(LegalpadDocument $document) { $viewer = $this->getViewer();
$curtain = $this->newCurtainView($document);
$can_edit = PhabricatorPolicyFilter::hasCapability( $viewer, $document, PhabricatorPolicyCapability::CAN_EDIT);
$doc_id = $document->getID();
$curtain->addAction( id(new PhabricatorActionView()) ->setIcon('fa-pencil-square') ->setName(pht('View/Sign Document')) ->setHref('/'.$document->getMonogram()));
$curtain->addAction( id(new PhabricatorActionView()) ->setIcon('fa-pencil') ->setName(pht('Edit Document')) ->setHref($this->getApplicationURI('/edit/'.$doc_id.'/')) ->setDisabled(!$can_edit) ->setWorkflow(!$can_edit));
$curtain->addAction( id(new PhabricatorActionView()) ->setIcon('fa-terminal') ->setName(pht('View Signatures')) ->setHref($this->getApplicationURI('/signatures/'.$doc_id.'/')));
return $curtain; }
private function buildPropertyView( LegalpadDocument $document, PhabricatorMarkupEngine $engine) {
$viewer = $this->getViewer();
$properties = id(new PHUIPropertyListView()) ->setViewer($viewer);
$properties->addProperty( pht('Signature Type'), $document->getSignatureTypeName());
$properties->addProperty( pht('Last Updated'), phabricator_datetime($document->getDateModified(), $viewer));
$properties->addProperty( pht('Updated By'), $viewer->renderHandle($document->getDocumentBody()->getCreatorPHID()));
$properties->addProperty( pht('Versions'), $document->getVersions());
if ($document->getContributors()) { $properties->addProperty( pht('Contributors'), $viewer ->renderHandleList($document->getContributors()) ->setAsInline(true)); }
return id(new PHUIObjectBoxView()) ->setHeaderText(pht('Properties')) ->addPropertyList($properties) ->setBackground(PHUIObjectBoxView::BLUE_PROPERTY); }
private function buildCommentView(LegalpadDocument $document, $timeline) { $viewer = $this->getViewer(); $box = id(new LegalpadDocumentEditEngine()) ->setViewer($viewer) ->buildEditEngineCommentView($document) ->setTransactionTimeline($timeline);
return $box; }
}