public function loadStatus(PhabricatorUser $user)
 {
     $limit = self::MAX_STATUS_ITEMS;
     $revisions = id(new DifferentialRevisionQuery())->setViewer($user)->withResponsibleUsers(array($user->getPHID()))->withStatus(DifferentialRevisionQuery::STATUS_OPEN)->needRelationships(true)->setLimit($limit)->execute();
     $status = array();
     if (count($revisions) >= $limit) {
         $all_count = count($revisions);
         $all_count_str = pht('%s+ Active Review(s)', new PhutilNumber($limit - 1));
         $type = PhabricatorApplicationStatusView::TYPE_WARNING;
         $status[] = id(new PhabricatorApplicationStatusView())->setType($type)->setText($all_count_str)->setCount($all_count);
     } else {
         list($blocking, $active, $waiting) = DifferentialRevisionQuery::splitResponsible($revisions, array($user->getPHID()));
         $blocking = count($blocking);
         $blocking_str = pht('%s Review(s) Blocking Others', new PhutilNumber($blocking));
         $type = PhabricatorApplicationStatusView::TYPE_NEEDS_ATTENTION;
         $status[] = id(new PhabricatorApplicationStatusView())->setType($type)->setText($blocking_str)->setCount($blocking);
         $active = count($active);
         $active_str = pht('%s Review(s) Need Attention', new PhutilNumber($active));
         $type = PhabricatorApplicationStatusView::TYPE_WARNING;
         $status[] = id(new PhabricatorApplicationStatusView())->setType($type)->setText($active_str)->setCount($active);
         $waiting = count($waiting);
         $waiting_str = pht('%s Review(s) Waiting on Others', new PhutilNumber($waiting));
         $type = PhabricatorApplicationStatusView::TYPE_INFO;
         $status[] = id(new PhabricatorApplicationStatusView())->setType($type)->setText($waiting_str)->setCount($waiting);
     }
     return $status;
 }
 public function loadStatus(PhabricatorUser $user)
 {
     $revisions = id(new DifferentialRevisionQuery())->withResponsibleUsers(array($user->getPHID()))->withStatus(DifferentialRevisionQuery::STATUS_OPEN)->execute();
     list($active, $waiting) = DifferentialRevisionQuery::splitResponsible($revisions, $user->getPHID());
     $status = array();
     $active = count($active);
     $type = $active ? PhabricatorApplicationStatusView::TYPE_NEEDS_ATTENTION : PhabricatorApplicationStatusView::TYPE_EMPTY;
     $status[] = id(new PhabricatorApplicationStatusView())->setType($type)->setText(pht('%d Review(s) Need Attention', $active))->setCount($active);
     $waiting = count($waiting);
     $type = $waiting ? PhabricatorApplicationStatusView::TYPE_INFO : PhabricatorApplicationStatusView::TYPE_EMPTY;
     $status[] = id(new PhabricatorApplicationStatusView())->setType($type)->setText(pht('%d Review(s) Waiting on Others', $waiting));
     return $status;
 }
 protected function renderResultList(array $revisions, PhabricatorSavedQuery $query, array $handles)
 {
     assert_instances_of($revisions, 'DifferentialRevision');
     $viewer = $this->requireViewer();
     $template = id(new DifferentialRevisionListView())->setUser($viewer)->setNoBox($this->isPanelContext());
     $views = array();
     if ($query->getQueryKey() == 'active') {
         $split = DifferentialRevisionQuery::splitResponsible($revisions, $query->getParameter('responsiblePHIDs'));
         list($blocking, $active, $waiting) = $split;
         $views[] = id(clone $template)->setHeader(pht('Blocking Others'))->setNoDataString(pht('No revisions are blocked on your action.'))->setHighlightAge(true)->setRevisions($blocking)->setHandles(array());
         $views[] = id(clone $template)->setHeader(pht('Action Required'))->setNoDataString(pht('No revisions require your action.'))->setHighlightAge(true)->setRevisions($active)->setHandles(array());
         $views[] = id(clone $template)->setHeader(pht('Waiting on Others'))->setNoDataString(pht('You have no revisions waiting on others.'))->setRevisions($waiting)->setHandles(array());
     } else {
         $views[] = id(clone $template)->setRevisions($revisions)->setHandles(array());
     }
     $phids = array_mergev(mpull($views, 'getRequiredHandlePHIDs'));
     if ($phids) {
         $handles = id(new PhabricatorHandleQuery())->setViewer($viewer)->withPHIDs($phids)->execute();
     } else {
         $handles = array();
     }
     foreach ($views as $view) {
         $view->setHandles($handles);
     }
     if (count($views) == 1) {
         // Reduce this to a PHUIObjectItemListView so we can get the free
         // support from ApplicationSearch.
         return head($views)->render();
     } else {
         return $views;
     }
 }
 private function buildRevisionPanel()
 {
     $user = $this->getRequest()->getUser();
     $user_phid = $user->getPHID();
     $revision_query = id(new DifferentialRevisionQuery())->setViewer($user)->withStatus(DifferentialRevisionQuery::STATUS_OPEN)->withResponsibleUsers(array($user_phid))->needRelationships(true)->needFlags(true)->needDrafts(true);
     $revisions = $revision_query->execute();
     list($blocking, $active, ) = DifferentialRevisionQuery::splitResponsible($revisions, array($user_phid));
     if (!$blocking && !$active) {
         return $this->renderMiniPanel('No Waiting Revisions', 'No revisions are waiting on you.');
     }
     $title = pht('Revisions Waiting on You');
     $href = '/differential';
     $panel = new AphrontPanelView();
     $panel->setHeader($this->renderSectionHeader($title, $href));
     $revision_view = id(new DifferentialRevisionListView())->setHighlightAge(true)->setRevisions(array_merge($blocking, $active))->setUser($user);
     $phids = array_merge(array($user_phid), $revision_view->getRequiredHandlePHIDs());
     $handles = $this->loadViewerHandles($phids);
     $revision_view->setHandles($handles);
     $list_view = $revision_view->render();
     $list_view->setFlush(true);
     $panel->appendChild($list_view);
     $panel->setNoBackground();
     return $panel;
 }
 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 buildViews($filter, $user_phid, array $revisions)
 {
     assert_instances_of($revisions, 'DifferentialRevision');
     $user = $this->getRequest()->getUser();
     $template = id(new DifferentialRevisionListView())->setUser($user)->setFields(DifferentialRevisionListView::getDefaultFields());
     $views = array();
     switch ($filter) {
         case 'active':
             list($active, $waiting) = DifferentialRevisionQuery::splitResponsible($revisions, $user_phid);
             $view = id(clone $template)->setHighlightAge(true)->setRevisions($active)->loadAssets();
             $views[] = array('title' => 'Action Required', 'view' => $view);
             // Flags are sort of private, so only show the flag panel if you're
             // looking at your own requests.
             if ($user_phid == $user->getPHID()) {
                 $flags = id(new PhabricatorFlagQuery())->withOwnerPHIDs(array($user_phid))->withTypes(array(PhabricatorPHIDConstants::PHID_TYPE_DREV))->needHandles(true)->execute();
                 if ($flags) {
                     $view = id(new PhabricatorFlagListView())->setFlags($flags)->setUser($user);
                     $views[] = array('title' => 'Flagged Revisions', 'view' => $view, 'special' => true);
                 }
             }
             $view = id(clone $template)->setRevisions($waiting)->loadAssets();
             $views[] = array('title' => 'Waiting On Others', 'view' => $view);
             break;
         case 'revisions':
         case 'reviews':
         case 'subscribed':
         case 'drafts':
         case 'all':
             $titles = array('revisions' => 'Revisions by Author', 'reviews' => 'Revisions by Reviewer', 'subscribed' => 'Revisions by Subscriber', 'all' => 'Revisions');
             $view = id(clone $template)->setRevisions($revisions)->loadAssets();
             $views[] = array('title' => idx($titles, $filter), 'view' => $view);
             break;
         default:
             throw new Exception("Unknown filter '{$filter}'!");
     }
     return $views;
 }