[ Index ]

PHP Cross Reference of Phabricator

title

Body

[close]

/src/applications/phragment/controller/ -> PhragmentSnapshotViewController.php (source)

   1  <?php
   2  
   3  final class PhragmentSnapshotViewController extends PhragmentController {
   4  
   5    private $id;
   6  
   7    public function shouldAllowPublic() {
   8      return true;
   9    }
  10  
  11    public function willProcessRequest(array $data) {
  12      $this->id = idx($data, 'id', '');
  13    }
  14  
  15    public function processRequest() {
  16      $request = $this->getRequest();
  17      $viewer = $request->getUser();
  18  
  19      $snapshot = id(new PhragmentSnapshotQuery())
  20        ->setViewer($viewer)
  21        ->withIDs(array($this->id))
  22        ->executeOne();
  23      if ($snapshot === null) {
  24        return new Aphront404Response();
  25      }
  26  
  27      $box = $this->createSnapshotView($snapshot);
  28  
  29      $fragment = id(new PhragmentFragmentQuery())
  30        ->setViewer($viewer)
  31        ->withPHIDs(array($snapshot->getPrimaryFragmentPHID()))
  32        ->executeOne();
  33      if ($fragment === null) {
  34        return new Aphront404Response();
  35      }
  36  
  37      $parents = $this->loadParentFragments($fragment->getPath());
  38      if ($parents === null) {
  39        return new Aphront404Response();
  40      }
  41  
  42      $crumbs = $this->buildApplicationCrumbsWithPath($parents);
  43      $crumbs->addTextCrumb(pht('"%s" Snapshot', $snapshot->getName()));
  44  
  45      $children = id(new PhragmentSnapshotChildQuery())
  46        ->setViewer($viewer)
  47        ->needFragments(true)
  48        ->needFragmentVersions(true)
  49        ->withSnapshotPHIDs(array($snapshot->getPHID()))
  50        ->execute();
  51  
  52      $list = id(new PHUIObjectItemListView())
  53        ->setUser($viewer);
  54  
  55      foreach ($children as $child) {
  56        $item = id(new PHUIObjectItemView())
  57          ->setHeader($child->getFragment()->getPath());
  58  
  59        if ($child->getFragmentVersion() !== null) {
  60          $item
  61            ->setHref($child->getFragmentVersion()->getURI())
  62            ->addAttribute(pht(
  63              'Version %s',
  64              $child->getFragmentVersion()->getSequence()));
  65        } else {
  66          $item
  67            ->setHref($child->getFragment()->getURI())
  68            ->addAttribute(pht('Directory'));
  69        }
  70  
  71        $list->addItem($item);
  72      }
  73  
  74      return $this->buildApplicationPage(
  75        array(
  76          $crumbs,
  77          $this->renderConfigurationWarningIfRequired(),
  78          $box,
  79          $list,
  80        ),
  81        array(
  82          'title' => pht('View Snapshot'),
  83        ));
  84    }
  85  
  86    protected function createSnapshotView($snapshot) {
  87      if ($snapshot === null) {
  88        return null;
  89      }
  90  
  91      $viewer = $this->getRequest()->getUser();
  92  
  93      $phids = array();
  94      $phids[] = $snapshot->getPrimaryFragmentPHID();
  95  
  96      $this->loadHandles($phids);
  97  
  98      $header = id(new PHUIHeaderView())
  99        ->setHeader(pht('"%s" Snapshot', $snapshot->getName()))
 100        ->setPolicyObject($snapshot)
 101        ->setUser($viewer);
 102  
 103      $zip_uri = $this->getApplicationURI(
 104        'zip@'.$snapshot->getName().
 105        '/'.$snapshot->getPrimaryFragment()->getPath());
 106  
 107      $can_edit = PhabricatorPolicyFilter::hasCapability(
 108        $viewer,
 109        $snapshot,
 110        PhabricatorPolicyCapability::CAN_EDIT);
 111  
 112      $actions = id(new PhabricatorActionListView())
 113        ->setUser($viewer)
 114        ->setObject($snapshot)
 115        ->setObjectURI($snapshot->getURI());
 116      $actions->addAction(
 117        id(new PhabricatorActionView())
 118          ->setName(pht('Download Snapshot as ZIP'))
 119          ->setHref($this->isCorrectlyConfigured() ? $zip_uri : null)
 120          ->setDisabled(!$this->isCorrectlyConfigured())
 121          ->setIcon('fa-floppy-o'));
 122      $actions->addAction(
 123        id(new PhabricatorActionView())
 124          ->setName(pht('Delete Snapshot'))
 125          ->setHref($this->getApplicationURI(
 126            'snapshot/delete/'.$snapshot->getID().'/'))
 127          ->setDisabled(!$can_edit)
 128          ->setWorkflow(true)
 129          ->setIcon('fa-times'));
 130      $actions->addAction(
 131        id(new PhabricatorActionView())
 132          ->setName(pht('Promote Another Snapshot to Here'))
 133          ->setHref($this->getApplicationURI(
 134            'snapshot/promote/'.$snapshot->getID().'/'))
 135          ->setDisabled(!$can_edit)
 136          ->setWorkflow(true)
 137          ->setIcon('fa-arrow-up'));
 138  
 139      $properties = id(new PHUIPropertyListView())
 140        ->setUser($viewer)
 141        ->setObject($snapshot)
 142        ->setActionList($actions);
 143  
 144      $properties->addProperty(
 145        pht('Name'),
 146        $snapshot->getName());
 147      $properties->addProperty(
 148        pht('Fragment'),
 149        $this->renderHandlesForPHIDs(array($snapshot->getPrimaryFragmentPHID())));
 150  
 151      return id(new PHUIObjectBoxView())
 152        ->setHeader($header)
 153        ->addPropertyList($properties);
 154    }
 155  }


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