Correct Aphlict websocket URI construction after PHP8 compatibility changes
[phabricator.git] / src / applications / fund / controller / FundInitiativeViewController.php
blob6d6a19643d99d61dc15be5497085217ffa36d6df
1 <?php
3 final class FundInitiativeViewController
4 extends FundController {
6 public function shouldAllowPublic() {
7 return true;
10 public function handleRequest(AphrontRequest $request) {
11 $viewer = $request->getViewer();
12 $id = $request->getURIData('id');
14 $initiative = id(new FundInitiativeQuery())
15 ->setViewer($viewer)
16 ->withIDs(array($id))
17 ->executeOne();
18 if (!$initiative) {
19 return new Aphront404Response();
22 $crumbs = $this->buildApplicationCrumbs();
23 $crumbs->addTextCrumb($initiative->getMonogram());
24 $crumbs->setBorder(true);
26 $title = pht(
27 '%s %s',
28 $initiative->getMonogram(),
29 $initiative->getName());
31 if ($initiative->isClosed()) {
32 $status_icon = 'fa-ban';
33 $status_color = 'indigo';
34 } else {
35 $status_icon = 'fa-check';
36 $status_color = 'bluegrey';
38 $status_name = idx(
39 FundInitiative::getStatusNameMap(),
40 $initiative->getStatus());
42 $header = id(new PHUIHeaderView())
43 ->setHeader($initiative->getName())
44 ->setUser($viewer)
45 ->setPolicyObject($initiative)
46 ->setStatus($status_icon, $status_color, $status_name)
47 ->setHeaderIcon('fa-heart');
49 $curtain = $this->buildCurtain($initiative);
50 $details = $this->buildPropertySectionView($initiative);
52 $timeline = $this->buildTransactionTimeline(
53 $initiative,
54 new FundInitiativeTransactionQuery());
55 $timeline->setQuoteRef($initiative->getMonogram());
57 $comment_view = $this->buildCommentForm($initiative, $timeline);
59 $view = id(new PHUITwoColumnView())
60 ->setHeader($header)
61 ->setCurtain($curtain)
62 ->setMainColumn(array(
63 $timeline,
64 $comment_view,
66 ->addPropertySection(pht('Details'), $details);
68 return $this->newPage()
69 ->setTitle($title)
70 ->setCrumbs($crumbs)
71 ->setPageObjectPHIDs(array($initiative->getPHID()))
72 ->appendChild($view);
75 private function buildPropertySectionView(FundInitiative $initiative) {
76 $viewer = $this->getRequest()->getUser();
78 $view = id(new PHUIPropertyListView())
79 ->setUser($viewer);
81 $owner_phid = $initiative->getOwnerPHID();
82 $merchant_phid = $initiative->getMerchantPHID();
84 $view->addProperty(
85 pht('Owner'),
86 $viewer->renderHandle($owner_phid));
88 $view->addProperty(
89 pht('Payable to Merchant'),
90 $viewer->renderHandle($merchant_phid));
92 $view->addProperty(
93 pht('Total Funding'),
94 $initiative->getTotalAsCurrency()->formatForDisplay());
96 $description = $initiative->getDescription();
97 if (strlen($description)) {
98 $description = new PHUIRemarkupView($viewer, $description);
99 $view->addSectionHeader(
100 pht('Description'), PHUIPropertyListView::ICON_SUMMARY);
101 $view->addTextContent($description);
104 $risks = $initiative->getRisks();
105 if (strlen($risks)) {
106 $risks = new PHUIRemarkupView($viewer, $risks);
107 $view->addSectionHeader(
108 pht('Risks/Challenges'), 'fa-ambulance');
109 $view->addTextContent($risks);
112 return $view;
115 private function buildCurtain(FundInitiative $initiative) {
116 $viewer = $this->getViewer();
118 $id = $initiative->getID();
120 $can_edit = PhabricatorPolicyFilter::hasCapability(
121 $viewer,
122 $initiative,
123 PhabricatorPolicyCapability::CAN_EDIT);
125 $curtain = $this->newCurtainView($initiative);
127 $curtain->addAction(
128 id(new PhabricatorActionView())
129 ->setName(pht('Edit Initiative'))
130 ->setIcon('fa-pencil')
131 ->setDisabled(!$can_edit)
132 ->setWorkflow(!$can_edit)
133 ->setHref($this->getApplicationURI("/edit/{$id}/")));
135 if ($initiative->isClosed()) {
136 $close_name = pht('Reopen Initiative');
137 $close_icon = 'fa-check';
138 } else {
139 $close_name = pht('Close Initiative');
140 $close_icon = 'fa-times';
143 $curtain->addAction(
144 id(new PhabricatorActionView())
145 ->setName($close_name)
146 ->setIcon($close_icon)
147 ->setDisabled(!$can_edit)
148 ->setWorkflow(true)
149 ->setHref($this->getApplicationURI("/close/{$id}/")));
151 $curtain->addAction(
152 id(new PhabricatorActionView())
153 ->setName(pht('Back Initiative'))
154 ->setIcon('fa-money')
155 ->setDisabled($initiative->isClosed())
156 ->setWorkflow(true)
157 ->setHref($this->getApplicationURI("/back/{$id}/")));
159 $curtain->addAction(
160 id(new PhabricatorActionView())
161 ->setName(pht('View Backers'))
162 ->setIcon('fa-bank')
163 ->setHref($this->getApplicationURI("/backers/{$id}/")));
165 return $curtain;
168 private function buildCommentForm(FundInitiative $initiative, $timeline) {
169 $viewer = $this->getViewer();
170 $box = id(new FundInitiativeEditEngine())
171 ->setViewer($viewer)
172 ->buildEditEngineCommentView($initiative)
173 ->setTransactionTimeline($timeline);
175 return $box;