protected function execute(ConduitAPIRequest $request)
 {
     $query = new PhabricatorAuditQuery();
     $auditor_phids = $request->getValue('auditorPHIDs', array());
     if ($auditor_phids) {
         $query->withAuditorPHIDs($auditor_phids);
     }
     $commit_phids = $request->getValue('commitPHIDs', array());
     if ($commit_phids) {
         $query->withCommitPHIDs($commit_phids);
     }
     $status = $request->getValue('status', PhabricatorAuditQuery::STATUS_ANY);
     $query->withStatus($status);
     $query->setOffset($request->getValue('offset', 0));
     $query->setLimit($request->getValue('limit', 100));
     $requests = $query->execute();
     $results = array();
     foreach ($requests as $request) {
         $results[] = array('id' => $request->getID(), 'commitPHID' => $request->getCommitPHID(), 'auditorPHID' => $request->getAuditorPHID(), 'reasons' => $request->getAuditReasons(), 'status' => $request->getAuditStatus());
     }
     return $results;
 }
 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;
 }