Changeset View
Changeset View
Standalone View
Standalone View
src/applications/audit/view/PhabricatorAuditListView.php
<?php | <?php | ||||
final class PhabricatorAuditListView extends AphrontView { | final class PhabricatorAuditListView extends AphrontView { | ||||
private $commits; | private $commits; | ||||
private $handles; | |||||
private $authorityPHIDs = array(); | private $authorityPHIDs = array(); | ||||
private $header; | |||||
private $noDataString; | private $noDataString; | ||||
private $highlightedAudits; | private $highlightedAudits; | ||||
public function setHandles(array $handles) { | |||||
assert_instances_of($handles, 'PhabricatorObjectHandle'); | |||||
$this->handles = $handles; | |||||
return $this; | |||||
} | |||||
public function setAuthorityPHIDs(array $phids) { | public function setAuthorityPHIDs(array $phids) { | ||||
$this->authorityPHIDs = $phids; | $this->authorityPHIDs = $phids; | ||||
return $this; | return $this; | ||||
} | } | ||||
public function setNoDataString($no_data_string) { | public function setNoDataString($no_data_string) { | ||||
$this->noDataString = $no_data_string; | $this->noDataString = $no_data_string; | ||||
return $this; | return $this; | ||||
} | } | ||||
public function getNoDataString() { | public function getNoDataString() { | ||||
return $this->noDataString; | return $this->noDataString; | ||||
} | } | ||||
public function setHeader($header) { | |||||
$this->header = $header; | |||||
return $this; | |||||
} | |||||
public function getHeader() { | |||||
return $this->header; | |||||
} | |||||
/** | /** | ||||
* These commits should have both commit data and audit requests attached. | * These commits should have both commit data and audit requests attached. | ||||
*/ | */ | ||||
public function setCommits(array $commits) { | public function setCommits(array $commits) { | ||||
assert_instances_of($commits, 'PhabricatorRepositoryCommit'); | assert_instances_of($commits, 'PhabricatorRepositoryCommit'); | ||||
$this->commits = mpull($commits, null, 'getPHID'); | $this->commits = mpull($commits, null, 'getPHID'); | ||||
return $this; | return $this; | ||||
} | } | ||||
public function getCommits() { | public function getCommits() { | ||||
return $this->commits; | return $this->commits; | ||||
} | } | ||||
public function getRequiredHandlePHIDs() { | |||||
$phids = array(); | |||||
$commits = $this->getCommits(); | |||||
foreach ($commits as $commit) { | |||||
$phids[$commit->getPHID()] = true; | |||||
$phids[$commit->getAuthorPHID()] = true; | |||||
$audits = $commit->getAudits(); | |||||
foreach ($audits as $audit) { | |||||
$phids[$audit->getAuditorPHID()] = true; | |||||
} | |||||
} | |||||
return array_keys($phids); | |||||
} | |||||
private function getHandle($phid) { | |||||
$handle = idx($this->handles, $phid); | |||||
if (!$handle) { | |||||
throw new Exception(pht("No handle for '%s'!", $phid)); | |||||
} | |||||
return $handle; | |||||
} | |||||
private function getCommitDescription($phid) { | private function getCommitDescription($phid) { | ||||
if ($this->commits === null) { | if ($this->commits === null) { | ||||
return pht('(Unknown Commit)'); | return pht('(Unknown Commit)'); | ||||
} | } | ||||
$commit = idx($this->commits, $phid); | $commit = idx($this->commits, $phid); | ||||
if (!$commit) { | if (!$commit) { | ||||
return pht('(Unknown Commit)'); | return pht('(Unknown Commit)'); | ||||
Show All 16 Lines | final class PhabricatorAuditListView extends AphrontView { | ||||
public function render() { | public function render() { | ||||
$list = $this->buildList(); | $list = $this->buildList(); | ||||
$list->setFlush(true); | $list->setFlush(true); | ||||
return $list->render(); | return $list->render(); | ||||
} | } | ||||
public function buildList() { | public function buildList() { | ||||
$user = $this->getUser(); | $viewer = $this->getViewer(); | ||||
if (!$user) { | |||||
throw new Exception( | |||||
pht( | |||||
'You must %s before %s!', | |||||
'setUser()', | |||||
__FUNCTION__.'()')); | |||||
} | |||||
$rowc = array(); | $rowc = array(); | ||||
$handles = $viewer->loadHandles(mpull($this->commits, 'getPHID')); | |||||
$list = new PHUIObjectItemListView(); | $list = new PHUIObjectItemListView(); | ||||
foreach ($this->commits as $commit) { | foreach ($this->commits as $commit) { | ||||
$commit_phid = $commit->getPHID(); | $commit_phid = $commit->getPHID(); | ||||
$commit_handle = $this->getHandle($commit_phid); | $commit_handle = $handles[$commit_phid]; | ||||
$committed = null; | $committed = null; | ||||
$commit_name = $commit_handle->getName(); | $commit_name = $commit_handle->getName(); | ||||
$commit_link = $commit_handle->getURI(); | $commit_link = $commit_handle->getURI(); | ||||
$commit_desc = $this->getCommitDescription($commit_phid); | $commit_desc = $this->getCommitDescription($commit_phid); | ||||
$committed = phabricator_datetime($commit->getEpoch(), $user); | $committed = phabricator_datetime($commit->getEpoch(), $viewer); | ||||
$audits = mpull($commit->getAudits(), null, 'getAuditorPHID'); | $audits = mpull($commit->getAudits(), null, 'getAuditorPHID'); | ||||
$auditors = array(); | $auditors = array(); | ||||
$reasons = array(); | $reasons = array(); | ||||
foreach ($audits as $audit) { | foreach ($audits as $audit) { | ||||
$auditor_phid = $audit->getAuditorPHID(); | $auditor_phid = $audit->getAuditorPHID(); | ||||
$auditors[$auditor_phid] = | $auditors[$auditor_phid] = $viewer->renderHandle($auditor_phid); | ||||
$this->getHandle($auditor_phid)->renderLink(); | |||||
} | } | ||||
$auditors = phutil_implode_html(', ', $auditors); | $auditors = phutil_implode_html(', ', $auditors); | ||||
$authority_audits = array_select_keys($audits, $this->authorityPHIDs); | $authority_audits = array_select_keys($audits, $this->authorityPHIDs); | ||||
if ($authority_audits) { | if ($authority_audits) { | ||||
$audit = reset($authority_audits); | $audit = reset($authority_audits); | ||||
} else { | } else { | ||||
$audit = reset($audits); | $audit = reset($audits); | ||||
Show All 11 Lines | foreach ($this->commits as $commit) { | ||||
} else { | } else { | ||||
$reasons = null; | $reasons = null; | ||||
$status_text = null; | $status_text = null; | ||||
$status_color = null; | $status_color = null; | ||||
$status_icon = null; | $status_icon = null; | ||||
} | } | ||||
$author_phid = $commit->getAuthorPHID(); | $author_phid = $commit->getAuthorPHID(); | ||||
if ($author_phid) { | if ($author_phid) { | ||||
$author_name = $this->getHandle($author_phid)->renderLink(); | $author_name = $viewer->renderHandle($author_phid); | ||||
} else { | } else { | ||||
$author_name = $commit->getCommitData()->getAuthorName(); | $author_name = $commit->getCommitData()->getAuthorName(); | ||||
} | } | ||||
$item = id(new PHUIObjectItemView()) | $item = id(new PHUIObjectItemView()) | ||||
->setObjectName($commit_name) | ->setObjectName($commit_name) | ||||
->setHeader($commit_desc) | ->setHeader($commit_desc) | ||||
->setHref($commit_link) | ->setHref($commit_link) | ||||
Show All 12 Lines | foreach ($this->commits as $commit) { | ||||
$list->addItem($item); | $list->addItem($item); | ||||
} | } | ||||
if ($this->noDataString) { | if ($this->noDataString) { | ||||
$list->setNoDataString($this->noDataString); | $list->setNoDataString($this->noDataString); | ||||
} | } | ||||
if ($this->header) { | |||||
$list->setHeader($this->header); | |||||
} | |||||
return $list; | return $list; | ||||
} | } | ||||
} | } |