Path: blob/master/src/applications/legalpad/editor/LegalpadDocumentEditor.php
13452 views
<?php12final class LegalpadDocumentEditor3extends PhabricatorApplicationTransactionEditor {45public function getEditorApplicationClass() {6return 'PhabricatorLegalpadApplication';7}89public function getEditorObjectsDescription() {10return pht('Legalpad Documents');11}1213public function getTransactionTypes() {14$types = parent::getTransactionTypes();1516$types[] = PhabricatorTransactions::TYPE_COMMENT;17$types[] = PhabricatorTransactions::TYPE_VIEW_POLICY;18$types[] = PhabricatorTransactions::TYPE_EDIT_POLICY;1920return $types;21}2223public function getCreateObjectTitle($author, $object) {24return pht('%s created this document.', $author);25}2627public function getCreateObjectTitleForFeed($author, $object) {28return pht('%s created %s.', $author, $object);29}3031protected function applyFinalEffects(32PhabricatorLiskDAO $object,33array $xactions) {3435$is_contribution = false;3637foreach ($xactions as $xaction) {38switch ($xaction->getTransactionType()) {39case LegalpadDocumentTitleTransaction::TRANSACTIONTYPE:40case LegalpadDocumentTextTransaction::TRANSACTIONTYPE:41$is_contribution = true;42break;43}44}4546if ($is_contribution) {47$text = $object->getDocumentBody()->getText();48$title = $object->getDocumentBody()->getTitle();49$object->setVersions($object->getVersions() + 1);5051$body = new LegalpadDocumentBody();52$body->setCreatorPHID($this->getActingAsPHID());53$body->setText($text);54$body->setTitle($title);55$body->setVersion($object->getVersions());56$body->setDocumentPHID($object->getPHID());57$body->save();5859$object->setDocumentBodyPHID($body->getPHID());6061$type = PhabricatorContributedToObjectEdgeType::EDGECONST;62id(new PhabricatorEdgeEditor())63->addEdge($this->getActingAsPHID(), $type, $object->getPHID())64->save();6566$type = PhabricatorObjectHasContributorEdgeType::EDGECONST;67$contributors = PhabricatorEdgeQuery::loadDestinationPHIDs(68$object->getPHID(),69$type);70$object->setRecentContributorPHIDs(array_slice($contributors, 0, 3));71$object->setContributorCount(count($contributors));7273$object->save();74}7576return $xactions;77}7879protected function validateAllTransactions(PhabricatorLiskDAO $object,80array $xactions) {81$errors = array();8283$is_required = (bool)$object->getRequireSignature();84$document_type = $object->getSignatureType();85$individual = LegalpadDocument::SIGNATURE_TYPE_INDIVIDUAL;8687foreach ($xactions as $xaction) {88switch ($xaction->getTransactionType()) {89case LegalpadDocumentRequireSignatureTransaction::TRANSACTIONTYPE:90$is_required = (bool)$xaction->getNewValue();91break;92case LegalpadDocumentSignatureTypeTransaction::TRANSACTIONTYPE:93$document_type = $xaction->getNewValue();94break;95}96}9798if ($is_required && ($document_type != $individual)) {99$errors[] = new PhabricatorApplicationTransactionValidationError(100LegalpadDocumentRequireSignatureTransaction::TRANSACTIONTYPE,101pht('Invalid'),102pht('Only documents with signature type "individual" may '.103'require signing to log in.'),104null);105}106107return $errors;108}109110111/* -( Sending Mail )------------------------------------------------------- */112113protected function shouldSendMail(114PhabricatorLiskDAO $object,115array $xactions) {116return true;117}118119protected function buildReplyHandler(PhabricatorLiskDAO $object) {120return id(new LegalpadReplyHandler())121->setMailReceiver($object);122}123124protected function buildMailTemplate(PhabricatorLiskDAO $object) {125$id = $object->getID();126$title = $object->getDocumentBody()->getTitle();127128return id(new PhabricatorMetaMTAMail())129->setSubject("L{$id}: {$title}");130}131132protected function getMailTo(PhabricatorLiskDAO $object) {133return array(134$object->getCreatorPHID(),135$this->requireActor()->getPHID(),136);137}138139protected function shouldImplyCC(140PhabricatorLiskDAO $object,141PhabricatorApplicationTransaction $xaction) {142143switch ($xaction->getTransactionType()) {144case LegalpadDocumentTextTransaction::TRANSACTIONTYPE:145case LegalpadDocumentTitleTransaction::TRANSACTIONTYPE:146case LegalpadDocumentPreambleTransaction::TRANSACTIONTYPE:147case LegalpadDocumentRequireSignatureTransaction::TRANSACTIONTYPE:148return true;149}150151return parent::shouldImplyCC($object, $xaction);152}153154protected function buildMailBody(155PhabricatorLiskDAO $object,156array $xactions) {157158$body = parent::buildMailBody($object, $xactions);159160$body->addLinkSection(161pht('DOCUMENT DETAIL'),162PhabricatorEnv::getProductionURI('/legalpad/view/'.$object->getID().'/'));163164return $body;165}166167protected function getMailSubjectPrefix() {168return pht('[Legalpad]');169}170171172protected function shouldPublishFeedStory(173PhabricatorLiskDAO $object,174array $xactions) {175return false;176}177178protected function supportsSearch() {179return false;180}181182}183184185