[ Index ]

PHP Cross Reference of Phabricator

title

Body

[close]

/src/applications/project/storage/ -> PhabricatorProjectTransaction.php (source)

   1  <?php
   2  
   3  final class PhabricatorProjectTransaction
   4    extends PhabricatorApplicationTransaction {
   5  
   6    const TYPE_NAME       = 'project:name';
   7    const TYPE_SLUGS      = 'project:slugs';
   8    const TYPE_STATUS     = 'project:status';
   9    const TYPE_IMAGE      = 'project:image';
  10    const TYPE_ICON       = 'project:icon';
  11    const TYPE_COLOR      = 'project:color';
  12    const TYPE_LOCKED     = 'project:locked';
  13  
  14    // NOTE: This is deprecated, members are just a normal edge now.
  15    const TYPE_MEMBERS    = 'project:members';
  16  
  17    public function getApplicationName() {
  18      return 'project';
  19    }
  20  
  21    public function getApplicationTransactionType() {
  22      return PhabricatorProjectProjectPHIDType::TYPECONST;
  23    }
  24  
  25    public function getRequiredHandlePHIDs() {
  26      $old = $this->getOldValue();
  27      $new = $this->getNewValue();
  28  
  29      $req_phids = array();
  30      switch ($this->getTransactionType()) {
  31        case PhabricatorProjectTransaction::TYPE_MEMBERS:
  32          $add = array_diff($new, $old);
  33          $rem = array_diff($old, $new);
  34          $req_phids = array_merge($add, $rem);
  35          break;
  36        case PhabricatorProjectTransaction::TYPE_IMAGE:
  37          $req_phids[] = $old;
  38          $req_phids[] = $new;
  39          break;
  40      }
  41  
  42      return array_merge($req_phids, parent::getRequiredHandlePHIDs());
  43    }
  44  
  45    public function getTitle() {
  46      $old = $this->getOldValue();
  47      $new = $this->getNewValue();
  48      $author_handle = $this->renderHandleLink($this->getAuthorPHID());
  49  
  50      switch ($this->getTransactionType()) {
  51        case PhabricatorProjectTransaction::TYPE_NAME:
  52          if ($old === null) {
  53            return pht(
  54              '%s created this project.',
  55              $author_handle);
  56          } else {
  57            return pht(
  58              '%s renamed this project from "%s" to "%s".',
  59              $author_handle,
  60              $old,
  61              $new);
  62          }
  63        case PhabricatorProjectTransaction::TYPE_STATUS:
  64          if ($old == 0) {
  65            return pht(
  66              '%s closed this project.',
  67              $author_handle);
  68          } else {
  69            return pht(
  70              '%s reopened this project.',
  71              $author_handle);
  72          }
  73        case PhabricatorProjectTransaction::TYPE_IMAGE:
  74          // TODO: Some day, it would be nice to show the images.
  75          if (!$old) {
  76            return pht(
  77              '%s set this project\'s image to %s.',
  78              $author_handle,
  79              $this->renderHandleLink($new));
  80          } else if (!$new) {
  81            return pht(
  82              '%s removed this project\'s image.',
  83              $author_handle);
  84          } else {
  85            return pht(
  86              '%s updated this project\'s image from %s to %s.',
  87              $author_handle,
  88              $this->renderHandleLink($old),
  89              $this->renderHandleLink($new));
  90          }
  91  
  92        case PhabricatorProjectTransaction::TYPE_ICON:
  93          return pht(
  94            '%s set this project\'s icon to %s.',
  95            $author_handle,
  96            PhabricatorProjectIcon::getLabel($new));
  97  
  98        case PhabricatorProjectTransaction::TYPE_COLOR:
  99          return pht(
 100            '%s set this project\'s color to %s.',
 101            $author_handle,
 102            PHUITagView::getShadeName($new));
 103  
 104        case PhabricatorProjectTransaction::TYPE_LOCKED:
 105          if ($new) {
 106            return pht(
 107              '%s locked this project\'s membership.',
 108              $author_handle);
 109          } else {
 110            return pht(
 111              '%s unlocked this project\'s membership.',
 112              $author_handle);
 113          }
 114  
 115        case PhabricatorProjectTransaction::TYPE_SLUGS:
 116          $add = array_diff($new, $old);
 117          $rem = array_diff($old, $new);
 118  
 119          if ($add && $rem) {
 120            return pht(
 121              '%s changed project hashtag(s), added %d: %s; removed %d: %s',
 122              $author_handle,
 123              count($add),
 124              $this->renderSlugList($add),
 125              count($rem),
 126              $this->renderSlugList($rem));
 127          } else if ($add) {
 128            return pht(
 129              '%s added %d project hashtag(s): %s',
 130              $author_handle,
 131              count($add),
 132              $this->renderSlugList($add));
 133          } else if ($rem) {
 134              return pht(
 135                '%s removed %d project hashtag(s): %s',
 136                $author_handle,
 137                count($rem),
 138                $this->renderSlugList($rem));
 139          }
 140  
 141        case PhabricatorProjectTransaction::TYPE_MEMBERS:
 142          $add = array_diff($new, $old);
 143          $rem = array_diff($old, $new);
 144  
 145          if ($add && $rem) {
 146            return pht(
 147              '%s changed project member(s), added %d: %s; removed %d: %s',
 148              $author_handle,
 149              count($add),
 150              $this->renderHandleList($add),
 151              count($rem),
 152              $this->renderHandleList($rem));
 153          } else if ($add) {
 154            if (count($add) == 1 && (head($add) == $this->getAuthorPHID())) {
 155              return pht(
 156                '%s joined this project.',
 157                $author_handle);
 158            } else {
 159              return pht(
 160                '%s added %d project member(s): %s',
 161                $author_handle,
 162                count($add),
 163                $this->renderHandleList($add));
 164            }
 165          } else if ($rem) {
 166            if (count($rem) == 1 && (head($rem) == $this->getAuthorPHID())) {
 167              return pht(
 168                '%s left this project.',
 169                $author_handle);
 170            } else {
 171              return pht(
 172                '%s removed %d project member(s): %s',
 173                $author_handle,
 174                count($rem),
 175                $this->renderHandleList($rem));
 176            }
 177          }
 178      }
 179  
 180      return parent::getTitle();
 181    }
 182  
 183    private function renderSlugList($slugs) {
 184      return implode(', ', $slugs);
 185    }
 186  
 187  }


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