示例#1
0
 private function renderBar(PhabricatorSlowvoteOption $option)
 {
     if (!$this->areResultsVisible()) {
         return null;
     }
     $poll = $this->getPoll();
     $choices = mgroup($poll->getChoices(), 'getOptionID');
     $choices = count(idx($choices, $option->getID(), array()));
     $count = count(mgroup($poll->getChoices(), 'getAuthorPHID'));
     return phutil_tag('div', array('class' => 'slowvote-bar', 'style' => sprintf('width: %.1f%%;', $count ? 100 * ($choices / $count) : 0)), array(phutil_tag('div', array('class' => 'slowvote-control-offset'), $option->getName())));
 }
 private function renderPollOption(PhabricatorSlowvotePoll $poll, array $viewer_choices, PhabricatorSlowvoteOption $option)
 {
     $id = $option->getID();
     switch ($poll->getMethod()) {
         case PhabricatorSlowvotePoll::METHOD_PLURALITY:
             // Render a radio button.
             $selected_option = head($viewer_choices);
             if ($selected_option) {
                 $selected = $selected_option->getOptionID();
             } else {
                 $selected = null;
             }
             if ($selected == $id) {
                 $checked = "checked";
             } else {
                 $checked = null;
             }
             $input = phutil_render_tag('input', array('type' => 'radio', 'name' => 'vote[]', 'value' => $id, 'checked' => $checked));
             break;
         case PhabricatorSlowvotePoll::METHOD_APPROVAL:
             // Render a check box.
             $checked = null;
             foreach ($viewer_choices as $choice) {
                 if ($choice->getOptionID() == $id) {
                     $checked = 'checked';
                     break;
                 }
             }
             $input = phutil_render_tag('input', array('type' => 'checkbox', 'name' => 'vote[]', 'checked' => $checked, 'value' => $id));
             break;
         default:
             throw new Exception("Unknown poll method!");
     }
     if ($checked) {
         $checked_class = 'phabricator-slowvote-checked';
     } else {
         $checked_class = null;
     }
     return phutil_render_tag('label', array('class' => 'phabricator-slowvote-label ' . $checked_class), $input . phutil_escape_html($option->getName()));
 }