Correct a parameter order swap in "diffusion.historyquery" for Mercurial
[phabricator.git] / src / applications / countdown / controller / PhabricatorCountdownViewController.php
blobdb63613df260d38823de6edf49ce7b63507967f5
1 <?php
3 final class PhabricatorCountdownViewController
4 extends PhabricatorCountdownController {
6 public function shouldAllowPublic() {
7 return true;
10 public function handleRequest(AphrontRequest $request) {
11 $viewer = $request->getViewer();
12 $id = $request->getURIData('id');
14 $countdown = id(new PhabricatorCountdownQuery())
15 ->setViewer($viewer)
16 ->withIDs(array($id))
17 ->executeOne();
18 if (!$countdown) {
19 return new Aphront404Response();
22 $countdown_view = id(new PhabricatorCountdownView())
23 ->setUser($viewer)
24 ->setCountdown($countdown);
26 $id = $countdown->getID();
27 $title = $countdown->getTitle();
29 $crumbs = $this
30 ->buildApplicationCrumbs()
31 ->addTextCrumb($countdown->getMonogram())
32 ->setBorder(true);
34 $epoch = $countdown->getEpoch();
35 if ($epoch >= PhabricatorTime::getNow()) {
36 $icon = 'fa-clock-o';
37 $color = '';
38 $status = pht('Running');
39 } else {
40 $icon = 'fa-check-square-o';
41 $color = 'dark';
42 $status = pht('Launched');
45 $header = id(new PHUIHeaderView())
46 ->setHeader($title)
47 ->setUser($viewer)
48 ->setPolicyObject($countdown)
49 ->setStatus($icon, $color, $status)
50 ->setHeaderIcon('fa-rocket');
52 $curtain = $this->buildCurtain($countdown);
53 $subheader = $this->buildSubheaderView($countdown);
55 $timeline = $this->buildTransactionTimeline(
56 $countdown,
57 new PhabricatorCountdownTransactionQuery());
59 $comment_view = id(new PhabricatorCountdownEditEngine())
60 ->setViewer($viewer)
61 ->buildEditEngineCommentView($countdown);
63 $content = array(
64 $countdown_view,
65 $timeline,
66 $comment_view,
69 $view = id(new PHUITwoColumnView())
70 ->setHeader($header)
71 ->setSubheader($subheader)
72 ->setCurtain($curtain)
73 ->setMainColumn($content);
75 return $this->newPage()
76 ->setTitle($title)
77 ->setCrumbs($crumbs)
78 ->setPageObjectPHIDs(
79 array(
80 $countdown->getPHID(),
82 ->appendChild($view);
85 private function buildCurtain(PhabricatorCountdown $countdown) {
86 $viewer = $this->getViewer();
88 $id = $countdown->getID();
90 $can_edit = PhabricatorPolicyFilter::hasCapability(
91 $viewer,
92 $countdown,
93 PhabricatorPolicyCapability::CAN_EDIT);
95 $curtain = $this->newCurtainView($countdown);
97 $curtain->addAction(
98 id(new PhabricatorActionView())
99 ->setIcon('fa-pencil')
100 ->setName(pht('Edit Countdown'))
101 ->setHref($this->getApplicationURI("edit/{$id}/"))
102 ->setDisabled(!$can_edit)
103 ->setWorkflow(!$can_edit));
105 return $curtain;
108 private function buildSubheaderView(
109 PhabricatorCountdown $countdown) {
110 $viewer = $this->getViewer();
112 $author = $viewer->renderHandle($countdown->getAuthorPHID())->render();
113 $date = phabricator_datetime($countdown->getDateCreated(), $viewer);
114 $author = phutil_tag('strong', array(), $author);
116 $person = id(new PhabricatorPeopleQuery())
117 ->setViewer($viewer)
118 ->withPHIDs(array($countdown->getAuthorPHID()))
119 ->needProfileImage(true)
120 ->executeOne();
122 $image_uri = $person->getProfileImageURI();
123 $image_href = '/p/'.$person->getUsername();
125 $content = pht('Authored by %s on %s.', $author, $date);
127 return id(new PHUIHeadThingView())
128 ->setImage($image_uri)
129 ->setImageHref($image_href)
130 ->setContent($content);