private function buildRevisionPanel()
 {
     $user = $this->getRequest()->getUser();
     $user_phid = $user->getPHID();
     $revision_query = new DifferentialRevisionQuery();
     $revision_query->withStatus(DifferentialRevisionQuery::STATUS_OPEN);
     $revision_query->withResponsibleUsers(array($user_phid));
     $revision_query->needRelationships(true);
     // NOTE: We need to unlimit this query to hit the responsible user
     // fast-path.
     $revision_query->setLimit(null);
     $revisions = $revision_query->execute();
     list($active, $waiting) = DifferentialRevisionQuery::splitResponsible($revisions, $user_phid);
     if (!$active) {
         return $this->renderMiniPanel('No Waiting Revisions', 'No revisions are waiting on you.');
     }
     $panel = new AphrontPanelView();
     $panel->setHeader('Revisions Waiting on You');
     $panel->setCaption('Revisions waiting for you for review or commit.');
     $panel->addButton(phutil_render_tag('a', array('href' => '/differential/', 'class' => 'button grey'), "View Active Revisions »"));
     $revision_view = id(new DifferentialRevisionListView())->setHighlightAge(true)->setRevisions($active)->setFields(DifferentialRevisionListView::getDefaultFields())->setUser($user)->loadAssets();
     $phids = array_merge(array($user_phid), $revision_view->getRequiredHandlePHIDs());
     $handles = id(new PhabricatorObjectHandleData($phids))->loadHandles();
     $revision_view->setHandles($handles);
     $panel->appendChild($revision_view);
     return $panel;
 }
 private function buildQuery($filter, $user_phid)
 {
     $query = new DifferentialRevisionQuery();
     $query->needRelationships(true);
     switch ($filter) {
         case 'active':
             $query->withResponsibleUsers(array($user_phid));
             $query->withStatus(DifferentialRevisionQuery::STATUS_OPEN);
             $query->setLimit(null);
             break;
         case 'revisions':
             $query->withAuthors(array($user_phid));
             break;
         case 'reviews':
             $query->withReviewers(array($user_phid));
             break;
         case 'subscribed':
             $query->withSubscribers(array($user_phid));
             break;
         case 'drafts':
             $query->withDraftRepliesByAuthors(array($user_phid));
             break;
         case 'all':
             break;
         default:
             throw new Exception("Unknown filter '{$filter}'!");
     }
     return $query;
 }
 protected function execute(ConduitAPIRequest $request)
 {
     $authors = $request->getValue('authors');
     $ccs = $request->getValue('ccs');
     $reviewers = $request->getValue('reviewers');
     $status = $request->getValue('status');
     $order = $request->getValue('order');
     $commit_hashes = $request->getValue('commitHashes');
     $limit = $request->getValue('limit');
     $offset = $request->getValue('offset');
     $ids = $request->getValue('ids');
     $phids = $request->getValue('phids');
     $subscribers = $request->getValue('subscribers');
     $responsible_users = $request->getValue('responsibleUsers');
     $query = new DifferentialRevisionQuery();
     if ($authors) {
         $query->withAuthors($authors);
     }
     if ($ccs) {
         $query->withCCs($ccs);
     }
     if ($reviewers) {
         $query->withReviewers($reviewers);
     }
     /* TODO: Implement.
         $paths     = $request->getValue('paths');
         if ($paths) {
           foreach ($paths as $path) {
     
             // (Lookup the repository IDs.)
     
             $query->withPath($repository_id, $path);
           }
         }
      */
     if ($commit_hashes) {
         $hash_types = DifferentialRevisionHash::getTypes();
         foreach ($commit_hashes as $info) {
             list($type, $hash) = $info;
             if (empty($type) || !in_array($type, $hash_types) || empty($hash)) {
                 throw new ConduitException('ERR-INVALID-PARAMETER');
             }
         }
         $query->withCommitHashes($commit_hashes);
     }
     if ($status) {
         $query->withStatus($status);
     }
     if ($order) {
         $query->setOrder($order);
     }
     if ($limit) {
         $query->setLimit($limit);
     }
     if ($offset) {
         $query->setOffset($offset);
     }
     if ($ids) {
         $query->withIDs($ids);
     }
     if ($phids) {
         $query->withPHIDs($phids);
     }
     if ($responsible_users) {
         $query->withResponsibleUsers($responsible_users);
     }
     if ($subscribers) {
         $query->withSubscribers($subscribers);
     }
     $query->needRelationships(true);
     $query->needCommitPHIDs(true);
     $query->needDiffIDs(true);
     $query->needActiveDiffs(true);
     $revisions = $query->execute();
     $results = array();
     foreach ($revisions as $revision) {
         $diff = $revision->getActiveDiff();
         if (!$diff) {
             continue;
         }
         $id = $revision->getID();
         $results[] = array('id' => $id, 'phid' => $revision->getPHID(), 'title' => $revision->getTitle(), 'uri' => PhabricatorEnv::getProductionURI('/D' . $id), 'dateCreated' => $revision->getDateCreated(), 'dateModified' => $revision->getDateModified(), 'authorPHID' => $revision->getAuthorPHID(), 'status' => $revision->getStatus(), 'statusName' => DifferentialRevisionStatus::getNameForRevisionStatus($revision->getStatus()), 'sourcePath' => $diff->getSourcePath(), 'summary' => $revision->getSummary(), 'testPlan' => $revision->getTestPlan(), 'lineCount' => $revision->getLineCount(), 'diffs' => $revision->getDiffIDs(), 'commits' => $revision->getCommitPHIDs(), 'reviewers' => array_values($revision->getReviewers()), 'ccs' => array_values($revision->getCCPHIDs()));
     }
     return $results;
 }
 protected function execute(ConduitAPIRequest $request)
 {
     $authors = $request->getValue('authors');
     $ccs = $request->getValue('ccs');
     $reviewers = $request->getValue('reviewers');
     $status = $request->getValue('status');
     $order = $request->getValue('order');
     $commit_hashes = $request->getValue('commitHashes');
     $limit = $request->getValue('limit');
     $offset = $request->getValue('offset');
     $ids = $request->getValue('ids');
     $phids = $request->getValue('phids');
     $subscribers = $request->getValue('subscribers');
     $responsible_users = $request->getValue('responsibleUsers');
     $branches = $request->getValue('branches');
     $arc_projects = $request->getValue('arcanistProjects');
     $query = new DifferentialRevisionQuery();
     if ($authors) {
         $query->withAuthors($authors);
     }
     if ($ccs) {
         $query->withCCs($ccs);
     }
     if ($reviewers) {
         $query->withReviewers($reviewers);
     }
     /* TODO: Implement.
         $paths     = $request->getValue('paths');
         if ($paths) {
           foreach ($paths as $path) {
     
             // (Lookup the repository IDs.)
     
             $query->withPath($repository_id, $path);
           }
         }
      */
     if ($commit_hashes) {
         $hash_types = ArcanistDifferentialRevisionHash::getTypes();
         foreach ($commit_hashes as $info) {
             list($type, $hash) = $info;
             if (empty($type) || !in_array($type, $hash_types) || empty($hash)) {
                 throw new ConduitException('ERR-INVALID-PARAMETER');
             }
         }
         $query->withCommitHashes($commit_hashes);
     }
     if ($status) {
         $query->withStatus($status);
     }
     if ($order) {
         $query->setOrder($order);
     }
     if ($limit) {
         $query->setLimit($limit);
     }
     if ($offset) {
         $query->setOffset($offset);
     }
     if ($ids) {
         $query->withIDs($ids);
     }
     if ($phids) {
         $query->withPHIDs($phids);
     }
     if ($responsible_users) {
         $query->withResponsibleUsers($responsible_users);
     }
     if ($subscribers) {
         $query->withSubscribers($subscribers);
     }
     if ($branches) {
         $query->withBranches($branches);
     }
     if ($arc_projects) {
         // This is sort of special-cased, but don't make arc do an extra round
         // trip.
         $projects = id(new PhabricatorRepositoryArcanistProject())->loadAllWhere('name in (%Ls)', $arc_projects);
         if (!$projects) {
             return array();
         }
         $query->withArcanistProjectPHIDs(mpull($projects, 'getPHID'));
     }
     $query->needRelationships(true);
     $query->needCommitPHIDs(true);
     $query->needDiffIDs(true);
     $query->needActiveDiffs(true);
     $revisions = $query->execute();
     $results = array();
     foreach ($revisions as $revision) {
         $diff = $revision->getActiveDiff();
         if (!$diff) {
             continue;
         }
         $id = $revision->getID();
         $result = array('id' => $id, 'phid' => $revision->getPHID(), 'title' => $revision->getTitle(), 'uri' => PhabricatorEnv::getProductionURI('/D' . $id), 'dateCreated' => $revision->getDateCreated(), 'dateModified' => $revision->getDateModified(), 'authorPHID' => $revision->getAuthorPHID(), 'status' => $revision->getStatus(), 'statusName' => ArcanistDifferentialRevisionStatus::getNameForRevisionStatus($revision->getStatus()), 'branch' => $diff->getBranch(), 'summary' => $revision->getSummary(), 'testPlan' => $revision->getTestPlan(), 'lineCount' => $revision->getLineCount(), 'diffs' => $revision->getDiffIDs(), 'commits' => $revision->getCommitPHIDs(), 'reviewers' => array_values($revision->getReviewers()), 'ccs' => array_values($revision->getCCPHIDs()));
         // TODO: This is a hacky way to put permissions on this field until we
         // have first-class support, see T838.
         if ($revision->getAuthorPHID() == $request->getUser()->getPHID()) {
             $result['sourcePath'] = $diff->getSourcePath();
         }
         $results[] = $result;
     }
     return $results;
 }