@recaptime-dev's working patches + fork for Phorge, a community fork of Phabricator. (Upstream dev and stable branches are at upstream/main and upstream/stable respectively.) hq.recaptime.dev/wiki/Phorge
phorge phabricator
at recaptime-dev/main 133 lines 3.5 kB view raw
1<?php 2 3final class PhabricatorCountdownViewController 4 extends PhabricatorCountdownController { 5 6 public function shouldAllowPublic() { 7 return true; 8 } 9 10 public function handleRequest(AphrontRequest $request) { 11 $viewer = $request->getViewer(); 12 $id = $request->getURIData('id'); 13 14 $countdown = id(new PhabricatorCountdownQuery()) 15 ->setViewer($viewer) 16 ->withIDs(array($id)) 17 ->executeOne(); 18 if (!$countdown) { 19 return new Aphront404Response(); 20 } 21 22 $countdown_view = id(new PhabricatorCountdownView()) 23 ->setUser($viewer) 24 ->setCountdown($countdown); 25 26 $id = $countdown->getID(); 27 $title = $countdown->getTitle(); 28 29 $crumbs = $this 30 ->buildApplicationCrumbs() 31 ->addTextCrumb($countdown->getMonogram()) 32 ->setBorder(true); 33 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'); 43 } 44 45 $header = id(new PHUIHeaderView()) 46 ->setHeader($title) 47 ->setUser($viewer) 48 ->setPolicyObject($countdown) 49 ->setStatus($icon, $color, $status) 50 ->setHeaderIcon('fa-rocket'); 51 52 $curtain = $this->buildCurtain($countdown); 53 $subheader = $this->buildSubheaderView($countdown); 54 55 $timeline = $this->buildTransactionTimeline( 56 $countdown, 57 new PhabricatorCountdownTransactionQuery()); 58 59 $comment_view = id(new PhabricatorCountdownEditEngine()) 60 ->setViewer($viewer) 61 ->buildEditEngineCommentView($countdown); 62 63 $content = array( 64 $countdown_view, 65 $timeline, 66 $comment_view, 67 ); 68 69 $view = id(new PHUITwoColumnView()) 70 ->setHeader($header) 71 ->setSubheader($subheader) 72 ->setCurtain($curtain) 73 ->setMainColumn($content); 74 75 return $this->newPage() 76 ->setTitle($title) 77 ->setCrumbs($crumbs) 78 ->setPageObjectPHIDs( 79 array( 80 $countdown->getPHID(), 81 )) 82 ->appendChild($view); 83 } 84 85 private function buildCurtain(PhabricatorCountdown $countdown) { 86 $viewer = $this->getViewer(); 87 88 $id = $countdown->getID(); 89 90 $can_edit = PhabricatorPolicyFilter::hasCapability( 91 $viewer, 92 $countdown, 93 PhabricatorPolicyCapability::CAN_EDIT); 94 95 $curtain = $this->newCurtainView($countdown); 96 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)); 104 105 return $curtain; 106 } 107 108 private function buildSubheaderView( 109 PhabricatorCountdown $countdown) { 110 $viewer = $this->getViewer(); 111 112 $author = $viewer->renderHandle($countdown->getAuthorPHID())->render(); 113 $date = phabricator_datetime($countdown->getDateCreated(), $viewer); 114 $author = phutil_tag('strong', array(), $author); 115 116 $person = id(new PhabricatorPeopleQuery()) 117 ->setViewer($viewer) 118 ->withPHIDs(array($countdown->getAuthorPHID())) 119 ->needProfileImage(true) 120 ->executeOne(); 121 122 $image_uri = $person->getProfileImageURI(); 123 $image_href = '/p/'.$person->getUsername(); 124 125 $content = pht('Authored by %s on %s.', $author, $date); 126 127 return id(new PHUIHeadThingView()) 128 ->setImage($image_uri) 129 ->setImageHref($image_href) 130 ->setContent($content); 131 } 132 133}