[ Index ]

PHP Cross Reference of Phabricator

title

Body

[close]

/src/applications/slowvote/storage/ -> PhabricatorSlowvoteTransaction.php (source)

   1  <?php
   2  
   3  final class PhabricatorSlowvoteTransaction
   4    extends PhabricatorApplicationTransaction {
   5  
   6    const TYPE_QUESTION     = 'vote:question';
   7    const TYPE_DESCRIPTION  = 'vote:description';
   8    const TYPE_RESPONSES    = 'vote:responses';
   9    const TYPE_SHUFFLE      = 'vote:shuffle';
  10    const TYPE_CLOSE        = 'vote:close';
  11  
  12    public function getApplicationName() {
  13      return 'slowvote';
  14    }
  15  
  16    public function getApplicationTransactionType() {
  17      return PhabricatorSlowvotePollPHIDType::TYPECONST;
  18    }
  19  
  20    public function getApplicationTransactionCommentObject() {
  21      return new PhabricatorSlowvoteTransactionComment();
  22    }
  23  
  24    public function shouldHide() {
  25      $old = $this->getOldValue();
  26      $new = $this->getNewValue();
  27  
  28      switch ($this->getTransactionType()) {
  29        case PhabricatorSlowvoteTransaction::TYPE_DESCRIPTION:
  30        case PhabricatorSlowvoteTransaction::TYPE_RESPONSES:
  31        case PhabricatorSlowvoteTransaction::TYPE_SHUFFLE:
  32        case PhabricatorSlowvoteTransaction::TYPE_CLOSE:
  33          return ($old === null);
  34      }
  35  
  36      return parent::shouldHide();
  37    }
  38  
  39    public function getTitle() {
  40      $author_phid = $this->getAuthorPHID();
  41  
  42      $old = $this->getOldValue();
  43      $new = $this->getNewValue();
  44  
  45      switch ($this->getTransactionType()) {
  46        case PhabricatorSlowvoteTransaction::TYPE_QUESTION:
  47          if ($old === null) {
  48            return pht(
  49              '%s created this poll.',
  50              $this->renderHandleLink($author_phid));
  51          } else {
  52            return pht(
  53              '%s changed the poll question from "%s" to "%s".',
  54              $this->renderHandleLink($author_phid),
  55              $old,
  56              $new);
  57          }
  58          break;
  59        case PhabricatorSlowvoteTransaction::TYPE_DESCRIPTION:
  60          return pht(
  61            '%s updated the description for this poll.',
  62            $this->renderHandleLink($author_phid));
  63        case PhabricatorSlowvoteTransaction::TYPE_RESPONSES:
  64          // TODO: This could be more detailed
  65          return pht(
  66            '%s changed who can see the responses.',
  67            $this->renderHandleLink($author_phid));
  68        case PhabricatorSlowvoteTransaction::TYPE_SHUFFLE:
  69          if ($new) {
  70            return pht(
  71              '%s made poll responses appear in a random order.',
  72              $this->renderHandleLink($author_phid));
  73          } else {
  74            return pht(
  75              '%s made poll responses appear in a fixed order.',
  76              $this->renderHandleLink($author_phid));
  77          }
  78          break;
  79        case PhabricatorSlowvoteTransaction::TYPE_CLOSE:
  80          if ($new) {
  81            return pht(
  82              '%s closed this poll.',
  83              $this->renderHandleLink($author_phid));
  84          } else {
  85            return pht(
  86              '%s reopened this poll.',
  87              $this->renderHandleLink($author_phid));
  88          }
  89  
  90          break;
  91      }
  92  
  93      return parent::getTitle();
  94    }
  95  
  96    public function getIcon() {
  97      $old = $this->getOldValue();
  98      $new = $this->getNewValue();
  99  
 100      switch ($this->getTransactionType()) {
 101        case PhabricatorSlowvoteTransaction::TYPE_QUESTION:
 102          if ($old === null) {
 103            return 'fa-plus';
 104          } else {
 105            return 'fa-pencil';
 106          }
 107        case PhabricatorSlowvoteTransaction::TYPE_DESCRIPTION:
 108        case PhabricatorSlowvoteTransaction::TYPE_RESPONSES:
 109          return 'fa-pencil';
 110        case PhabricatorSlowvoteTransaction::TYPE_SHUFFLE:
 111          return 'fa-refresh';
 112        case PhabricatorSlowvoteTransaction::TYPE_CLOSE:
 113          if ($new) {
 114            return 'fa-ban';
 115          } else {
 116            return 'fa-pencil';
 117          }
 118      }
 119  
 120      return parent::getIcon();
 121    }
 122  
 123  
 124    public function getColor() {
 125      $old = $this->getOldValue();
 126      $new = $this->getNewValue();
 127  
 128      switch ($this->getTransactionType()) {
 129        case PhabricatorSlowvoteTransaction::TYPE_QUESTION:
 130        case PhabricatorSlowvoteTransaction::TYPE_DESCRIPTION:
 131        case PhabricatorSlowvoteTransaction::TYPE_RESPONSES:
 132        case PhabricatorSlowvoteTransaction::TYPE_SHUFFLE:
 133        case PhabricatorSlowvoteTransaction::TYPE_CLOSE:
 134          return PhabricatorTransactions::COLOR_BLUE;
 135      }
 136  
 137      return parent::getColor();
 138    }
 139  
 140    public function hasChangeDetails() {
 141      switch ($this->getTransactionType()) {
 142        case PhabricatorSlowvoteTransaction::TYPE_DESCRIPTION:
 143          return true;
 144      }
 145      return parent::hasChangeDetails();
 146    }
 147  
 148    public function renderChangeDetails(PhabricatorUser $viewer) {
 149      return $this->renderTextCorpusChangeDetails($viewer);
 150    }
 151  
 152  
 153  }


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