[ Index ]

PHP Cross Reference of Phabricator

title

Body

[close]

/src/applications/fund/storage/ -> FundInitiativeTransaction.php (source)

   1  <?php
   2  
   3  final class FundInitiativeTransaction
   4    extends PhabricatorApplicationTransaction {
   5  
   6    const TYPE_NAME = 'fund:name';
   7    const TYPE_DESCRIPTION = 'fund:description';
   8    const TYPE_RISKS = 'fund:risks';
   9    const TYPE_STATUS = 'fund:status';
  10    const TYPE_BACKER = 'fund:backer';
  11    const TYPE_REFUND = 'fund:refund';
  12    const TYPE_MERCHANT = 'fund:merchant';
  13  
  14    const MAILTAG_BACKER = 'fund.backer';
  15    const MAILTAG_STATUS = 'fund.status';
  16    const MAILTAG_OTHER  = 'fund.other';
  17  
  18    const PROPERTY_AMOUNT = 'fund.amount';
  19    const PROPERTY_BACKER = 'fund.backer';
  20  
  21    public function getApplicationName() {
  22      return 'fund';
  23    }
  24  
  25    public function getApplicationTransactionType() {
  26      return FundInitiativePHIDType::TYPECONST;
  27    }
  28  
  29    public function getApplicationTransactionCommentObject() {
  30      return null;
  31    }
  32  
  33    public function getRequiredHandlePHIDs() {
  34      $phids = parent::getRequiredHandlePHIDs();
  35  
  36      $old = $this->getOldValue();
  37      $new = $this->getNewValue();
  38  
  39      $type = $this->getTransactionType();
  40      switch ($type) {
  41        case FundInitiativeTransaction::TYPE_MERCHANT:
  42          if ($old) {
  43            $phids[] = $old;
  44          }
  45          if ($new) {
  46            $phids[] = $new;
  47          }
  48          break;
  49        case FundInitiativeTransaction::TYPE_REFUND:
  50          $phids[] = $this->getMetadataValue(self::PROPERTY_BACKER);
  51          break;
  52      }
  53  
  54      return $phids;
  55    }
  56  
  57    public function getTitle() {
  58      $author_phid = $this->getAuthorPHID();
  59      $object_phid = $this->getObjectPHID();
  60  
  61      $old = $this->getOldValue();
  62      $new = $this->getNewValue();
  63  
  64      $type = $this->getTransactionType();
  65      switch ($type) {
  66        case FundInitiativeTransaction::TYPE_NAME:
  67          if ($old === null) {
  68            return pht(
  69              '%s created this initiative.',
  70              $this->renderHandleLink($author_phid));
  71          } else {
  72            return pht(
  73              '%s renamed this initiative from "%s" to "%s".',
  74              $this->renderHandleLink($author_phid),
  75              $old,
  76              $new);
  77          }
  78          break;
  79        case FundInitiativeTransaction::TYPE_RISKS:
  80          return pht(
  81            '%s edited the risks for this initiative.',
  82            $this->renderHandleLink($author_phid));
  83        case FundInitiativeTransaction::TYPE_DESCRIPTION:
  84          return pht(
  85            '%s edited the description of this initiative.',
  86            $this->renderHandleLink($author_phid));
  87        case FundInitiativeTransaction::TYPE_STATUS:
  88          switch ($new) {
  89            case FundInitiative::STATUS_OPEN:
  90              return pht(
  91                '%s reopened this initiative.',
  92                $this->renderHandleLink($author_phid));
  93            case FundInitiative::STATUS_CLOSED:
  94              return pht(
  95                '%s closed this initiative.',
  96                $this->renderHandleLink($author_phid));
  97          }
  98          break;
  99        case FundInitiativeTransaction::TYPE_BACKER:
 100          $amount = $this->getMetadataValue(self::PROPERTY_AMOUNT);
 101          $amount = PhortuneCurrency::newFromString($amount);
 102          return pht(
 103            '%s backed this initiative with %s.',
 104            $this->renderHandleLink($author_phid),
 105            $amount->formatForDisplay());
 106        case FundInitiativeTransaction::TYPE_REFUND:
 107          $amount = $this->getMetadataValue(self::PROPERTY_AMOUNT);
 108          $amount = PhortuneCurrency::newFromString($amount);
 109  
 110          $backer_phid = $this->getMetadataValue(self::PROPERTY_BACKER);
 111  
 112          return pht(
 113            '%s refunded %s to %s.',
 114            $this->renderHandleLink($author_phid),
 115            $amount->formatForDisplay(),
 116            $this->renderHandleLink($backer_phid));
 117        case FundInitiativeTransaction::TYPE_MERCHANT:
 118          if ($old === null) {
 119            return pht(
 120              '%s set this initiative to pay to %s.',
 121              $this->renderHandleLink($author_phid),
 122              $this->renderHandleLink($new));
 123          } else {
 124            return pht(
 125              '%s changed the merchant receiving funds from this '.
 126              'initiative from %s to %s.',
 127              $this->renderHandleLink($author_phid),
 128              $this->renderHandleLink($old),
 129              $this->renderHandleLink($new));
 130          }
 131      }
 132  
 133      return parent::getTitle();
 134    }
 135  
 136    public function getTitleForFeed(PhabricatorFeedStory $story) {
 137      $author_phid = $this->getAuthorPHID();
 138      $object_phid = $this->getObjectPHID();
 139  
 140      $old = $this->getOldValue();
 141      $new = $this->getNewValue();
 142  
 143      $type = $this->getTransactionType();
 144      switch ($type) {
 145        case FundInitiativeTransaction::TYPE_NAME:
 146          if ($old === null) {
 147            return pht(
 148              '%s created %s.',
 149              $this->renderHandleLink($author_phid),
 150              $this->renderHandleLink($object_phid));
 151  
 152          } else {
 153            return pht(
 154              '%s renamed %s.',
 155              $this->renderHandleLink($author_phid),
 156              $this->renderHandleLink($object_phid));
 157          }
 158          break;
 159        case FundInitiativeTransaction::TYPE_DESCRIPTION:
 160          return pht(
 161            '%s updated the description for %s.',
 162            $this->renderHandleLink($author_phid),
 163            $this->renderHandleLink($object_phid));
 164        case FundInitiativeTransaction::TYPE_STATUS:
 165          switch ($new) {
 166            case FundInitiative::STATUS_OPEN:
 167              return pht(
 168                '%s reopened %s.',
 169                $this->renderHandleLink($author_phid),
 170                $this->renderHandleLink($object_phid));
 171            case FundInitiative::STATUS_CLOSED:
 172              return pht(
 173                '%s closed %s.',
 174                $this->renderHandleLink($author_phid),
 175                $this->renderHandleLink($object_phid));
 176          }
 177          break;
 178        case FundInitiativeTransaction::TYPE_BACKER:
 179          $amount = $this->getMetadataValue(self::PROPERTY_AMOUNT);
 180          $amount = PhortuneCurrency::newFromString($amount);
 181          return pht(
 182            '%s backed %s with %s.',
 183            $this->renderHandleLink($author_phid),
 184            $this->renderHandleLink($object_phid),
 185            $amount->formatForDisplay());
 186        case FundInitiativeTransaction::TYPE_REFUND:
 187          $amount = $this->getMetadataValue(self::PROPERTY_AMOUNT);
 188          $amount = PhortuneCurrency::newFromString($amount);
 189  
 190          $backer_phid = $this->getMetadataValue(self::PROPERTY_BACKER);
 191  
 192          return pht(
 193            '%s refunded %s to %s for %s.',
 194            $this->renderHandleLink($author_phid),
 195            $amount->formatForDisplay(),
 196            $this->renderHandleLink($backer_phid),
 197            $this->renderHandleLink($object_phid));
 198      }
 199  
 200      return parent::getTitleForFeed($story);
 201    }
 202  
 203    public function getMailTags() {
 204      $tags = parent::getMailTags();
 205  
 206      switch ($this->getTransactionType()) {
 207        case self::TYPE_STATUS:
 208          $tags[] = self::MAILTAG_STATUS;
 209          break;
 210        case self::TYPE_BACKER:
 211        case self::TYPE_REFUND:
 212          $tags[] = self::MAILTAG_BACKER;
 213          break;
 214        default:
 215          $tags[] = self::MAILTAG_OTHER;
 216          break;
 217      }
 218  
 219      return $tags;
 220    }
 221  
 222  
 223    public function shouldHide() {
 224      $old = $this->getOldValue();
 225      switch ($this->getTransactionType()) {
 226        case FundInitiativeTransaction::TYPE_DESCRIPTION:
 227        case FundInitiativeTransaction::TYPE_RISKS:
 228          return ($old === null);
 229      }
 230      return parent::shouldHide();
 231    }
 232  
 233    public function hasChangeDetails() {
 234      switch ($this->getTransactionType()) {
 235        case FundInitiativeTransaction::TYPE_DESCRIPTION:
 236        case FundInitiativeTransaction::TYPE_RISKS:
 237          return ($this->getOldValue() !== null);
 238      }
 239  
 240      return parent::hasChangeDetails();
 241    }
 242  
 243    public function renderChangeDetails(PhabricatorUser $viewer) {
 244      return $this->renderTextCorpusChangeDetails(
 245        $viewer,
 246        $this->getOldValue(),
 247        $this->getNewValue());
 248    }
 249  }


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