[ Index ]

PHP Cross Reference of Phabricator

title

Body

[close]

/src/applications/phortune/editor/ -> PhortuneAccountEditor.php (source)

   1  <?php
   2  
   3  
   4  final class PhortuneAccountEditor
   5    extends PhabricatorApplicationTransactionEditor {
   6  
   7    public function getEditorApplicationClass() {
   8      return 'PhabricatorPhortuneApplication';
   9    }
  10  
  11    public function getEditorObjectsDescription() {
  12      return pht('Phortune Accounts');
  13    }
  14  
  15    public function getTransactionTypes() {
  16      $types = parent::getTransactionTypes();
  17  
  18      $types[] = PhabricatorTransactions::TYPE_EDGE;
  19      $types[] = PhortuneAccountTransaction::TYPE_NAME;
  20  
  21      return $types;
  22    }
  23  
  24  
  25    protected function getCustomTransactionOldValue(
  26      PhabricatorLiskDAO $object,
  27      PhabricatorApplicationTransaction $xaction) {
  28      switch ($xaction->getTransactionType()) {
  29        case PhortuneAccountTransaction::TYPE_NAME:
  30          return $object->getName();
  31      }
  32      return parent::getCustomTransactionOldValue($object, $xaction);
  33    }
  34  
  35    protected function getCustomTransactionNewValue(
  36      PhabricatorLiskDAO $object,
  37      PhabricatorApplicationTransaction $xaction) {
  38      switch ($xaction->getTransactionType()) {
  39        case PhortuneAccountTransaction::TYPE_NAME:
  40          return $xaction->getNewValue();
  41      }
  42      return parent::getCustomTransactionNewValue($object, $xaction);
  43    }
  44  
  45    protected function applyCustomInternalTransaction(
  46      PhabricatorLiskDAO $object,
  47      PhabricatorApplicationTransaction $xaction) {
  48      switch ($xaction->getTransactionType()) {
  49        case PhortuneAccountTransaction::TYPE_NAME:
  50          $object->setName($xaction->getNewValue());
  51          return;
  52        case PhabricatorTransactions::TYPE_EDGE:
  53          return;
  54      }
  55      return parent::applyCustomInternalTransaction($object, $xaction);
  56    }
  57  
  58    protected function applyCustomExternalTransaction(
  59      PhabricatorLiskDAO $object,
  60      PhabricatorApplicationTransaction $xaction) {
  61      switch ($xaction->getTransactionType()) {
  62        case PhortuneAccountTransaction::TYPE_NAME:
  63          return;
  64        case PhabricatorTransactions::TYPE_EDGE:
  65          return;
  66      }
  67      return parent::applyCustomExternalTransaction($object, $xaction);
  68    }
  69  
  70    protected function validateTransaction(
  71      PhabricatorLiskDAO $object,
  72      $type,
  73      array $xactions) {
  74  
  75      $errors = parent::validateTransaction($object, $type, $xactions);
  76  
  77      switch ($type) {
  78        case PhortuneAccountTransaction::TYPE_NAME:
  79          $missing = $this->validateIsEmptyTextField(
  80            $object->getName(),
  81            $xactions);
  82  
  83          if ($missing) {
  84            $error = new PhabricatorApplicationTransactionValidationError(
  85              $type,
  86              pht('Required'),
  87              pht('Account name is required.'),
  88              nonempty(last($xactions), null));
  89  
  90            $error->setIsMissingFieldError(true);
  91            $errors[] = $error;
  92          }
  93          break;
  94        case PhabricatorTransactions::TYPE_EDGE:
  95          foreach ($xactions as $xaction) {
  96            switch ($xaction->getMetadataValue('edge:type')) {
  97              case PhortuneAccountHasMemberEdgeType::EDGECONST:
  98                // TODO: This is a bit cumbersome, but validation happens before
  99                // transaction normalization. Maybe provide a cleaner attack on
 100                // this eventually? There's no way to generate "+" or "-"
 101                // transactions right now.
 102                $new = $xaction->getNewValue();
 103                $set = idx($new, '=', array());
 104  
 105                if (empty($set[$this->requireActor()->getPHID()])) {
 106                  $error = new PhabricatorApplicationTransactionValidationError(
 107                    $type,
 108                    pht('Invalid'),
 109                    pht('You can not remove yourself as an account member.'),
 110                    $xaction);
 111                  $errors[] = $error;
 112                }
 113                break;
 114            }
 115          }
 116          break;
 117      }
 118  
 119      return $errors;
 120    }
 121  }


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