| 
									
										
										
										
											2014-02-16 20:17:52 -08:00
										 |  |  | <?php | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | final class PhabricatorProjectEditMainController | 
					
						
							|  |  |  |   extends PhabricatorProjectController { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   private $id; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   public function willProcessRequest(array $data) { | 
					
						
							|  |  |  |     $this->id = idx($data, 'id'); | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   public function processRequest() { | 
					
						
							|  |  |  |     $request = $this->getRequest(); | 
					
						
							|  |  |  |     $viewer = $request->getUser(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     $project = id(new PhabricatorProjectQuery()) | 
					
						
							|  |  |  |       ->setViewer($viewer) | 
					
						
							|  |  |  |       ->withIDs(array($this->id)) | 
					
						
							|  |  |  |       ->needImages(true) | 
					
						
							|  |  |  |       ->executeOne(); | 
					
						
							|  |  |  |     if (!$project) { | 
					
						
							|  |  |  |       return new Aphront404Response(); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     $header = id(new PHUIHeaderView()) | 
					
						
							|  |  |  |       ->setHeader(pht('Edit %s', $project->getName())) | 
					
						
							|  |  |  |       ->setUser($viewer) | 
					
						
							|  |  |  |       ->setPolicyObject($project) | 
					
						
							|  |  |  |       ->setImage($project->getProfileImageURI()); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if ($project->getStatus() == PhabricatorProjectStatus::STATUS_ACTIVE) { | 
					
						
							|  |  |  |       $header->setStatus('oh-ok', '', pht('Active')); | 
					
						
							|  |  |  |     } else { | 
					
						
							|  |  |  |       $header->setStatus('policy-noone', '', pht('Archived')); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     $actions = $this->buildActionListView($project); | 
					
						
							|  |  |  |     $properties = $this->buildPropertyListView($project, $actions); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     $crumbs = $this->buildApplicationCrumbs(); | 
					
						
							|  |  |  |     $crumbs->addTextCrumb( | 
					
						
							|  |  |  |       $project->getName(), | 
					
						
							|  |  |  |       $this->getApplicationURI('view/'.$project->getID().'/')); | 
					
						
							|  |  |  |     $crumbs->addTextCrumb(pht('Edit')); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     $object_box = id(new PHUIObjectBoxView()) | 
					
						
							|  |  |  |       ->setHeader($header) | 
					
						
							|  |  |  |       ->addPropertyList($properties); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     $xactions = id(new PhabricatorProjectTransactionQuery()) | 
					
						
							|  |  |  |       ->setViewer($viewer) | 
					
						
							|  |  |  |       ->withObjectPHIDs(array($project->getPHID())) | 
					
						
							|  |  |  |       ->execute(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     $timeline = id(new PhabricatorApplicationTransactionView()) | 
					
						
							|  |  |  |       ->setUser($viewer) | 
					
						
							|  |  |  |       ->setObjectPHID($project->getPHID()) | 
					
						
							| 
									
										
										
										
											2014-03-14 08:51:50 -07:00
										 |  |  |       ->setShouldTerminate(true) | 
					
						
							| 
									
										
										
										
											2014-02-16 20:17:52 -08:00
										 |  |  |       ->setTransactions($xactions); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     return $this->buildApplicationPage( | 
					
						
							|  |  |  |       array( | 
					
						
							|  |  |  |         $crumbs, | 
					
						
							|  |  |  |         $object_box, | 
					
						
							|  |  |  |         $timeline, | 
					
						
							|  |  |  |       ), | 
					
						
							|  |  |  |       array( | 
					
						
							|  |  |  |         'title' => $project->getName(), | 
					
						
							|  |  |  |         'device' => true, | 
					
						
							|  |  |  |       )); | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   private function buildActionListView(PhabricatorProject $project) { | 
					
						
							|  |  |  |     $request = $this->getRequest(); | 
					
						
							|  |  |  |     $viewer = $request->getUser(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     $id = $project->getID(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     $view = id(new PhabricatorActionListView()) | 
					
						
							|  |  |  |       ->setUser($viewer) | 
					
						
							|  |  |  |       ->setObjectURI($request->getRequestURI()); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     $can_edit = PhabricatorPolicyFilter::hasCapability( | 
					
						
							|  |  |  |       $viewer, | 
					
						
							|  |  |  |       $project, | 
					
						
							|  |  |  |       PhabricatorPolicyCapability::CAN_EDIT); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     $view->addAction( | 
					
						
							|  |  |  |       id(new PhabricatorActionView()) | 
					
						
							|  |  |  |         ->setName(pht('Edit Details')) | 
					
						
							|  |  |  |         ->setIcon('edit') | 
					
						
							|  |  |  |         ->setHref($this->getApplicationURI("details/{$id}/")) | 
					
						
							|  |  |  |         ->setDisabled(!$can_edit) | 
					
						
							|  |  |  |         ->setWorkflow(!$can_edit)); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     $view->addAction( | 
					
						
							|  |  |  |       id(new PhabricatorActionView()) | 
					
						
							|  |  |  |         ->setName(pht('Edit Picture')) | 
					
						
							|  |  |  |         ->setIcon('image') | 
					
						
							|  |  |  |         ->setHref($this->getApplicationURI("picture/{$id}/")) | 
					
						
							|  |  |  |         ->setDisabled(!$can_edit) | 
					
						
							|  |  |  |         ->setWorkflow(!$can_edit)); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if ($project->isArchived()) { | 
					
						
							|  |  |  |       $view->addAction( | 
					
						
							|  |  |  |         id(new PhabricatorActionView()) | 
					
						
							|  |  |  |           ->setName(pht('Unarchive Project')) | 
					
						
							|  |  |  |           ->setIcon('enable') | 
					
						
							|  |  |  |           ->setHref($this->getApplicationURI("archive/{$id}/")) | 
					
						
							|  |  |  |           ->setDisabled(!$can_edit) | 
					
						
							|  |  |  |           ->setWorkflow(true)); | 
					
						
							|  |  |  |     } else { | 
					
						
							|  |  |  |       $view->addAction( | 
					
						
							|  |  |  |         id(new PhabricatorActionView()) | 
					
						
							|  |  |  |           ->setName(pht('Archive Project')) | 
					
						
							|  |  |  |           ->setIcon('disable') | 
					
						
							|  |  |  |           ->setHref($this->getApplicationURI("archive/{$id}/")) | 
					
						
							|  |  |  |           ->setDisabled(!$can_edit) | 
					
						
							|  |  |  |           ->setWorkflow(true)); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     return $view; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   private function buildPropertyListView( | 
					
						
							|  |  |  |     PhabricatorProject $project, | 
					
						
							|  |  |  |     PhabricatorActionListView $actions) { | 
					
						
							|  |  |  |     $request = $this->getRequest(); | 
					
						
							|  |  |  |     $viewer = $request->getUser(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     $view = id(new PHUIPropertyListView()) | 
					
						
							|  |  |  |       ->setUser($viewer) | 
					
						
							|  |  |  |       ->setObject($project) | 
					
						
							|  |  |  |       ->setActionList($actions); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     $descriptions = PhabricatorPolicyQuery::renderPolicyDescriptions( | 
					
						
							|  |  |  |       $viewer, | 
					
						
							|  |  |  |       $project); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     $view->addProperty( | 
					
						
							|  |  |  |       pht('Visible To'), | 
					
						
							|  |  |  |       $descriptions[PhabricatorPolicyCapability::CAN_VIEW]); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     $view->addProperty( | 
					
						
							|  |  |  |       pht('Editable By'), | 
					
						
							|  |  |  |       $descriptions[PhabricatorPolicyCapability::CAN_EDIT]); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     $view->addProperty( | 
					
						
							|  |  |  |       pht('Joinable By'), | 
					
						
							|  |  |  |       $descriptions[PhabricatorPolicyCapability::CAN_JOIN]); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     return $view; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | } |