public function processRequest()
 {
     $request = $this->getRequest();
     $user = $request->getUser();
     $poll = new PhabricatorSlowvotePoll();
     $poll->setAuthorPHID($user->getPHID());
     $e_question = true;
     $e_response = true;
     $errors = array();
     $responses = $request->getArr('response');
     if ($request->isFormPost()) {
         $poll->setQuestion($request->getStr('question'));
         $poll->setResponseVisibility($request->getInt('response_visibility'));
         $poll->setShuffle($request->getBool('shuffle', false));
         $poll->setMethod($request->getInt('method'));
         if (!strlen($poll->getQuestion())) {
             $e_question = 'Required';
             $errors[] = 'You must ask a poll question.';
         } else {
             $e_question = null;
         }
         $responses = array_filter($responses);
         if (empty($responses)) {
             $errors[] = 'You must offer at least one response.';
             $e_response = 'Required';
         } else {
             $e_response = null;
         }
         if (empty($errors)) {
             $poll->save();
             foreach ($responses as $response) {
                 $option = new PhabricatorSlowvoteOption();
                 $option->setName($response);
                 $option->setPollID($poll->getID());
                 $option->save();
             }
             return id(new AphrontRedirectResponse())->setURI('/V' . $poll->getID());
         }
     }
     $error_view = null;
     if ($errors) {
         $error_view = new AphrontErrorView();
         $error_view->setTitle('Form Errors');
         $error_view->setErrors($errors);
     }
     $form = id(new AphrontFormView())->setUser($user)->appendChild('<p class="aphront-form-instructions">Resolve issues and build ' . 'consensus through protracted deliberation.</p>')->appendChild(id(new AphrontFormTextControl())->setLabel('Question')->setName('question')->setValue($poll->getQuestion())->setError($e_question));
     for ($ii = 0; $ii < 10; $ii++) {
         $n = $ii + 1;
         $response = id(new AphrontFormTextControl())->setLabel("Response {$n}")->setName('response[]')->setValue(idx($responses, $ii, ''));
         if ($ii == 0) {
             $response->setError($e_response);
         }
         $form->appendChild($response);
     }
     $poll_type_options = array(PhabricatorSlowvotePoll::METHOD_PLURALITY => 'Plurality (Single Choice)', PhabricatorSlowvotePoll::METHOD_APPROVAL => 'Approval (Multiple Choice)');
     $response_type_options = array(PhabricatorSlowvotePoll::RESPONSES_VISIBLE => 'Allow anyone to see the responses', PhabricatorSlowvotePoll::RESPONSES_VOTERS => 'Require a vote to see the responses', PhabricatorSlowvotePoll::RESPONSES_OWNER => 'Only I can see the responses');
     $form->appendChild(id(new AphrontFormSelectControl())->setLabel('Vote Type')->setName('method')->setValue($poll->getMethod())->setOptions($poll_type_options))->appendChild(id(new AphrontFormSelectControl())->setLabel('Responses')->setName('response_visibility')->setValue($poll->getResponseVisibility())->setOptions($response_type_options))->appendChild(id(new AphrontFormCheckboxControl())->setLabel('Shuffle')->addCheckbox('shuffle', 1, 'Show choices in random order', $poll->getShuffle()))->appendChild(id(new AphrontFormSubmitControl())->setValue('Create Slowvote')->addCancelButton('/vote/'));
     $panel = new AphrontPanelView();
     $panel->setWidth(AphrontPanelView::WIDTH_FORM);
     $panel->setHeader('Create Slowvote');
     $panel->appendChild($form);
     return $this->buildStandardPageResponse(array($error_view, $panel), array('title' => 'Create Slowvote'));
 }
 private function renderResultMarkup(PhabricatorSlowvotePoll $poll, array $options, array $choices, array $comments, array $viewer_choices, array $choices_by_option, array $comments_by_option, array $handles, array $objects)
 {
     $viewer_phid = $this->getRequest()->getUser()->getPHID();
     $can_see_responses = false;
     $need_vote = false;
     switch ($poll->getResponseVisibility()) {
         case PhabricatorSlowvotePoll::RESPONSES_VISIBLE:
             $can_see_responses = true;
             break;
         case PhabricatorSlowvotePoll::RESPONSES_VOTERS:
             $can_see_responses = (bool) $viewer_choices;
             $need_vote = true;
             break;
         case PhabricatorSlowvotePoll::RESPONSES_OWNER:
             $can_see_responses = $viewer_phid == $poll->getAuthorPHID();
             break;
     }
     $result_markup = id(new AphrontFormLayoutView())->appendChild('<h1>Ongoing Deliberation</h1>');
     if (!$can_see_responses) {
         if ($need_vote) {
             $reason = "You must vote to see the results.";
         } else {
             $reason = "The results are not public.";
         }
         $result_markup->appendChild('<p class="aphront-form-instructions"><em>' . $reason . '</em></p>');
         return $result_markup;
     }
     foreach ($options as $option) {
         $id = $option->getID();
         $chosen = idx($choices_by_option, $id, array());
         $users = array_select_keys($handles, mpull($chosen, 'getAuthorPHID'));
         if ($users) {
             $user_markup = array();
             foreach ($users as $handle) {
                 $object = idx($objects, $handle->getPHID());
                 if (!$object) {
                     continue;
                 }
                 $profile_image = PhabricatorFileURI::getViewURIForPHID($object->getProfileImagePHID());
                 $user_markup[] = phutil_render_tag('a', array('href' => $handle->getURI(), 'class' => 'phabricator-slowvote-facepile'), phutil_render_tag('img', array('src' => $profile_image)));
             }
             $user_markup = implode('', $user_markup);
         } else {
             $user_markup = 'This option has failed to appeal to anyone.';
         }
         $comment_markup = $this->renderComments(idx($comments_by_option, $id, array()), $handles);
         $vote_count = $this->renderVoteCount($poll, $choices, $chosen);
         $result_markup->appendChild('<div>' . '<div class="phabricator-slowvote-count">' . $vote_count . '</div>' . '<h1>' . phutil_escape_html($option->getName()) . '</h1>' . '<hr class="phabricator-slowvote-hr" />' . $user_markup . '<div style="clear: both;">' . '<hr class="phabricator-slowvote-hr" />' . $comment_markup . '</div>');
     }
     if ($poll->getMethod() == PhabricatorSlowvotePoll::METHOD_APPROVAL && $comments) {
         $comment_markup = $this->renderComments($comments, $handles);
         $result_markup->appendChild('<h1>Motions Proposed for Consideration</h1>');
         $result_markup->appendChild($comment_markup);
     }
     return $result_markup;
 }