public function renderView()
 {
     $data = $this->getStoryData();
     $view = new PhabricatorFeedStoryView();
     $type = $data->getValue('type');
     $old = $data->getValue('old');
     $new = $data->getValue('new');
     $proj_phid = $data->getValue('projectPHID');
     $author_phid = $data->getAuthorPHID();
     switch ($type) {
         case PhabricatorProjectTransactionType::TYPE_NAME:
             if (strlen($old)) {
                 $action = 'renamed project ' . $this->linkTo($proj_phid) . ' from ' . $this->renderString($old) . ' to ' . $this->renderString($new) . '.';
             } else {
                 $action = 'created project ' . $this->linkTo($proj_phid) . ' (as ' . $this->renderString($new) . ').';
             }
             break;
         case PhabricatorProjectTransactionType::TYPE_STATUS:
             $action = 'changed project ' . $this->linkTo($proj_phid) . ' status from ' . $this->renderString(PhabricatorProjectStatus::getNameForStatus($old)) . ' to ' . $this->renderString(PhabricatorProjectStatus::getNameForStatus($new)) . '.';
             break;
         case PhabricatorProjectTransactionType::TYPE_MEMBERS:
             $add = array_diff($new, $old);
             $rem = array_diff($old, $new);
             if (count($add) == 1 && count($rem) == 0 && head($add) == $author_phid) {
                 $action = 'joined project ' . $this->linkTo($proj_phid) . '.';
             } else {
                 if (count($add) == 0 && count($rem) == 1 && head($rem) == $author_phid) {
                     $action = 'left project ' . $this->linkTo($proj_phid) . '.';
                 } else {
                     if (empty($rem)) {
                         $action = 'added members to project ' . $this->linkTo($proj_phid) . ': ' . $this->renderHandleList($add) . '.';
                     } else {
                         if (empty($add)) {
                             $action = 'removed members from project ' . $this->linkTo($proj_phid) . ': ' . $this->renderHandleList($rem) . '.';
                         } else {
                             $action = 'changed members of project ' . $this->linkTo($proj_phid) . ', added: ' . $this->renderHandleList($add) . '; removed: ' . $this->renderHandleList($rem) . '.';
                         }
                     }
                 }
             }
             break;
         default:
             $action = 'updated project ' . $this->linkTo($proj_phid) . '.';
             break;
     }
     $view->setTitle($this->linkTo($author_phid) . ' ' . $action);
     $view->setOneLineStory(true);
     return $view;
 }
 public function processRequest()
 {
     $projects = id(new PhabricatorProject())->loadAllWhere('1 = 1 ORDER BY id DESC limit 100');
     $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);
     }
     $author_phids = mpull($projects, 'getAuthorPHID');
     $handles = id(new PhabricatorObjectHandleData($author_phids))->loadHandles();
     $query = id(new ManiphestTaskQuery())->withProjects($project_phids)->withAnyProject(true)->withStatus(ManiphestTaskQuery::STATUS_OPEN)->setLimit(PHP_INT_MAX);
     $tasks = $query->execute();
     $groups = array();
     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);
         $status = PhabricatorProjectStatus::getNameForStatus($project->getStatus());
         $blurb = $profile->getBlurb();
         $blurb = phutil_utf8_shorten($blurb, $columns = 100);
         $rows[] = array(phutil_escape_html($project->getName()), phutil_escape_html($blurb), $handles[$project->getAuthorPHID()]->renderLink(), phutil_escape_html($population), phutil_escape_html($status), phutil_render_tag('a', array('href' => '/maniphest/view/all/?projects=' . $phid), phutil_escape_html($task_count)), phutil_render_tag('a', array('class' => 'small grey button', 'href' => '/project/view/' . $project->getID() . '/'), 'View Project Profile'));
     }
     $table = new AphrontTableView($rows);
     $table->setHeaders(array('Project', 'Description', 'Mastermind', 'Population', 'Status', 'Open Tasks', ''));
     $table->setColumnClasses(array('pri', 'wide', '', 'right', '', 'right', 'action'));
     $panel = new AphrontPanelView();
     $panel->appendChild($table);
     $panel->setHeader('Project');
     $panel->setCreateButton('Create New Project', '/project/create/');
     return $this->buildStandardPageResponse($panel, array('title' => 'Projects'));
 }
 private function renderBasicInformation($project, $profile)
 {
     $blurb = nonempty($profile->getBlurb(), '//Nothing is known about this elusive project.//');
     $engine = PhabricatorMarkupEngine::newProfileMarkupEngine();
     $blurb = $engine->markupText($blurb);
     $affiliations = $project->loadAffiliations();
     $phids = array_merge(array($project->getAuthorPHID()), $project->getSubprojectPHIDs(), mpull($affiliations, 'getUserPHID'));
     $phids = array_unique($phids);
     $handles = id(new PhabricatorObjectHandleData($phids))->loadHandles();
     $affiliated = array();
     foreach ($affiliations as $affiliation) {
         $user = $handles[$affiliation->getUserPHID()]->renderLink();
         $role = phutil_escape_html($affiliation->getRole());
         $status = null;
         if ($affiliation->getStatus() == 'former') {
             $role = '<em>Former ' . $role . '</em>';
         }
         $affiliated[] = '<li>' . $user . ' &mdash; ' . $role . $status . '</li>';
     }
     if ($affiliated) {
         $affiliated = '<ul>' . implode("\n", $affiliated) . '</ul>';
     } else {
         $affiliated = '<p><em>No one is affiliated with this project.</em></p>';
     }
     if ($project->getSubprojectPHIDs()) {
         $table = $this->renderSubprojectTable($handles, $project->getSubprojectPHIDs());
         $subproject_list = $table->render();
     } else {
         $subproject_list = '<p><em>There are no projects attached for such specie.</em></p>';
     }
     $timestamp = phabricator_format_timestamp($project->getDateCreated());
     $status = PhabricatorProjectStatus::getNameForStatus($project->getStatus());
     $content = '<div class="phabricator-profile-info-group">
     <h1 class="phabricator-profile-info-header">Basic Information</h1>
     <div class="phabricator-profile-info-pane">
       <table class="phabricator-profile-info-table">
         <tr>
           <th>Creator</th>
           <td>' . $handles[$project->getAuthorPHID()]->renderLink() . '</td>
         </tr>
         <tr>
           <th>Status</th>
           <td><strong>' . phutil_escape_html($status) . '</strong></td>
         </tr>
         <tr>
           <th>Created</th>
           <td>' . $timestamp . '</td>
         </tr>
         <tr>
           <th>PHID</th>
           <td>' . phutil_escape_html($project->getPHID()) . '</td>
         </tr>
         <tr>
           <th>Blurb</th>
           <td>' . $blurb . '</td>
         </tr>
       </table>
     </div>
   </div>';
     $content .= '<div class="phabricator-profile-info-group">' . '<h1 class="phabricator-profile-info-header">Resources</h1>' . '<div class="phabricator-profile-info-pane">' . $affiliated . '</div>' . '</div>';
     $content .= '<div class="phabricator-profile-info-group">' . '<h1 class="phabricator-profile-info-header">Subprojects</h1>' . '<div class="phabricator-profile-info-pane">' . $subproject_list . '</div>' . '</div>';
     $query = id(new ManiphestTaskQuery())->withProjects(array($project->getPHID()))->withStatus(ManiphestTaskQuery::STATUS_OPEN)->setOrderBy(ManiphestTaskQuery::ORDER_PRIORITY)->setLimit(10)->setCalculateRows(true);
     $tasks = $query->execute();
     $count = $query->getRowCount();
     $phids = mpull($tasks, 'getOwnerPHID');
     $phids = array_filter($phids);
     $handles = id(new PhabricatorObjectHandleData($phids))->loadHandles();
     $task_views = array();
     foreach ($tasks as $task) {
         $view = id(new ManiphestTaskSummaryView())->setTask($task)->setHandles($handles)->setUser($this->getRequest()->getUser());
         $task_views[] = $view->render();
     }
     if (empty($tasks)) {
         $task_views = '<em>No open tasks.</em>';
     } else {
         $task_views = implode('', $task_views);
     }
     $open = number_format($count);
     $more_link = phutil_render_tag('a', array('href' => '/maniphest/view/all/?projects=' . $project->getPHID()), "View All Open Tasks »");
     $content .= '<div class="phabricator-profile-info-group">
     <h1 class="phabricator-profile-info-header">' . "Open Tasks ({$open})" . '</h1>' . '<div class="phabricator-profile-info-pane">' . $task_views . '<div class="phabricator-profile-info-pane-more-link">' . $more_link . '</div>' . '</div>
   </div>';
     return $content;
 }
 public function processRequest()
 {
     $request = $this->getRequest();
     $nav = new AphrontSideNavFilterView();
     $nav->setBaseURI(new PhutilURI('/project/filter/'))->addLabel('User')->addFilter('active', 'Active')->addSpacer()->addLabel('All')->addFilter('all', 'All Projects')->addFilter('allactive', 'Active 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->setViewer($request->getUser());
     $query->needMembers(true);
     $view_phid = $request->getUser()->getPHID();
     $status_filter = PhabricatorProjectQuery::STATUS_ANY;
     switch ($this->filter) {
         case 'active':
             $table_header = 'Your Projects';
             $query->withMemberPHIDs(array($view_phid));
             $query->withStatus(PhabricatorProjectQuery::STATUS_ACTIVE);
             break;
         case 'allactive':
             $status_filter = PhabricatorProjectQuery::STATUS_ACTIVE;
             $table_header = 'Active Projects';
             // fallthrough
         // fallthrough
         case 'all':
             $table_header = 'All Projects';
             $query->withStatus($status_filter);
             break;
     }
     $projects = $query->executeWithOffsetPager($pager);
     $project_phids = mpull($projects, 'getPHID');
     $profiles = array();
     if ($projects) {
         $profiles = id(new PhabricatorProjectProfile())->loadAllWhere('projectPHID in (%Ls)', $project_phids);
         $profiles = mpull($profiles, null, 'getProjectPHID');
     }
     $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 = idx($profiles, $phid);
         $members = $project->getMemberPHIDs();
         $group = idx($groups, $phid, array());
         $task_count = count($group);
         $population = count($members);
         if ($profile) {
             $blurb = $profile->getBlurb();
             $blurb = phutil_utf8_shorten($blurb, 64);
         } else {
             $blurb = null;
         }
         $rows[] = array(phutil_render_tag('a', array('href' => '/project/view/' . $project->getID() . '/'), phutil_escape_html($project->getName())), phutil_escape_html(PhabricatorProjectStatus::getNameForStatus($project->getStatus())), 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', 'Status', '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'));
 }