protected function execute(ConduitAPIRequest $request)
 {
     $query = new PhabricatorProjectQuery();
     $query->needMembers(true);
     $ids = $request->getValue('ids');
     if ($ids) {
         $query->withIDs($ids);
     }
     $status = $request->getValue('status');
     if ($status) {
         $query->withStatus($status);
     }
     $phids = $request->getValue('phids');
     if ($phids) {
         $query->withPHIDs($phids);
     }
     $members = $request->getValue('members');
     if ($members) {
         $query->setMembers($members);
     }
     $limit = $request->getValue('limit');
     if ($limit) {
         $query->setLimit($limit);
     }
     $offset = $request->getValue('offset');
     if ($offset) {
         $query->setOffset($offset);
     }
     $results = $query->execute();
     return $this->buildProjectInfoDictionaries($results);
 }
 protected function execute(ConduitAPIRequest $request)
 {
     $query = new PhabricatorProjectQuery();
     $query->setViewer($request->getUser());
     $query->needMembers(true);
     $query->needSlugs(true);
     $ids = $request->getValue('ids');
     if ($ids) {
         $query->withIDs($ids);
     }
     $names = $request->getValue('names');
     if ($names) {
         $query->withNames($names);
     }
     $status = $request->getValue('status');
     if ($status) {
         $query->withStatus($status);
     }
     $phids = $request->getValue('phids');
     if ($phids) {
         $query->withPHIDs($phids);
     }
     $slugs = $request->getValue('slugs');
     if ($slugs) {
         $query->withSlugs($slugs);
     }
     $members = $request->getValue('members');
     if ($members) {
         $query->withMemberPHIDs($members);
     }
     $limit = $request->getValue('limit');
     if ($limit) {
         $query->setLimit($limit);
     }
     $offset = $request->getValue('offset');
     if ($offset) {
         $query->setOffset($offset);
     }
     $pager = $this->newPager($request);
     $results = $query->executeWithCursorPager($pager);
     $projects = $this->buildProjectInfoDictionaries($results);
     // TODO: This is pretty hideous.
     $slug_map = array();
     foreach ($slugs as $slug) {
         $normal = rtrim(PhabricatorSlug::normalize($slug), '/');
         foreach ($projects as $project) {
             if (in_array($normal, $project['slugs'])) {
                 $slug_map[$slug] = $project['phid'];
             }
         }
     }
     $result = array('data' => $projects, 'slugMap' => $slug_map);
     return $this->addPagerResults($result, $pager);
 }
 public function processRequest()
 {
     $request = $this->getRequest();
     $nav = new AphrontSideNavFilterView();
     $nav->setBaseURI(new PhutilURI('/project/filter/'))->addLabel('User')->addFilter('active', 'Active')->addFilter('owned', 'Owned')->addSpacer()->addLabel('All')->addFilter('all', 'All Projects');
     $this->filter = $nav->selectFilter($this->filter, 'active');
     $pager = new AphrontPagerView();
     $pager->setPageSize(250);
     $pager->setURI($request->getRequestURI(), 'page');
     $pager->setOffset($request->getInt('page'));
     $query = new PhabricatorProjectQuery();
     $query->setOffset($pager->getOffset());
     $query->setLimit($pager->getPageSize() + 1);
     $view_phid = $request->getUser()->getPHID();
     switch ($this->filter) {
         case 'active':
             $table_header = 'Active Projects';
             $query->setMembers(array($view_phid));
             break;
         case 'owned':
             $table_header = 'Owned Projects';
             $query->setOwners(array($view_phid));
             break;
         case 'all':
             $table_header = 'All Projects';
             break;
     }
     $projects = $query->execute();
     $projects = $pager->sliceResults($projects);
     $project_phids = mpull($projects, 'getPHID');
     $profiles = array();
     if ($projects) {
         $profiles = id(new PhabricatorProjectProfile())->loadAllWhere('projectPHID in (%Ls)', $project_phids);
         $profiles = mpull($profiles, null, 'getProjectPHID');
     }
     $affil_groups = array();
     if ($projects) {
         $affil_groups = PhabricatorProjectAffiliation::loadAllForProjectPHIDs($project_phids);
     }
     $tasks = array();
     $groups = array();
     if ($project_phids) {
         $query = id(new ManiphestTaskQuery())->withProjects($project_phids)->withAnyProject(true)->withStatus(ManiphestTaskQuery::STATUS_OPEN)->setLimit(PHP_INT_MAX);
         $tasks = $query->execute();
         foreach ($tasks as $task) {
             foreach ($task->getProjectPHIDs() as $phid) {
                 $groups[$phid][] = $task;
             }
         }
     }
     $rows = array();
     foreach ($projects as $project) {
         $phid = $project->getPHID();
         $profile = $profiles[$phid];
         $affiliations = $affil_groups[$phid];
         $group = idx($groups, $phid, array());
         $task_count = count($group);
         $population = count($affiliations);
         $blurb = $profile->getBlurb();
         $blurb = phutil_utf8_shorten($blurb, 64);
         $rows[] = array(phutil_render_tag('a', array('href' => '/project/view/' . $project->getID() . '/'), phutil_escape_html($project->getName())), phutil_escape_html($blurb), phutil_escape_html($population), phutil_render_tag('a', array('href' => '/maniphest/view/all/?projects=' . $phid), phutil_escape_html($task_count)));
     }
     $table = new AphrontTableView($rows);
     $table->setHeaders(array('Project', 'Description', 'Population', 'Open Tasks'));
     $table->setColumnClasses(array('pri', 'wide', '', ''));
     $panel = new AphrontPanelView();
     $panel->setHeader($table_header);
     $panel->setCreateButton('Create New Project', '/project/create/');
     $panel->appendChild($table);
     $panel->appendChild($pager);
     $nav->appendChild($panel);
     return $this->buildStandardPageResponse($nav, array('title' => 'Projects'));
 }
 protected function execute(ConduitAPIRequest $request)
 {
     $query = new PhabricatorProjectQuery();
     $query->setViewer($request->getUser());
     $query->needMembers(true);
     $query->needSlugs(true);
     $ids = $request->getValue('ids');
     if ($ids) {
         $query->withIDs($ids);
     }
     $names = $request->getValue('names');
     if ($names) {
         $query->withNames($names);
     }
     $status = $request->getValue('status');
     if ($status) {
         $query->withStatus($status);
     }
     $phids = $request->getValue('phids');
     if ($phids) {
         $query->withPHIDs($phids);
     }
     $slugs = $request->getValue('slugs');
     if ($slugs) {
         $query->withSlugs($slugs);
     }
     $request->getValue('icons');
     if ($request->getValue('icons')) {
         $icons = array();
         // the internal 'fa-' prefix is a detail hidden from api clients
         // but needs to pre prepended to the values in the icons array:
         foreach ($request->getValue('icons') as $value) {
             $icons[] = 'fa-' . $value;
         }
         $query->withIcons($icons);
     }
     $colors = $request->getValue('colors');
     if ($colors) {
         $query->withColors($colors);
     }
     $members = $request->getValue('members');
     if ($members) {
         $query->withMemberPHIDs($members);
     }
     $limit = $request->getValue('limit');
     if ($limit) {
         $query->setLimit($limit);
     }
     $offset = $request->getValue('offset');
     if ($offset) {
         $query->setOffset($offset);
     }
     $pager = $this->newPager($request);
     $results = $query->executeWithCursorPager($pager);
     $projects = $this->buildProjectInfoDictionaries($results);
     // TODO: This is pretty hideous.
     $slug_map = array();
     if ($slugs) {
         foreach ($slugs as $slug) {
             $normal = PhabricatorSlug::normalizeProjectSlug($slug);
             foreach ($projects as $project) {
                 if (in_array($normal, $project['slugs'])) {
                     $slug_map[$slug] = $project['phid'];
                 }
             }
         }
     }
     $result = array('data' => $projects, 'slugMap' => $slug_map);
     return $this->addPagerResults($result, $pager);
 }