[ Index ]

PHP Cross Reference of Phabricator

title

Body

[close]

/src/applications/legalpad/editor/ -> LegalpadDocumentEditor.php (source)

   1  <?php
   2  
   3  final class LegalpadDocumentEditor
   4    extends PhabricatorApplicationTransactionEditor {
   5  
   6    private $isContribution = false;
   7  
   8    public function getEditorApplicationClass() {
   9      return 'PhabricatorLegalpadApplication';
  10    }
  11  
  12    public function getEditorObjectsDescription() {
  13      return pht('Legalpad Documents');
  14    }
  15  
  16    private function setIsContribution($is_contribution) {
  17      $this->isContribution = $is_contribution;
  18    }
  19  
  20    private function isContribution() {
  21      return $this->isContribution;
  22    }
  23  
  24    public function getTransactionTypes() {
  25      $types = parent::getTransactionTypes();
  26  
  27      $types[] = PhabricatorTransactions::TYPE_COMMENT;
  28      $types[] = PhabricatorTransactions::TYPE_VIEW_POLICY;
  29      $types[] = PhabricatorTransactions::TYPE_EDIT_POLICY;
  30  
  31      $types[] = LegalpadTransactionType::TYPE_TITLE;
  32      $types[] = LegalpadTransactionType::TYPE_TEXT;
  33      $types[] = LegalpadTransactionType::TYPE_SIGNATURE_TYPE;
  34      $types[] = LegalpadTransactionType::TYPE_PREAMBLE;
  35  
  36      return $types;
  37    }
  38  
  39    protected function getCustomTransactionOldValue(
  40      PhabricatorLiskDAO $object,
  41      PhabricatorApplicationTransaction $xaction) {
  42  
  43      switch ($xaction->getTransactionType()) {
  44        case LegalpadTransactionType::TYPE_TITLE:
  45          return $object->getDocumentBody()->getTitle();
  46        case LegalpadTransactionType::TYPE_TEXT:
  47          return $object->getDocumentBody()->getText();
  48        case LegalpadTransactionType::TYPE_SIGNATURE_TYPE:
  49          return $object->getSignatureType();
  50        case LegalpadTransactionType::TYPE_PREAMBLE:
  51          return $object->getPreamble();
  52      }
  53    }
  54  
  55    protected function getCustomTransactionNewValue(
  56      PhabricatorLiskDAO $object,
  57      PhabricatorApplicationTransaction $xaction) {
  58  
  59      switch ($xaction->getTransactionType()) {
  60        case LegalpadTransactionType::TYPE_TITLE:
  61        case LegalpadTransactionType::TYPE_TEXT:
  62        case LegalpadTransactionType::TYPE_SIGNATURE_TYPE:
  63        case LegalpadTransactionType::TYPE_PREAMBLE:
  64          return $xaction->getNewValue();
  65      }
  66    }
  67  
  68    protected function applyCustomInternalTransaction(
  69      PhabricatorLiskDAO $object,
  70      PhabricatorApplicationTransaction $xaction) {
  71  
  72      switch ($xaction->getTransactionType()) {
  73        case LegalpadTransactionType::TYPE_TITLE:
  74          $object->setTitle($xaction->getNewValue());
  75          $body = $object->getDocumentBody();
  76          $body->setTitle($xaction->getNewValue());
  77          $this->setIsContribution(true);
  78          break;
  79        case LegalpadTransactionType::TYPE_TEXT:
  80          $body = $object->getDocumentBody();
  81          $body->setText($xaction->getNewValue());
  82          $this->setIsContribution(true);
  83          break;
  84        case LegalpadTransactionType::TYPE_SIGNATURE_TYPE:
  85          $object->setSignatureType($xaction->getNewValue());
  86          break;
  87        case LegalpadTransactionType::TYPE_PREAMBLE:
  88          $object->setPreamble($xaction->getNewValue());
  89          break;
  90      }
  91    }
  92  
  93    protected function applyCustomExternalTransaction(
  94      PhabricatorLiskDAO $object,
  95      PhabricatorApplicationTransaction $xaction) {
  96      return;
  97    }
  98  
  99    protected function applyFinalEffects(
 100      PhabricatorLiskDAO $object,
 101      array $xactions) {
 102  
 103      if ($this->isContribution()) {
 104        $object->setVersions($object->getVersions() + 1);
 105        $body = $object->getDocumentBody();
 106        $body->setVersion($object->getVersions());
 107        $body->setDocumentPHID($object->getPHID());
 108        $body->save();
 109  
 110        $object->setDocumentBodyPHID($body->getPHID());
 111  
 112        $actor = $this->getActor();
 113        $type = PhabricatorEdgeConfig::TYPE_CONTRIBUTED_TO_OBJECT;
 114        id(new PhabricatorEdgeEditor())
 115          ->addEdge($actor->getPHID(), $type, $object->getPHID())
 116          ->save();
 117  
 118        $type = PhabricatorEdgeConfig::TYPE_OBJECT_HAS_CONTRIBUTOR;
 119        $contributors = PhabricatorEdgeQuery::loadDestinationPHIDs(
 120          $object->getPHID(),
 121          $type);
 122        $object->setRecentContributorPHIDs(array_slice($contributors, 0, 3));
 123        $object->setContributorCount(count($contributors));
 124  
 125        $object->save();
 126      }
 127  
 128      return $xactions;
 129    }
 130  
 131    protected function mergeTransactions(
 132      PhabricatorApplicationTransaction $u,
 133      PhabricatorApplicationTransaction $v) {
 134  
 135      $type = $u->getTransactionType();
 136      switch ($type) {
 137        case LegalpadTransactionType::TYPE_TITLE:
 138        case LegalpadTransactionType::TYPE_TEXT:
 139        case LegalpadTransactionType::TYPE_SIGNATURE_TYPE:
 140        case LegalpadTransactionType::TYPE_PREAMBLE:
 141          return $v;
 142      }
 143  
 144      return parent::mergeTransactions($u, $v);
 145    }
 146  
 147  /* -(  Sending Mail  )------------------------------------------------------- */
 148  
 149    protected function shouldSendMail(
 150      PhabricatorLiskDAO $object,
 151      array $xactions) {
 152      return true;
 153    }
 154  
 155    protected function buildReplyHandler(PhabricatorLiskDAO $object) {
 156      return id(new LegalpadReplyHandler())
 157        ->setMailReceiver($object);
 158    }
 159  
 160    protected function buildMailTemplate(PhabricatorLiskDAO $object) {
 161      $id = $object->getID();
 162      $phid = $object->getPHID();
 163      $title = $object->getDocumentBody()->getTitle();
 164  
 165      return id(new PhabricatorMetaMTAMail())
 166        ->setSubject("L{$id}: {$title}")
 167        ->addHeader('Thread-Topic', "L{$id}: {$phid}");
 168    }
 169  
 170    protected function getMailTo(PhabricatorLiskDAO $object) {
 171      return array(
 172        $object->getCreatorPHID(),
 173        $this->requireActor()->getPHID(),
 174      );
 175    }
 176  
 177    protected function shouldImplyCC(
 178      PhabricatorLiskDAO $object,
 179      PhabricatorApplicationTransaction $xaction) {
 180  
 181      switch ($xaction->getTransactionType()) {
 182        case LegalpadTransactionType::TYPE_TEXT:
 183        case LegalpadTransactionType::TYPE_TITLE:
 184        case LegalpadTransactionType::TYPE_PREAMBLE:
 185          return true;
 186      }
 187  
 188      return parent::shouldImplyCC($object, $xaction);
 189    }
 190  
 191    protected function buildMailBody(
 192      PhabricatorLiskDAO $object,
 193      array $xactions) {
 194  
 195      $body = parent::buildMailBody($object, $xactions);
 196  
 197      $body->addLinkSection(
 198        pht('DOCUMENT DETAIL'),
 199        PhabricatorEnv::getProductionURI('/legalpad/view/'.$object->getID().'/'));
 200  
 201      return $body;
 202    }
 203  
 204    protected function getMailSubjectPrefix() {
 205      return PhabricatorEnv::getEnvConfig('metamta.legalpad.subject-prefix');
 206    }
 207  
 208  
 209    protected function shouldPublishFeedStory(
 210      PhabricatorLiskDAO $object,
 211      array $xactions) {
 212      return false;
 213    }
 214  
 215    protected function supportsSearch() {
 216      return false;
 217    }
 218  
 219  }


Generated: Sun Nov 30 09:20:46 2014 Cross-referenced by PHPXref 0.7.1