[ Index ]

PHP Cross Reference of Phabricator

title

Body

[close]

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

   1  <?php
   2  
   3  final class PhabricatorAuditListView extends AphrontView {
   4  
   5    private $commits;
   6    private $handles;
   7    private $authorityPHIDs = array();
   8    private $noDataString;
   9  
  10    private $highlightedAudits;
  11  
  12    public function setHandles(array $handles) {
  13      assert_instances_of($handles, 'PhabricatorObjectHandle');
  14      $this->handles = $handles;
  15      return $this;
  16    }
  17  
  18    public function setAuthorityPHIDs(array $phids) {
  19      $this->authorityPHIDs = $phids;
  20      return $this;
  21    }
  22  
  23    public function setNoDataString($no_data_string) {
  24      $this->noDataString = $no_data_string;
  25      return $this;
  26    }
  27  
  28    public function getNoDataString() {
  29      return $this->noDataString;
  30    }
  31  
  32    /**
  33     * These commits should have both commit data and audit requests attached.
  34     */
  35    public function setCommits(array $commits) {
  36      assert_instances_of($commits, 'PhabricatorRepositoryCommit');
  37      $this->commits = mpull($commits, null, 'getPHID');
  38      return $this;
  39    }
  40  
  41    public function getCommits() {
  42      return $this->commits;
  43    }
  44  
  45    public function getRequiredHandlePHIDs() {
  46      $phids = array();
  47      $commits = $this->getCommits();
  48      foreach ($commits as $commit) {
  49        $phids[$commit->getPHID()] = true;
  50        $phids[$commit->getAuthorPHID()] = true;
  51        $audits = $commit->getAudits();
  52        foreach ($audits as $audit) {
  53          $phids[$audit->getAuditorPHID()] = true;
  54        }
  55      }
  56      return array_keys($phids);
  57    }
  58  
  59    private function getHandle($phid) {
  60      $handle = idx($this->handles, $phid);
  61      if (!$handle) {
  62        throw new Exception("No handle for '{$phid}'!");
  63      }
  64      return $handle;
  65    }
  66  
  67    private function getCommitDescription($phid) {
  68      if ($this->commits === null) {
  69        return pht('(Unknown Commit)');
  70      }
  71  
  72      $commit = idx($this->commits, $phid);
  73      if (!$commit) {
  74        return pht('(Unknown Commit)');
  75      }
  76  
  77      $summary = $commit->getCommitData()->getSummary();
  78      if (strlen($summary)) {
  79        return $summary;
  80      }
  81  
  82      // No summary, so either this is still impoting or just has an empty
  83      // commit message.
  84  
  85      if (!$commit->isImported()) {
  86        return pht('(Importing Commit...)');
  87      } else {
  88        return pht('(Untitled Commit)');
  89      }
  90    }
  91  
  92    public function render() {
  93      $list = $this->buildList();
  94      $list->setFlush(true);
  95      return $list->render();
  96    }
  97  
  98    public function buildList() {
  99      $user = $this->getUser();
 100      if (!$user) {
 101        throw new Exception('you must setUser() before buildList()!');
 102      }
 103      $rowc = array();
 104  
 105      $list = new PHUIObjectItemListView();
 106      foreach ($this->commits as $commit) {
 107        $commit_phid = $commit->getPHID();
 108        $commit_handle = $this->getHandle($commit_phid);
 109        $committed = null;
 110  
 111        $commit_name = $commit_handle->getName();
 112        $commit_link = $commit_handle->getURI();
 113        $commit_desc = $this->getCommitDescription($commit_phid);
 114        $committed = phabricator_datetime($commit->getEpoch(), $user);
 115  
 116        $audits = mpull($commit->getAudits(), null, 'getAuditorPHID');
 117        $auditors = array();
 118        $reasons = array();
 119        foreach ($audits as $audit) {
 120          $auditor_phid = $audit->getAuditorPHID();
 121          $auditors[$auditor_phid] =
 122            $this->getHandle($auditor_phid)->renderLink();
 123        }
 124        $auditors = phutil_implode_html(', ', $auditors);
 125  
 126        $authority_audits = array_select_keys($audits, $this->authorityPHIDs);
 127        if ($authority_audits) {
 128          $audit = reset($authority_audits);
 129        } else {
 130          $audit = reset($audits);
 131        }
 132        if ($audit) {
 133          $reasons = $audit->getAuditReasons();
 134          $reasons = phutil_implode_html(', ', $reasons);
 135          $status_code = $audit->getAuditStatus();
 136          $status_text =
 137            PhabricatorAuditStatusConstants::getStatusName($status_code);
 138          $status_color =
 139            PhabricatorAuditStatusConstants::getStatusColor($status_code);
 140        } else {
 141          $reasons = null;
 142          $status_text = null;
 143          $status_color = null;
 144        }
 145        $author_name = $commit->getCommitData()->getAuthorName();
 146  
 147        $item = id(new PHUIObjectItemView())
 148          ->setObjectName($commit_name)
 149          ->setHeader($commit_desc)
 150          ->setHref($commit_link)
 151          ->setBarColor($status_color)
 152          ->addAttribute($status_text)
 153          ->addAttribute($reasons)
 154          ->addIcon('none', $committed)
 155          ->addByline(pht('Author: %s', $author_name));
 156  
 157        if (!empty($auditors)) {
 158          $item->addAttribute(pht('Auditors: %s', $auditors));
 159        }
 160  
 161        $list->addItem($item);
 162      }
 163  
 164      if ($this->noDataString) {
 165        $list->setNoDataString($this->noDataString);
 166      }
 167  
 168      return $list;
 169    }
 170  
 171  }


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