@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
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

at recaptime-dev/main 164 lines 4.7 kB view raw
1<?php 2 3final class PhabricatorSlowvotePollController 4 extends PhabricatorSlowvoteController { 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 $poll = id(new PhabricatorSlowvoteQuery()) 15 ->setViewer($viewer) 16 ->withIDs(array($id)) 17 ->needOptions(true) 18 ->needChoices(true) 19 ->needViewerChoices(true) 20 ->executeOne(); 21 if (!$poll) { 22 return new Aphront404Response(); 23 } 24 25 $poll_view = id(new SlowvoteEmbedView()) 26 ->setViewer($viewer) 27 ->setPoll($poll); 28 29 if ($request->isAjax()) { 30 return id(new AphrontAjaxResponse()) 31 ->setContent( 32 array( 33 'pollID' => $poll->getID(), 34 'contentHTML' => $poll_view->render(), 35 )); 36 } 37 38 $status = $poll->getStatusObject(); 39 40 $header_icon = $status->getHeaderTagIcon(); 41 $header_color = $status->getHeaderTagColor(); 42 $header_name = $status->getName(); 43 44 $header = id(new PHUIHeaderView()) 45 ->setHeader($poll->getQuestion()) 46 ->setViewer($viewer) 47 ->setStatus($header_icon, $header_color, $header_name) 48 ->setPolicyObject($poll) 49 ->setHeaderIcon('fa-bar-chart'); 50 51 $curtain = $this->buildCurtain($poll); 52 $subheader = $this->buildSubheaderView($poll); 53 54 $crumbs = $this->buildApplicationCrumbs(); 55 $crumbs->addTextCrumb($poll->getMonogram()); 56 $crumbs->setBorder(true); 57 58 $timeline = $this->buildTransactionTimeline( 59 $poll, 60 new PhabricatorSlowvoteTransactionQuery()); 61 $add_comment = $this->buildCommentForm($poll); 62 63 $poll_content = array( 64 $poll_view, 65 $timeline, 66 $add_comment, 67 ); 68 69 $view = id(new PHUITwoColumnView()) 70 ->setHeader($header) 71 ->setSubheader($subheader) 72 ->setCurtain($curtain) 73 ->setMainColumn($poll_content); 74 75 return $this->newPage() 76 ->setTitle( 77 pht( 78 '%s %s', 79 $poll->getMonogram(), 80 $poll->getQuestion())) 81 ->setCrumbs($crumbs) 82 ->setPageObjectPHIDs(array($poll->getPHID())) 83 ->appendChild($view); 84 } 85 86 private function buildCurtain(PhabricatorSlowvotePoll $poll) { 87 $viewer = $this->getViewer(); 88 89 $can_edit = PhabricatorPolicyFilter::hasCapability( 90 $viewer, 91 $poll, 92 PhabricatorPolicyCapability::CAN_EDIT); 93 94 $curtain = $this->newCurtainView($poll); 95 96 $is_closed = $poll->isClosed(); 97 $close_poll_text = $is_closed ? pht('Reopen Poll') : pht('Close Poll'); 98 $close_poll_icon = $is_closed ? 'fa-check' : 'fa-ban'; 99 100 $curtain->addAction( 101 id(new PhabricatorActionView()) 102 ->setName(pht('Edit Poll')) 103 ->setIcon('fa-pencil') 104 ->setHref($this->getApplicationURI('edit/'.$poll->getID().'/')) 105 ->setDisabled(!$can_edit) 106 ->setWorkflow(!$can_edit)); 107 108 $curtain->addAction( 109 id(new PhabricatorActionView()) 110 ->setName($close_poll_text) 111 ->setIcon($close_poll_icon) 112 ->setHref($this->getApplicationURI('close/'.$poll->getID().'/')) 113 ->setDisabled(!$can_edit) 114 ->setWorkflow(true)); 115 116 return $curtain; 117 } 118 119 private function buildSubheaderView( 120 PhabricatorSlowvotePoll $poll) { 121 $viewer = $this->getViewer(); 122 123 $author = $viewer->renderHandle($poll->getAuthorPHID())->render(); 124 $date = phabricator_datetime($poll->getDateCreated(), $viewer); 125 $author = phutil_tag('strong', array(), $author); 126 127 $person = id(new PhabricatorPeopleQuery()) 128 ->setViewer($viewer) 129 ->withPHIDs(array($poll->getAuthorPHID())) 130 ->needProfileImage(true) 131 ->executeOne(); 132 133 $image_uri = $person->getProfileImageURI(); 134 $image_href = '/p/'.$person->getUsername(); 135 136 $content = pht('Asked by %s on %s.', $author, $date); 137 138 return id(new PHUIHeadThingView()) 139 ->setImage($image_uri) 140 ->setImageHref($image_href) 141 ->setContent($content); 142 } 143 144 private function buildCommentForm(PhabricatorSlowvotePoll $poll) { 145 $viewer = $this->getRequest()->getUser(); 146 147 $is_serious = PhabricatorEnv::getEnvConfig('phabricator.serious-business'); 148 149 $add_comment_header = $is_serious 150 ? pht('Add Comment') 151 : pht('Enter Deliberations'); 152 153 $draft = PhabricatorDraft::newFromUserAndKey($viewer, $poll->getPHID()); 154 155 return id(new PhabricatorApplicationTransactionCommentView()) 156 ->setViewer($viewer) 157 ->setObject($poll) 158 ->setDraft($draft) 159 ->setHeaderText($add_comment_header) 160 ->setAction($this->getApplicationURI('/comment/'.$poll->getID().'/')) 161 ->setSubmitButtonName(pht('Add Comment')); 162 } 163 164}