[ Index ] |
PHP Cross Reference of Phabricator |
[Summary view] [Print] [Text view]
1 <?php 2 3 final class PhabricatorSlowvotePollController 4 extends PhabricatorSlowvoteController { 5 6 private $id; 7 8 public function willProcessRequest(array $data) { 9 $this->id = $data['id']; 10 } 11 12 public function processRequest() { 13 $request = $this->getRequest(); 14 $user = $request->getUser(); 15 16 $poll = id(new PhabricatorSlowvoteQuery()) 17 ->setViewer($user) 18 ->withIDs(array($this->id)) 19 ->needOptions(true) 20 ->needChoices(true) 21 ->needViewerChoices(true) 22 ->executeOne(); 23 if (!$poll) { 24 return new Aphront404Response(); 25 } 26 27 $poll_view = id(new SlowvoteEmbedView()) 28 ->setHeadless(true) 29 ->setUser($user) 30 ->setPoll($poll); 31 32 if ($request->isAjax()) { 33 return id(new AphrontAjaxResponse()) 34 ->setContent( 35 array( 36 'pollID' => $poll->getID(), 37 'contentHTML' => $poll_view->render(), 38 )); 39 } 40 41 $header_icon = $poll->getIsClosed() ? 'fa-ban' : 'fa-circle-o'; 42 $header_name = $poll->getIsClosed() ? pht('Closed') : pht('Open'); 43 $header_color = $poll->getIsClosed() ? 'dark' : 'bluegrey'; 44 45 $header = id(new PHUIHeaderView()) 46 ->setHeader($poll->getQuestion()) 47 ->setUser($user) 48 ->setStatus($header_icon, $header_color, $header_name) 49 ->setPolicyObject($poll); 50 51 $actions = $this->buildActionView($poll); 52 $properties = $this->buildPropertyView($poll, $actions); 53 54 $crumbs = $this->buildApplicationCrumbs(); 55 $crumbs->addTextCrumb('V'.$poll->getID()); 56 57 $xactions = $this->buildTransactions($poll); 58 $add_comment = $this->buildCommentForm($poll); 59 60 $object_box = id(new PHUIObjectBoxView()) 61 ->setHeader($header) 62 ->addPropertyList($properties); 63 64 return $this->buildApplicationPage( 65 array( 66 $crumbs, 67 $object_box, 68 phutil_tag( 69 'div', 70 array( 71 'class' => 'mlt mml mmr', 72 ), 73 $poll_view), 74 $xactions, 75 $add_comment, 76 ), 77 array( 78 'title' => 'V'.$poll->getID().' '.$poll->getQuestion(), 79 'pageObjects' => array($poll->getPHID()), 80 )); 81 } 82 83 private function buildActionView(PhabricatorSlowvotePoll $poll) { 84 $viewer = $this->getRequest()->getUser(); 85 86 $view = id(new PhabricatorActionListView()) 87 ->setUser($viewer) 88 ->setObject($poll); 89 90 $can_edit = PhabricatorPolicyFilter::hasCapability( 91 $viewer, 92 $poll, 93 PhabricatorPolicyCapability::CAN_EDIT); 94 95 $is_closed = $poll->getIsClosed(); 96 $close_poll_text = $is_closed ? pht('Reopen Poll') : pht('Close Poll'); 97 $close_poll_icon = $is_closed ? 'fa-play-circle-o' : 'fa-ban'; 98 99 $view->addAction( 100 id(new PhabricatorActionView()) 101 ->setName(pht('Edit Poll')) 102 ->setIcon('fa-pencil') 103 ->setHref($this->getApplicationURI('edit/'.$poll->getID().'/')) 104 ->setDisabled(!$can_edit) 105 ->setWorkflow(!$can_edit)); 106 107 $view->addAction( 108 id(new PhabricatorActionView()) 109 ->setName($close_poll_text) 110 ->setIcon($close_poll_icon) 111 ->setHref($this->getApplicationURI('close/'.$poll->getID().'/')) 112 ->setDisabled(!$can_edit) 113 ->setWorkflow(true)); 114 115 return $view; 116 } 117 118 private function buildPropertyView( 119 PhabricatorSlowvotePoll $poll, 120 PhabricatorActionListView $actions) { 121 122 $viewer = $this->getRequest()->getUser(); 123 124 $view = id(new PHUIPropertyListView()) 125 ->setUser($viewer) 126 ->setObject($poll) 127 ->setActionList($actions); 128 129 $view->invokeWillRenderEvent(); 130 131 if (strlen($poll->getDescription())) { 132 $view->addTextContent( 133 $output = PhabricatorMarkupEngine::renderOneObject( 134 id(new PhabricatorMarkupOneOff())->setContent( 135 $poll->getDescription()), 136 'default', 137 $viewer)); 138 } 139 140 return $view; 141 } 142 143 private function buildTransactions(PhabricatorSlowvotePoll $poll) { 144 $viewer = $this->getRequest()->getUser(); 145 146 $xactions = id(new PhabricatorSlowvoteTransactionQuery()) 147 ->setViewer($viewer) 148 ->withObjectPHIDs(array($poll->getPHID())) 149 ->execute(); 150 151 $engine = id(new PhabricatorMarkupEngine()) 152 ->setViewer($viewer); 153 foreach ($xactions as $xaction) { 154 if ($xaction->getComment()) { 155 $engine->addObject( 156 $xaction->getComment(), 157 PhabricatorApplicationTransactionComment::MARKUP_FIELD_COMMENT); 158 } 159 } 160 $engine->process(); 161 162 $timeline = id(new PhabricatorApplicationTransactionView()) 163 ->setUser($viewer) 164 ->setObjectPHID($poll->getPHID()) 165 ->setTransactions($xactions) 166 ->setMarkupEngine($engine); 167 168 return $timeline; 169 } 170 171 private function buildCommentForm(PhabricatorSlowvotePoll $poll) { 172 $viewer = $this->getRequest()->getUser(); 173 174 $is_serious = PhabricatorEnv::getEnvConfig('phabricator.serious-business'); 175 176 $add_comment_header = $is_serious 177 ? pht('Add Comment') 178 : pht('Enter Deliberations'); 179 180 $draft = PhabricatorDraft::newFromUserAndKey($viewer, $poll->getPHID()); 181 182 return id(new PhabricatorApplicationTransactionCommentView()) 183 ->setUser($viewer) 184 ->setObjectPHID($poll->getPHID()) 185 ->setDraft($draft) 186 ->setHeaderText($add_comment_header) 187 ->setAction($this->getApplicationURI('/comment/'.$poll->getID().'/')) 188 ->setSubmitButtonName(pht('Add Comment')); 189 } 190 191 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Sun Nov 30 09:20:46 2014 | Cross-referenced by PHPXref 0.7.1 |