[ Index ]

PHP Cross Reference of Phabricator

title

Body

[close]

/src/applications/audit/view/ -> PhabricatorAuditTransactionView.php (source)

   1  <?php
   2  
   3  final class PhabricatorAuditTransactionView
   4    extends PhabricatorApplicationTransactionView {
   5  
   6    private $pathMap;
   7  
   8    public function setPathMap(array $path_map) {
   9      $this->pathMap = $path_map;
  10      return $this;
  11    }
  12  
  13    public function getPathMap() {
  14      return $this->pathMap;
  15    }
  16  
  17    // TODO: This shares a lot of code with Differential and Pholio and should
  18    // probably be merged up.
  19  
  20    protected function shouldGroupTransactions(
  21      PhabricatorApplicationTransaction $u,
  22      PhabricatorApplicationTransaction $v) {
  23  
  24      if ($u->getAuthorPHID() != $v->getAuthorPHID()) {
  25        // Don't group transactions by different authors.
  26        return false;
  27      }
  28  
  29      if (($v->getDateCreated() - $u->getDateCreated()) > 60) {
  30        // Don't group if transactions that happened more than 60s apart.
  31        return false;
  32      }
  33  
  34      switch ($u->getTransactionType()) {
  35        case PhabricatorTransactions::TYPE_COMMENT:
  36        case PhabricatorAuditActionConstants::INLINE:
  37          break;
  38        default:
  39          return false;
  40      }
  41  
  42      switch ($v->getTransactionType()) {
  43        case PhabricatorAuditActionConstants::INLINE:
  44          return true;
  45      }
  46  
  47      return parent::shouldGroupTransactions($u, $v);
  48    }
  49  
  50    protected function renderTransactionContent(
  51      PhabricatorApplicationTransaction $xaction) {
  52  
  53      $out = array();
  54  
  55      $type_inline = PhabricatorAuditActionConstants::INLINE;
  56  
  57      $group = $xaction->getTransactionGroup();
  58      if ($xaction->getTransactionType() == $type_inline) {
  59        array_unshift($group, $xaction);
  60      } else {
  61        $out[] = parent::renderTransactionContent($xaction);
  62      }
  63  
  64      if (!$group) {
  65        return $out;
  66      }
  67  
  68      $inlines = array();
  69      foreach ($group as $xaction) {
  70        switch ($xaction->getTransactionType()) {
  71          case PhabricatorAuditActionConstants::INLINE:
  72            $inlines[] = $xaction;
  73            break;
  74          default:
  75            throw new Exception('Unknown grouped transaction type!');
  76        }
  77      }
  78  
  79      if ($inlines) {
  80  
  81        // TODO: This should do something similar to sortAndGroupInlines() to get
  82        // a stable ordering.
  83  
  84        $inlines_by_path = array();
  85        foreach ($inlines as $key => $inline) {
  86          $comment = $inline->getComment();
  87          if (!$comment) {
  88            // TODO: Migrate these away? They probably do not exist on normal
  89            // non-development installs.
  90            unset($inlines[$key]);
  91            continue;
  92          }
  93          $path_id = $comment->getPathID();
  94          $inlines_by_path[$path_id][] = $inline;
  95        }
  96  
  97        $inline_view = new PhabricatorInlineSummaryView();
  98        foreach ($inlines_by_path as $path_id => $group) {
  99          $path = idx($this->pathMap, $path_id);
 100          if ($path === null) {
 101            continue;
 102          }
 103  
 104          $items = array();
 105          foreach ($group as $inline) {
 106            $comment = $inline->getComment();
 107            $item = array(
 108              'id' => $comment->getID(),
 109              'line' => $comment->getLineNumber(),
 110              'length' => $comment->getLineLength(),
 111              'content' => parent::renderTransactionContent($inline),
 112            );
 113            $items[] = $item;
 114          }
 115          $inline_view->addCommentGroup($path, $items);
 116        }
 117  
 118        $out[] = $inline_view;
 119      }
 120  
 121      return $out;
 122    }
 123  
 124  }


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