[ Index ]

PHP Cross Reference of Phabricator

title

Body

[close]

/src/applications/macro/storage/ -> PhabricatorMacroTransaction.php (source)

   1  <?php
   2  
   3  final class PhabricatorMacroTransaction
   4    extends PhabricatorApplicationTransaction {
   5  
   6    public function getApplicationName() {
   7      return 'file';
   8    }
   9  
  10    public function getTableName() {
  11      return 'macro_transaction';
  12    }
  13  
  14    public function getApplicationTransactionType() {
  15      return PhabricatorMacroMacroPHIDType::TYPECONST;
  16    }
  17  
  18    public function getApplicationTransactionCommentObject() {
  19      return new PhabricatorMacroTransactionComment();
  20    }
  21  
  22    public function getRequiredHandlePHIDs() {
  23      $phids = parent::getRequiredHandlePHIDs();
  24  
  25      $old = $this->getOldValue();
  26      $new = $this->getNewValue();
  27  
  28      switch ($this->getTransactionType()) {
  29        case PhabricatorMacroTransactionType::TYPE_FILE:
  30        case PhabricatorMacroTransactionType::TYPE_AUDIO:
  31          if ($old !== null) {
  32            $phids[] = $old;
  33          }
  34          $phids[] = $new;
  35          break;
  36      }
  37  
  38      return $phids;
  39    }
  40  
  41    public function shouldHide() {
  42      $old = $this->getOldValue();
  43      $new = $this->getNewValue();
  44  
  45      switch ($this->getTransactionType()) {
  46        case PhabricatorMacroTransactionType::TYPE_NAME:
  47          return ($old === null);
  48      }
  49  
  50      return parent::shouldHide();
  51    }
  52  
  53    public function getTitle() {
  54      $author_phid = $this->getAuthorPHID();
  55  
  56      $old = $this->getOldValue();
  57      $new = $this->getNewValue();
  58  
  59      switch ($this->getTransactionType()) {
  60        case PhabricatorMacroTransactionType::TYPE_NAME:
  61          return pht(
  62            '%s renamed this macro from "%s" to "%s".',
  63            $this->renderHandleLink($author_phid),
  64            $old,
  65            $new);
  66          break;
  67        case PhabricatorMacroTransactionType::TYPE_DISABLED:
  68          if ($new) {
  69            return pht(
  70              '%s disabled this macro.',
  71              $this->renderHandleLink($author_phid));
  72          } else {
  73            return pht(
  74              '%s restored this macro.',
  75              $this->renderHandleLink($author_phid));
  76          }
  77          break;
  78  
  79        case PhabricatorMacroTransactionType::TYPE_AUDIO:
  80          if (!$old) {
  81            return pht(
  82              '%s attached audio: %s.',
  83              $this->renderHandleLink($author_phid),
  84              $this->renderHandleLink($new));
  85          } else {
  86            return pht(
  87              '%s changed the audio for this macro from %s to %s.',
  88              $this->renderHandleLink($author_phid),
  89              $this->renderHandleLink($old),
  90              $this->renderHandleLink($new));
  91          }
  92  
  93        case PhabricatorMacroTransactionType::TYPE_AUDIO_BEHAVIOR:
  94          switch ($new) {
  95            case PhabricatorFileImageMacro::AUDIO_BEHAVIOR_ONCE:
  96              return pht(
  97                '%s set the audio to play once.',
  98                $this->renderHandleLink($author_phid));
  99            case PhabricatorFileImageMacro::AUDIO_BEHAVIOR_LOOP:
 100              return pht(
 101                '%s set the audio to loop.',
 102                $this->renderHandleLink($author_phid));
 103            default:
 104              return pht(
 105                '%s disabled the audio for this macro.',
 106                $this->renderHandleLink($author_phid));
 107          }
 108  
 109        case PhabricatorMacroTransactionType::TYPE_FILE:
 110          if ($old === null) {
 111            return pht(
 112              '%s created this macro.',
 113              $this->renderHandleLink($author_phid));
 114          } else {
 115            return pht(
 116              '%s changed the image for this macro from %s to %s.',
 117              $this->renderHandleLink($author_phid),
 118              $this->renderHandleLink($old),
 119              $this->renderHandleLink($new));
 120          }
 121          break;
 122      }
 123  
 124      return parent::getTitle();
 125    }
 126  
 127    public function getTitleForFeed(PhabricatorFeedStory $story) {
 128      $author_phid = $this->getAuthorPHID();
 129      $object_phid = $this->getObjectPHID();
 130  
 131      $old = $this->getOldValue();
 132      $new = $this->getNewValue();
 133  
 134      switch ($this->getTransactionType()) {
 135        case PhabricatorMacroTransactionType::TYPE_NAME:
 136          return pht(
 137            '%s renamed %s from "%s" to "%s".',
 138            $this->renderHandleLink($author_phid),
 139            $this->renderHandleLink($object_phid),
 140            $old,
 141            $new);
 142        case PhabricatorMacroTransactionType::TYPE_DISABLED:
 143          if ($new) {
 144            return pht(
 145              '%s disabled %s.',
 146              $this->renderHandleLink($author_phid),
 147              $this->renderHandleLink($object_phid));
 148          } else {
 149            return pht(
 150              '%s restored %s.',
 151              $this->renderHandleLink($author_phid),
 152              $this->renderHandleLink($object_phid));
 153          }
 154        case PhabricatorMacroTransactionType::TYPE_FILE:
 155          if ($old === null) {
 156            return pht(
 157              '%s created %s.',
 158              $this->renderHandleLink($author_phid),
 159              $this->renderHandleLink($object_phid));
 160          } else {
 161            return pht(
 162              '%s updated the image for %s.',
 163              $this->renderHandleLink($author_phid),
 164              $this->renderHandleLink($object_phid));
 165          }
 166  
 167        case PhabricatorMacroTransactionType::TYPE_AUDIO:
 168          if (!$old) {
 169            return pht(
 170              '%s attached audio to %s: %s.',
 171              $this->renderHandleLink($author_phid),
 172              $this->renderHandleLink($object_phid),
 173              $this->renderHandleLink($new));
 174          } else {
 175            return pht(
 176              '%s changed the audio for %s from %s to %s.',
 177              $this->renderHandleLink($author_phid),
 178              $this->renderHandleLink($object_phid),
 179              $this->renderHandleLink($old),
 180              $this->renderHandleLink($new));
 181          }
 182  
 183        case PhabricatorMacroTransactionType::TYPE_AUDIO_BEHAVIOR:
 184          switch ($new) {
 185            case PhabricatorFileImageMacro::AUDIO_BEHAVIOR_ONCE:
 186              return pht(
 187                '%s set the audio for %s to play once.',
 188                $this->renderHandleLink($author_phid),
 189                $this->renderHandleLink($object_phid));
 190            case PhabricatorFileImageMacro::AUDIO_BEHAVIOR_LOOP:
 191              return pht(
 192                '%s set the audio for %s to loop.',
 193                $this->renderHandleLink($author_phid),
 194                $this->renderHandleLink($object_phid));
 195            default:
 196              return pht(
 197                '%s disabled the audio for %s.',
 198                $this->renderHandleLink($author_phid),
 199                $this->renderHandleLink($object_phid));
 200          }
 201  
 202      }
 203  
 204      return parent::getTitleForFeed($story);
 205    }
 206  
 207    public function getActionName() {
 208      $old = $this->getOldValue();
 209      $new = $this->getNewValue();
 210  
 211      switch ($this->getTransactionType()) {
 212        case PhabricatorMacroTransactionType::TYPE_NAME:
 213          if ($old === null) {
 214            return pht('Created');
 215          } else {
 216            return pht('Renamed');
 217          }
 218        case PhabricatorMacroTransactionType::TYPE_DISABLED:
 219          if ($new) {
 220            return pht('Disabled');
 221          } else {
 222            return pht('Restored');
 223          }
 224        case PhabricatorMacroTransactionType::TYPE_FILE:
 225          if ($old === null) {
 226            return pht('Created');
 227          } else {
 228            return pht('Edited Image');
 229          }
 230  
 231        case PhabricatorMacroTransactionType::TYPE_AUDIO:
 232          return pht('Audio');
 233  
 234        case PhabricatorMacroTransactionType::TYPE_AUDIO_BEHAVIOR:
 235          return pht('Audio Behavior');
 236  
 237      }
 238  
 239      return parent::getActionName();
 240    }
 241  
 242    public function getActionStrength() {
 243      switch ($this->getTransactionType()) {
 244        case PhabricatorMacroTransactionType::TYPE_DISABLED:
 245          return 2.0;
 246        case PhabricatorMacroTransactionType::TYPE_FILE:
 247          return 1.5;
 248      }
 249      return parent::getActionStrength();
 250    }
 251  
 252    public function getIcon() {
 253      $old = $this->getOldValue();
 254      $new = $this->getNewValue();
 255  
 256      switch ($this->getTransactionType()) {
 257        case PhabricatorMacroTransactionType::TYPE_NAME:
 258          return 'fa-pencil';
 259        case PhabricatorMacroTransactionType::TYPE_FILE:
 260          if ($old === null) {
 261            return 'fa-plus';
 262          } else {
 263            return 'fa-pencil';
 264          }
 265        case PhabricatorMacroTransactionType::TYPE_DISABLED:
 266          if ($new) {
 267            return 'fa-times';
 268          } else {
 269            return 'fa-undo';
 270          }
 271        case PhabricatorMacroTransactionType::TYPE_AUDIO:
 272          return 'fa-headphones';
 273      }
 274  
 275      return parent::getIcon();
 276    }
 277  
 278    public function getColor() {
 279      $old = $this->getOldValue();
 280      $new = $this->getNewValue();
 281  
 282      switch ($this->getTransactionType()) {
 283        case PhabricatorMacroTransactionType::TYPE_NAME:
 284          return PhabricatorTransactions::COLOR_BLUE;
 285        case PhabricatorMacroTransactionType::TYPE_FILE:
 286          if ($old === null) {
 287            return PhabricatorTransactions::COLOR_GREEN;
 288          } else {
 289            return PhabricatorTransactions::COLOR_BLUE;
 290          }
 291        case PhabricatorMacroTransactionType::TYPE_DISABLED:
 292          if ($new) {
 293            return PhabricatorTransactions::COLOR_BLACK;
 294          } else {
 295            return PhabricatorTransactions::COLOR_SKY;
 296          }
 297      }
 298  
 299      return parent::getColor();
 300    }
 301  
 302  
 303  }


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