public function generateProjectStatus() { $statuses = array_keys(PhabricatorProjectStatus::getStatusMap()); // Make sure 4/5th of all generated Projects are active $random = rand(0, 4); if ($random != 0) { return $statuses[0]; } else { return $statuses[1]; } }
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 . ' — ' . $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(); $user = $request->getUser(); $project = id(new PhabricatorProjectQuery())->setViewer($user)->withIDs(array($this->id))->requireCapabilities(array(PhabricatorPolicyCapability::CAN_VIEW, PhabricatorPolicyCapability::CAN_EDIT))->executeOne(); if (!$project) { return new Aphront404Response(); } $profile = $project->loadProfile(); if (empty($profile)) { $profile = new PhabricatorProjectProfile(); } $img_src = $profile->loadProfileImageURI(); $options = PhabricatorProjectStatus::getStatusMap(); $supported_formats = PhabricatorFile::getTransformableImageFormats(); $e_name = true; $e_image = null; $errors = array(); if ($request->isFormPost()) { try { $xactions = array(); $xaction = new PhabricatorProjectTransaction(); $xaction->setTransactionType(PhabricatorProjectTransactionType::TYPE_NAME); $xaction->setNewValue($request->getStr('name')); $xactions[] = $xaction; $xaction = new PhabricatorProjectTransaction(); $xaction->setTransactionType(PhabricatorProjectTransactionType::TYPE_STATUS); $xaction->setNewValue($request->getStr('status')); $xactions[] = $xaction; $xaction = new PhabricatorProjectTransaction(); $xaction->setTransactionType(PhabricatorProjectTransactionType::TYPE_CAN_VIEW); $xaction->setNewValue($request->getStr('can_view')); $xactions[] = $xaction; $xaction = new PhabricatorProjectTransaction(); $xaction->setTransactionType(PhabricatorProjectTransactionType::TYPE_CAN_EDIT); $xaction->setNewValue($request->getStr('can_edit')); $xactions[] = $xaction; $xaction = new PhabricatorProjectTransaction(); $xaction->setTransactionType(PhabricatorProjectTransactionType::TYPE_CAN_JOIN); $xaction->setNewValue($request->getStr('can_join')); $xactions[] = $xaction; $editor = new PhabricatorProjectEditor($project); $editor->setUser($user); $editor->applyTransactions($xactions); } catch (PhabricatorProjectNameCollisionException $ex) { $e_name = 'Not Unique'; $errors[] = $ex->getMessage(); } $profile->setBlurb($request->getStr('blurb')); if (!strlen($project->getName())) { $e_name = 'Required'; $errors[] = 'Project name is required.'; } else { $e_name = null; } $default_image = $request->getExists('default_image'); if ($default_image) { $profile->setProfileImagePHID(null); } else { if (!empty($_FILES['image'])) { $err = idx($_FILES['image'], 'error'); if ($err != UPLOAD_ERR_NO_FILE) { $file = PhabricatorFile::newFromPHPUpload($_FILES['image'], array('authorPHID' => $user->getPHID())); $okay = $file->isTransformableImage(); if ($okay) { $xformer = new PhabricatorImageTransformer(); $xformed = $xformer->executeThumbTransform($file, $x = 50, $y = 50); $profile->setProfileImagePHID($xformed->getPHID()); } else { $e_image = 'Not Supported'; $errors[] = 'This server only supports these image formats: ' . implode(', ', $supported_formats) . '.'; } } } } if (!$errors) { $project->save(); $profile->setProjectPHID($project->getPHID()); $profile->save(); return id(new AphrontRedirectResponse())->setURI('/project/view/' . $project->getID() . '/'); } } $error_view = null; if ($errors) { $error_view = new AphrontErrorView(); $error_view->setTitle('Form Errors'); $error_view->setErrors($errors); } $header_name = 'Edit Project'; $title = 'Edit Project'; $action = '/project/edit/' . $project->getID() . '/'; $policies = id(new PhabricatorPolicyQuery())->setViewer($user)->setObject($project)->execute(); $form = new AphrontFormView(); $form->setID('project-edit-form')->setUser($user)->setAction($action)->setEncType('multipart/form-data')->appendChild(id(new AphrontFormTextControl())->setLabel('Name')->setName('name')->setValue($project->getName())->setError($e_name))->appendChild(id(new AphrontFormSelectControl())->setLabel('Project Status')->setName('status')->setOptions($options)->setValue($project->getStatus()))->appendChild(id(new AphrontFormTextAreaControl())->setLabel('Blurb')->setName('blurb')->setValue($profile->getBlurb()))->appendChild('<p class="aphront-form-instructions">NOTE: Policy settings are not ' . 'yet fully implemented. Some interfaces still ignore these settings, ' . 'particularly "Visible To".</p>')->appendChild(id(new AphrontFormPolicyControl())->setUser($user)->setName('can_view')->setCaption('Members can always view a project.')->setPolicyObject($project)->setPolicies($policies)->setCapability(PhabricatorPolicyCapability::CAN_VIEW))->appendChild(id(new AphrontFormPolicyControl())->setUser($user)->setName('can_edit')->setPolicyObject($project)->setPolicies($policies)->setCapability(PhabricatorPolicyCapability::CAN_EDIT))->appendChild(id(new AphrontFormPolicyControl())->setUser($user)->setName('can_join')->setCaption('Users who can edit a project can always join a project.')->setPolicyObject($project)->setPolicies($policies)->setCapability(PhabricatorPolicyCapability::CAN_JOIN))->appendChild(id(new AphrontFormMarkupControl())->setLabel('Profile Image')->setValue(phutil_render_tag('img', array('src' => $img_src))))->appendChild(id(new AphrontFormImageControl())->setLabel('Change Image')->setName('image')->setError($e_image)->setCaption('Supported formats: ' . implode(', ', $supported_formats)))->appendChild(id(new AphrontFormSubmitControl())->addCancelButton('/project/view/' . $project->getID() . '/')->setValue('Save')); $panel = new AphrontPanelView(); $panel->setHeader($header_name); $panel->setWidth(AphrontPanelView::WIDTH_FORM); $panel->appendChild($form); $nav = $this->buildLocalNavigation($project); $nav->selectFilter('edit'); $nav->appendChild(array($error_view, $panel)); return $this->buildStandardPageResponse($nav, array('title' => $title)); }
public function processRequest() { $request = $this->getRequest(); $user = $request->getUser(); $project = id(new PhabricatorProject())->load($this->id); if (!$project) { return new Aphront404Response(); } $profile = $project->loadProfile(); if (empty($profile)) { $profile = new PhabricatorProjectProfile(); } if ($project->getSubprojectPHIDs()) { $phids = $project->getSubprojectPHIDs(); $handles = id(new PhabricatorObjectHandleData($phids))->loadHandles(); $subprojects = mpull($handles, 'getFullName', 'getPHID'); } else { $subprojects = array(); } $options = PhabricatorProjectStatus::getStatusMap(); $affiliations = $project->loadAffiliations(); $affiliations = mpull($affiliations, null, 'getUserPHID'); $e_name = true; $errors = array(); $state = null; if ($request->isFormPost()) { $project->setName($request->getStr('name')); $project->setStatus($request->getStr('status')); $project->setSubprojectPHIDs($request->getArr('set_subprojects')); $profile->setBlurb($request->getStr('blurb')); if (!strlen($project->getName())) { $e_name = 'Required'; $errors[] = 'Project name is required.'; } else { $e_name = null; } if (!empty($_FILES['image'])) { $err = idx($_FILES['image'], 'error'); if ($err != UPLOAD_ERR_NO_FILE) { $file = PhabricatorFile::newFromPHPUpload($_FILES['image'], array('authorPHID' => $user->getPHID())); $okay = $file->isTransformableImage(); if ($okay) { $xformer = new PhabricatorImageTransformer(); $xformed = $xformer->executeProfileTransform($file, $width = 280, $min_height = 140, $max_height = 420); $profile->setProfileImagePHID($xformed->getPHID()); } else { $errors[] = 'Only valid image files (jpg, jpeg, png or gif) ' . 'will be accepted.'; } } } $resources = $request->getStr('resources'); $resources = json_decode($resources, true); if (!is_array($resources)) { throw new Exception("Project resource information was not correctly encoded in the " . "request."); } $state = array(); foreach ($resources as $resource) { $user_phid = $resource['phid']; if (!$user_phid) { continue; } if (isset($state[$user_phid])) { // TODO: We should deal with this better -- the user has entered // the same resource more than once. } $state[$user_phid] = array('phid' => $user_phid, 'status' => $resource['status'], 'role' => $resource['role'], 'owner' => $resource['owner']); } $all_phids = array_merge(array_keys($state), array_keys($affiliations)); $all_phids = array_unique($all_phids); $delete_affiliations = array(); $save_affiliations = array(); foreach ($all_phids as $phid) { $old = idx($affiliations, $phid); $new = idx($state, $phid); if ($old && !$new) { $delete_affiliations[] = $affiliations[$phid]; continue; } if (!$old) { $affil = new PhabricatorProjectAffiliation(); $affil->setUserPHID($phid); } else { $affil = $old; } $affil->setRole((string) $new['role']); $affil->setStatus((string) $new['status']); $affil->setIsOwner((int) $new['owner']); $save_affiliations[] = $affil; } if (!$errors) { $project->save(); $profile->setProjectPHID($project->getPHID()); $profile->save(); foreach ($delete_affiliations as $affil) { $affil->delete(); } foreach ($save_affiliations as $save) { $save->setProjectPHID($project->getPHID()); $save->save(); } return id(new AphrontRedirectResponse())->setURI('/project/view/' . $project->getID() . '/'); } else { $phids = array_keys($state); $handles = id(new PhabricatorObjectHandleData($phids))->loadHandles(); foreach ($state as $phid => $info) { $state[$phid]['name'] = $handles[$phid]->getFullName(); } } } else { $phids = mpull($affiliations, 'getUserPHID'); $handles = id(new PhabricatorObjectHandleData($phids))->loadHandles(); $state = array(); foreach ($affiliations as $affil) { $user_phid = $affil->getUserPHID(); $state[] = array('phid' => $user_phid, 'name' => $handles[$user_phid]->getFullName(), 'status' => $affil->getStatus(), 'role' => $affil->getRole(), 'owner' => $affil->getIsOwner()); } } $error_view = null; if ($errors) { $error_view = new AphrontErrorView(); $error_view->setTitle('Form Errors'); $error_view->setErrors($errors); } $header_name = 'Edit Project'; $title = 'Edit Project'; $action = '/project/edit/' . $project->getID() . '/'; require_celerity_resource('project-edit-css'); $form = new AphrontFormView(); $form->setID('project-edit-form')->setUser($user)->setAction($action)->setEncType('multipart/form-data')->appendChild(id(new AphrontFormTextControl())->setLabel('Name')->setName('name')->setValue($project->getName())->setError($e_name))->appendChild(id(new AphrontFormSelectControl())->setLabel('Project Status')->setName('status')->setOptions($options)->setValue($project->getStatus()))->appendChild(id(new AphrontFormTextAreaControl())->setLabel('Blurb')->setName('blurb')->setValue($profile->getBlurb()))->appendChild(id(new AphrontFormTokenizerControl())->setDatasource('/typeahead/common/projects/')->setLabel('Subprojects')->setName('set_subprojects')->setValue($subprojects))->appendChild(id(new AphrontFormFileControl())->setLabel('Change Image')->setName('image'))->appendChild('<h1>Resources</h1>' . '<input type="hidden" name="resources" id="resources" />' . '<div class="aphront-form-inset">' . '<div style="float: right;">' . javelin_render_tag('a', array('href' => '#', 'class' => 'button green', 'sigil' => 'add-resource', 'mustcapture' => true), 'Add New Resource') . '</div>' . '<p></p>' . '<div style="clear: both;"></div>' . javelin_render_tag('table', array('sigil' => 'resources', 'class' => 'project-resource-table'), '') . '</div>')->appendChild(id(new AphrontFormSubmitControl())->addCancelButton('/project/view/' . $project->getID() . '/')->setValue('Save')); $template = new AphrontTokenizerTemplateView(); $template = $template->render(); Javelin::initBehavior('projects-resource-editor', array('root' => 'project-edit-form', 'tokenizerTemplate' => $template, 'tokenizerSource' => '/typeahead/common/users/', 'input' => 'resources', 'state' => array_values($state))); $panel = new AphrontPanelView(); $panel->setHeader($header_name); $panel->setWidth(AphrontPanelView::WIDTH_WIDE); $panel->appendChild($form); return $this->buildStandardPageResponse(array($error_view, $panel), array('title' => $title)); }
public function processRequest() { $request = $this->getRequest(); $user = $request->getUser(); $project = id(new PhabricatorProject())->load($this->id); if (!$project) { return new Aphront404Response(); } $profile = $project->loadProfile(); if (empty($profile)) { $profile = new PhabricatorProjectProfile(); } $img_src = $profile->loadProfileImageURI(); if ($project->getSubprojectPHIDs()) { $phids = $project->getSubprojectPHIDs(); $handles = id(new PhabricatorObjectHandleData($phids))->loadHandles(); $subprojects = mpull($handles, 'getFullName', 'getPHID'); } else { $subprojects = array(); } $options = PhabricatorProjectStatus::getStatusMap(); $affiliations = $project->loadAffiliations(); $affiliations = mpull($affiliations, null, 'getUserPHID'); $supported_formats = PhabricatorFile::getTransformableImageFormats(); $e_name = true; $e_image = null; $errors = array(); $state = null; if ($request->isFormPost()) { try { $xactions = array(); $xaction = new PhabricatorProjectTransaction(); $xaction->setTransactionType(PhabricatorProjectTransactionType::TYPE_NAME); $xaction->setNewValue($request->getStr('name')); $xactions[] = $xaction; $xaction = new PhabricatorProjectTransaction(); $xaction->setTransactionType(PhabricatorProjectTransactionType::TYPE_STATUS); $xaction->setNewValue($request->getStr('status')); $xactions[] = $xaction; $editor = new PhabricatorProjectEditor($project); $editor->setUser($user); $editor->applyTransactions($xactions); } catch (PhabricatorProjectNameCollisionException $ex) { $e_name = 'Not Unique'; $errors[] = $ex->getMessage(); } $project->setSubprojectPHIDs($request->getArr('set_subprojects')); $profile->setBlurb($request->getStr('blurb')); if (!strlen($project->getName())) { $e_name = 'Required'; $errors[] = 'Project name is required.'; } else { $e_name = null; } $default_image = $request->getExists('default_image'); if ($default_image) { $profile->setProfileImagePHID(null); } else { if (!empty($_FILES['image'])) { $err = idx($_FILES['image'], 'error'); if ($err != UPLOAD_ERR_NO_FILE) { $file = PhabricatorFile::newFromPHPUpload($_FILES['image'], array('authorPHID' => $user->getPHID())); $okay = $file->isTransformableImage(); if ($okay) { $xformer = new PhabricatorImageTransformer(); $xformed = $xformer->executeThumbTransform($file, $x = 50, $y = 50); $profile->setProfileImagePHID($xformed->getPHID()); } else { $e_image = 'Not Supported'; $errors[] = 'This server only supports these image formats: ' . implode(', ', $supported_formats) . '.'; } } } } $resources = $request->getStr('resources'); $resources = json_decode($resources, true); if (!is_array($resources)) { throw new Exception("Project resource information was not correctly encoded in the " . "request."); } $state = array(); foreach ($resources as $resource) { $user_phid = $resource['phid']; if (!$user_phid) { continue; } if (isset($state[$user_phid])) { // TODO: We should deal with this better -- the user has entered // the same resource more than once. } $state[$user_phid] = array('phid' => $user_phid, 'role' => $resource['role'], 'owner' => $resource['owner']); } $all_phids = array_merge(array_keys($state), array_keys($affiliations)); $all_phids = array_unique($all_phids); $delete_affiliations = array(); $save_affiliations = array(); foreach ($all_phids as $phid) { $old = idx($affiliations, $phid); $new = idx($state, $phid); if ($old && !$new) { $delete_affiliations[] = $affiliations[$phid]; continue; } if (!$old) { $affil = new PhabricatorProjectAffiliation(); $affil->setUserPHID($phid); } else { $affil = $old; } $affil->setRole((string) $new['role']); $affil->setIsOwner((int) $new['owner']); $save_affiliations[] = $affil; } if (!$errors) { $project->save(); $profile->setProjectPHID($project->getPHID()); $profile->save(); foreach ($delete_affiliations as $affil) { $affil->delete(); } foreach ($save_affiliations as $save) { $save->setProjectPHID($project->getPHID()); $save->save(); } return id(new AphrontRedirectResponse())->setURI('/project/view/' . $project->getID() . '/'); } else { $phids = array_keys($state); $handles = id(new PhabricatorObjectHandleData($phids))->loadHandles(); foreach ($state as $phid => $info) { $state[$phid]['name'] = $handles[$phid]->getFullName(); } } } else { $phids = mpull($affiliations, 'getUserPHID'); $handles = id(new PhabricatorObjectHandleData($phids))->loadHandles(); $state = array(); foreach ($affiliations as $affil) { $user_phid = $affil->getUserPHID(); $state[] = array('phid' => $user_phid, 'name' => $handles[$user_phid]->getFullName(), 'role' => $affil->getRole(), 'owner' => $affil->getIsOwner()); } } $error_view = null; if ($errors) { $error_view = new AphrontErrorView(); $error_view->setTitle('Form Errors'); $error_view->setErrors($errors); } $header_name = 'Edit Project'; $title = 'Edit Project'; $action = '/project/edit/' . $project->getID() . '/'; require_celerity_resource('project-edit-css'); $form = new AphrontFormView(); $form->setID('project-edit-form')->setUser($user)->setAction($action)->setEncType('multipart/form-data')->appendChild(id(new AphrontFormTextControl())->setLabel('Name')->setName('name')->setValue($project->getName())->setError($e_name))->appendChild(id(new AphrontFormSelectControl())->setLabel('Project Status')->setName('status')->setOptions($options)->setValue($project->getStatus()))->appendChild(id(new AphrontFormTextAreaControl())->setLabel('Blurb')->setName('blurb')->setValue($profile->getBlurb()))->appendChild(id(new AphrontFormTokenizerControl())->setDatasource('/typeahead/common/projects/')->setLabel('Subprojects')->setName('set_subprojects')->setValue($subprojects))->appendChild(id(new AphrontFormMarkupControl())->setLabel('Profile Image')->setValue(phutil_render_tag('img', array('src' => $img_src))))->appendChild(id(new AphrontFormImageControl())->setLabel('Change Image')->setName('image')->setError($e_image)->setCaption('Supported formats: ' . implode(', ', $supported_formats)))->appendChild(id(new AphrontFormInsetView())->setTitle('Resources')->setRightButton(javelin_render_tag('a', array('href' => '#', 'class' => 'button green', 'sigil' => 'add-resource', 'mustcapture' => true), 'Add New Resource'))->appendChild(phutil_render_tag('input', array('type' => 'hidden', 'name' => 'resources', 'id' => 'resources')))->setContent(javelin_render_tag('table', array('sigil' => 'resources', 'class' => 'project-resource-table'), '')))->appendChild(id(new AphrontFormSubmitControl())->addCancelButton('/project/view/' . $project->getID() . '/')->setValue('Save')); $template = new AphrontTokenizerTemplateView(); $template = $template->render(); Javelin::initBehavior('projects-resource-editor', array('root' => 'project-edit-form', 'tokenizerTemplate' => $template, 'tokenizerSource' => '/typeahead/common/users/', 'input' => 'resources', 'state' => array_values($state))); $panel = new AphrontPanelView(); $panel->setHeader($header_name); $panel->setWidth(AphrontPanelView::WIDTH_WIDE); $panel->appendChild($form); return $this->buildStandardPageResponse(array($error_view, $panel), array('title' => $title)); }
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')); }