コード例 #1
0
 /**
  * Get Poll related data
  *
  * @param int $pollId
  * @return array|bool
  */
 public function getPollData($pollId)
 {
     if (empty($pollId)) {
         return false;
     }
     $poll = $this->_pollModel->load($pollId);
     $pollAnswers = Mage::getModel('poll/poll_answer')->getResourceCollection()->addPollFilter($pollId)->load()->countPercent($poll);
     // correct rounded percents to be always equal 100
     $percentsSorted = array();
     $answersArr = array();
     foreach ($pollAnswers as $key => $answer) {
         $percentsSorted[$key] = $answer->getPercent();
         $answersArr[$key] = $answer;
     }
     asort($percentsSorted);
     $total = 0;
     foreach ($percentsSorted as $key => $value) {
         $total += $value;
     }
     // change the max value only
     if ($total > 0 && $total !== 100) {
         $answersArr[$key]->setPercent($value + 100 - $total);
     }
     return array('poll' => $poll, 'poll_answers' => $pollAnswers, 'action' => Mage::getUrl('poll/vote/add', array('poll_id' => $pollId, '_secure' => true)));
 }