[ Index ]

PHP Cross Reference of Phabricator

title

Body

[close]

/src/applications/harbormaster/controller/ -> HarbormasterPlanEditController.php (source)

   1  <?php
   2  
   3  final class HarbormasterPlanEditController extends HarbormasterPlanController {
   4  
   5    private $id;
   6  
   7    public function willProcessRequest(array $data) {
   8      $this->id = idx($data, 'id');
   9    }
  10  
  11    public function processRequest() {
  12      $request = $this->getRequest();
  13      $viewer = $request->getUser();
  14  
  15      $this->requireApplicationCapability(
  16        HarbormasterManagePlansCapability::CAPABILITY);
  17  
  18      if ($this->id) {
  19        $plan = id(new HarbormasterBuildPlanQuery())
  20          ->setViewer($viewer)
  21          ->withIDs(array($this->id))
  22          ->executeOne();
  23        if (!$plan) {
  24          return new Aphront404Response();
  25        }
  26      } else {
  27        $plan = HarbormasterBuildPlan::initializeNewBuildPlan($viewer);
  28      }
  29  
  30      $e_name = true;
  31      $v_name = $plan->getName();
  32      $validation_exception = null;
  33      if ($request->isFormPost()) {
  34        $xactions = array();
  35  
  36        $v_name = $request->getStr('name');
  37        $e_name = null;
  38        $type_name = HarbormasterBuildPlanTransaction::TYPE_NAME;
  39  
  40        $xactions[] = id(new HarbormasterBuildPlanTransaction())
  41          ->setTransactionType($type_name)
  42          ->setNewValue($v_name);
  43  
  44        $editor = id(new HarbormasterBuildPlanEditor())
  45          ->setActor($viewer)
  46          ->setContentSourceFromRequest($request);
  47  
  48        try {
  49          $editor->applyTransactions($plan, $xactions);
  50          return id(new AphrontRedirectResponse())
  51            ->setURI($this->getApplicationURI('plan/'.$plan->getID().'/'));
  52        } catch (PhabricatorApplicationTransactionValidationException $ex) {
  53          $validation_exception = $ex;
  54  
  55          $e_name = $validation_exception->getShortMessage(
  56            HarbormasterBuildPlanTransaction::TYPE_NAME);
  57        }
  58  
  59      }
  60  
  61      $is_new = (!$plan->getID());
  62      if ($is_new) {
  63        $title = pht('New Build Plan');
  64        $cancel_uri = $this->getApplicationURI();
  65        $save_button = pht('Create Build Plan');
  66      } else {
  67        $id = $plan->getID();
  68  
  69        $title = pht('Edit Build Plan');
  70        $cancel_uri = $this->getApplicationURI('plan/'.$plan->getID().'/');
  71        $save_button = pht('Save Build Plan');
  72      }
  73  
  74      $form = id(new AphrontFormView())
  75        ->setUser($viewer)
  76        ->appendChild(
  77          id(new AphrontFormTextControl())
  78            ->setLabel('Plan Name')
  79            ->setName('name')
  80            ->setError($e_name)
  81            ->setValue($v_name));
  82  
  83      $form->appendChild(
  84        id(new AphrontFormSubmitControl())
  85          ->setValue($save_button)
  86          ->addCancelButton($cancel_uri));
  87  
  88      $box = id(new PHUIObjectBoxView())
  89        ->setHeaderText($title)
  90        ->setValidationException($validation_exception)
  91        ->setForm($form);
  92  
  93      $crumbs = $this->buildApplicationCrumbs();
  94      if ($is_new) {
  95        $crumbs->addTextCrumb(pht('New Build Plan'));
  96      } else {
  97        $id = $plan->getID();
  98        $crumbs->addTextCrumb(
  99          pht('Plan %d', $id),
 100          $this->getApplicationURI("plan/{$id}/"));
 101        $crumbs->addTextCrumb(pht('Edit'));
 102      }
 103  
 104      return $this->buildApplicationPage(
 105        array(
 106          $crumbs,
 107          $box,
 108        ),
 109        array(
 110          'title' => $title,
 111        ));
 112    }
 113  
 114  }


Generated: Sun Nov 30 09:20:46 2014 Cross-referenced by PHPXref 0.7.1