private function buildAuditTable(PhabricatorRepositoryCommit $commit, array $audits)
 {
     assert_instances_of($audits, 'PhabricatorRepositoryAuditRequest');
     $user = $this->getRequest()->getUser();
     $view = new PhabricatorAuditListView();
     $view->setAudits($audits);
     $view->setCommits(array($commit));
     $view->setUser($user);
     $view->setShowDescriptions(false);
     $phids = $view->getRequiredHandlePHIDs();
     $handles = id(new PhabricatorObjectHandleData($phids))->loadHandles();
     $view->setHandles($handles);
     $view->setAuthorityPHIDs($this->auditAuthorityPHIDs);
     $panel = new AphrontPanelView();
     $panel->setHeader('Audits');
     $panel->setCaption('Audits you are responsible for are highlighted.');
     $panel->appendChild($view);
     return $panel;
 }
 public function buildAuditPanel()
 {
     $request = $this->getRequest();
     $user = $request->getUser();
     $phids = PhabricatorAuditCommentEditor::loadAuditPHIDsForUser($user);
     $query = new PhabricatorAuditQuery();
     $query->withAuditorPHIDs($phids);
     $query->withStatus(PhabricatorAuditQuery::STATUS_OPEN);
     $query->withAwaitingUser($user);
     $query->needCommitData(true);
     $query->setLimit(10);
     $audits = $query->execute();
     $commits = $query->getCommits();
     if (!$audits) {
         return $this->renderMinipanel('No Audits', 'No commits are waiting for you to audit them.');
     }
     $view = new PhabricatorAuditListView();
     $view->setAudits($audits);
     $view->setCommits($commits);
     $view->setUser($user);
     $phids = $view->getRequiredHandlePHIDs();
     $handles = id(new PhabricatorObjectHandleData($phids))->loadHandles();
     $view->setHandles($handles);
     $panel = new AphrontPanelView();
     $panel->setHeader('Audits');
     $panel->setCaption('Commits awaiting your audit.');
     $panel->appendChild($view);
     $panel->addButton(phutil_render_tag('a', array('href' => '/audit/', 'class' => 'button grey'), "View Active Audits »"));
     return $panel;
 }
 private function buildAuditView(PhabricatorObjectHandle $handle = null)
 {
     $request = $this->getRequest();
     $query = new PhabricatorAuditQuery();
     $use_pager = $this->filter != 'active';
     if ($use_pager) {
         $pager = new AphrontPagerView();
         $pager->setURI($request->getRequestURI(), 'offset');
         $pager->setOffset($request->getInt('offset'));
         $query->setOffset($pager->getOffset());
         $query->setLimit($pager->getPageSize() + 1);
     }
     $awaiting = null;
     $phids = null;
     switch ($this->filter) {
         case 'user':
         case 'active':
             $obj = id(new PhabricatorUser())->loadOneWhere('phid = %s', $handle->getPHID());
             if (!$obj) {
                 throw new Exception("Invalid user!");
             }
             $phids = PhabricatorAuditCommentEditor::loadAuditPHIDsForUser($obj);
             $awaiting = $obj;
             break;
         case 'project':
         case 'package':
             $phids = array($handle->getPHID());
             break;
         case 'audits':
             break;
         default:
             throw new Exception("Unknown filter!");
     }
     if ($phids) {
         $query->withAuditorPHIDs($phids);
     }
     if ($awaiting) {
         $query->withAwaitingUser($awaiting);
     }
     switch ($this->filter) {
         case 'audits':
         case 'user':
         case 'project':
         case 'package':
             switch ($this->filterStatus) {
                 case 'open':
                     $query->withStatus(PhabricatorAuditQuery::STATUS_OPEN);
                     break;
             }
             break;
         case 'active':
             $query->withStatus(PhabricatorAuditQuery::STATUS_OPEN);
             break;
     }
     if ($handle) {
         $handle_name = phutil_escape_html($handle->getName());
     } else {
         $handle_name = null;
     }
     switch ($this->filter) {
         case 'active':
             $header = 'Required Audits';
             $nodata = 'No commits require your audit.';
             break;
         case 'user':
             $header = "Audits for {$handle_name}";
             $nodata = "No matching audits by {$handle_name}.";
             break;
         case 'audits':
             $header = "Audits";
             $nodata = "No matching audits.";
             break;
         case 'project':
             $header = "Audits in Project '{$handle_name}'";
             $nodata = "No matching audits in project '{$handle_name}'.";
             break;
         case 'package':
             $header = "Audits for Package '{$handle_name}'";
             $nodata = "No matching audits in package '{$handle_name}'.";
             break;
     }
     $query->needCommitData(true);
     $audits = $query->execute();
     if ($use_pager) {
         $audits = $pager->sliceResults($audits);
     }
     $view = new PhabricatorAuditListView();
     $view->setAudits($audits);
     $view->setCommits($query->getCommits());
     $view->setNoDataString($nodata);
     $phids = $view->getRequiredHandlePHIDs();
     $handles = id(new PhabricatorObjectHandleData($phids))->loadHandles();
     $view->setHandles($handles);
     $panel = new AphrontPanelView();
     $panel->setHeader($header);
     $panel->appendChild($view);
     if ($use_pager) {
         $panel->appendChild($pager);
     }
     return $panel;
 }