Correct Aphlict websocket URI construction after PHP8 compatibility changes
[phabricator.git] / src / applications / packages / controller / PhabricatorPackagesPackageViewController.php
bloba79f5d3b4eb223e43c72a4d9bf8c517962630ae7
1 <?php
3 final class PhabricatorPackagesPackageViewController
4 extends PhabricatorPackagesPackageController {
6 public function shouldAllowPublic() {
7 return true;
10 public function handleRequest(AphrontRequest $request) {
11 $viewer = $request->getViewer();
13 $publisher_key = $request->getURIData('publisherKey');
14 $package_key = $request->getURIData('packageKey');
15 $full_key = $publisher_key.'/'.$package_key;
17 $package = id(new PhabricatorPackagesPackageQuery())
18 ->setViewer($viewer)
19 ->withFullKeys(array($full_key))
20 ->executeOne();
21 if (!$package) {
22 return new Aphront404Response();
25 $publisher = $package->getPublisher();
27 $crumbs = $this->buildApplicationCrumbs()
28 ->addTextCrumb($publisher->getName(), $publisher->getURI())
29 ->addTextCrumb($package->getName())
30 ->setBorder(true);
32 $header = $this->buildHeaderView($package);
33 $curtain = $this->buildCurtain($package);
35 $versions_view = $this->buildVersionsView($package);
37 $timeline = $this->buildTransactionTimeline(
38 $package,
39 new PhabricatorPackagesPackageTransactionQuery());
40 $timeline->setShouldTerminate(true);
42 $package_view = id(new PHUITwoColumnView())
43 ->setHeader($header)
44 ->setCurtain($curtain)
45 ->setMainColumn(
46 array(
47 $versions_view,
48 $timeline,
49 ));
51 return $this->newPage()
52 ->setCrumbs($crumbs)
53 ->setPageObjectPHIDs(
54 array(
55 $package->getPHID(),
57 ->appendChild($package_view);
61 private function buildHeaderView(PhabricatorPackagesPackage $package) {
62 $viewer = $this->getViewer();
63 $name = $package->getName();
65 return id(new PHUIHeaderView())
66 ->setViewer($viewer)
67 ->setHeader($name)
68 ->setPolicyObject($package)
69 ->setHeaderIcon('fa-gift');
72 private function buildCurtain(PhabricatorPackagesPackage $package) {
73 $viewer = $this->getViewer();
74 $curtain = $this->newCurtainView($package);
76 $can_edit = PhabricatorPolicyFilter::hasCapability(
77 $viewer,
78 $package,
79 PhabricatorPolicyCapability::CAN_EDIT);
81 $id = $package->getID();
82 $edit_uri = $this->getApplicationURI("package/edit/{$id}/");
84 $curtain->addAction(
85 id(new PhabricatorActionView())
86 ->setName(pht('Edit Package'))
87 ->setIcon('fa-pencil')
88 ->setDisabled(!$can_edit)
89 ->setHref($edit_uri));
91 return $curtain;
94 private function buildVersionsView(PhabricatorPackagesPackage $package) {
95 $viewer = $this->getViewer();
97 $versions = id(new PhabricatorPackagesVersionQuery())
98 ->setViewer($viewer)
99 ->withPackagePHIDs(array($package->getPHID()))
100 ->setLimit(25)
101 ->execute();
103 $versions_list = id(new PhabricatorPackagesVersionListView())
104 ->setViewer($viewer)
105 ->setVersions($versions);
107 $all_href = urisprintf(
108 'version/?package=%s#R',
109 $package->getPHID());
110 $all_href = $this->getApplicationURI($all_href);
112 $view_all = id(new PHUIButtonView())
113 ->setTag('a')
114 ->setIcon('fa-search')
115 ->setText(pht('View All'))
116 ->setHref($all_href);
118 $header = id(new PHUIHeaderView())
119 ->setHeader(pht('Versions'))
120 ->addActionLink($view_all);
122 $versions_view = id(new PHUIObjectBoxView())
123 ->setHeader($header)
124 ->setBackground(PHUIObjectBoxView::BLUE_PROPERTY)
125 ->setObjectList($versions_list);
127 return $versions_view;