[ Index ]

PHP Cross Reference of Phabricator

title

Body

[close]

/src/applications/almanac/controller/ -> AlmanacBindingViewController.php (source)

   1  <?php
   2  
   3  final class AlmanacBindingViewController
   4    extends AlmanacServiceController {
   5  
   6    public function shouldAllowPublic() {
   7      return true;
   8    }
   9  
  10    public function handleRequest(AphrontRequest $request) {
  11      $viewer = $request->getViewer();
  12  
  13      $id = $request->getURIData('id');
  14  
  15      $binding = id(new AlmanacBindingQuery())
  16        ->setViewer($viewer)
  17        ->withIDs(array($id))
  18        ->executeOne();
  19      if (!$binding) {
  20        return new Aphront404Response();
  21      }
  22  
  23      $service = $binding->getService();
  24      $service_uri = $service->getURI();
  25  
  26      $title = pht('Binding %s', $binding->getID());
  27  
  28      $property_list = $this->buildPropertyList($binding);
  29      $action_list = $this->buildActionList($binding);
  30      $property_list->setActionList($action_list);
  31  
  32      $header = id(new PHUIHeaderView())
  33        ->setUser($viewer)
  34        ->setHeader($title)
  35        ->setPolicyObject($binding);
  36  
  37      $box = id(new PHUIObjectBoxView())
  38        ->setHeader($header)
  39        ->addPropertyList($property_list);
  40  
  41      $crumbs = $this->buildApplicationCrumbs();
  42      $crumbs->addTextCrumb($service->getName(), $service_uri);
  43      $crumbs->addTextCrumb($title);
  44  
  45      $xactions = id(new AlmanacBindingTransactionQuery())
  46        ->setViewer($viewer)
  47        ->withObjectPHIDs(array($binding->getPHID()))
  48        ->execute();
  49  
  50      $xaction_view = id(new PhabricatorApplicationTransactionView())
  51        ->setUser($viewer)
  52        ->setObjectPHID($binding->getPHID())
  53        ->setTransactions($xactions)
  54        ->setShouldTerminate(true);
  55  
  56      return $this->buildApplicationPage(
  57        array(
  58          $crumbs,
  59          $box,
  60          $this->buildAlmanacPropertiesTable($binding),
  61          $xaction_view,
  62        ),
  63        array(
  64          'title' => $title,
  65        ));
  66    }
  67  
  68    private function buildPropertyList(AlmanacBinding $binding) {
  69      $viewer = $this->getViewer();
  70  
  71      $properties = id(new PHUIPropertyListView())
  72        ->setUser($viewer);
  73  
  74      $handles = $this->loadViewerHandles(
  75        array(
  76          $binding->getServicePHID(),
  77          $binding->getDevicePHID(),
  78          $binding->getInterface()->getNetworkPHID(),
  79        ));
  80  
  81      $properties->addProperty(
  82        pht('Service'),
  83        $handles[$binding->getServicePHID()]->renderLink());
  84  
  85      $properties->addProperty(
  86        pht('Device'),
  87        $handles[$binding->getDevicePHID()]->renderLink());
  88  
  89      $properties->addProperty(
  90        pht('Network'),
  91        $handles[$binding->getInterface()->getNetworkPHID()]->renderLink());
  92  
  93      $properties->addProperty(
  94        pht('Interface'),
  95        $binding->getInterface()->renderDisplayAddress());
  96  
  97      return $properties;
  98    }
  99  
 100    private function buildActionList(AlmanacBinding $binding) {
 101      $viewer = $this->getViewer();
 102      $id = $binding->getID();
 103  
 104      $can_edit = PhabricatorPolicyFilter::hasCapability(
 105        $viewer,
 106        $binding,
 107        PhabricatorPolicyCapability::CAN_EDIT);
 108  
 109      $actions = id(new PhabricatorActionListView())
 110        ->setUser($viewer);
 111  
 112      $actions->addAction(
 113        id(new PhabricatorActionView())
 114          ->setIcon('fa-pencil')
 115          ->setName(pht('Edit Binding'))
 116          ->setHref($this->getApplicationURI("binding/edit/{$id}/"))
 117          ->setWorkflow(!$can_edit)
 118          ->setDisabled(!$can_edit));
 119  
 120      return $actions;
 121    }
 122  
 123  }


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