Пример #1
0
 public function loadStoreIds(Mage_Poll_Model_Poll $object)
 {
     $pollId = $object->getId();
     $storeIds = array();
     if ($pollId) {
         $select = $this->_getReadAdapter()->select()->from($this->getTable('poll/poll_store'), 'store_id')->where('poll_id = ?', $pollId);
         $storeIds = $this->_getReadAdapter()->fetchCol($select);
     }
     $object->setStoreIds($storeIds);
 }
Пример #2
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)));
 }
Пример #3
0
 /**
  * Render block HTML
  *
  * @return string
  */
 protected function _toHtml()
 {
     $pollId = $this->getPollToShow();
     $data = $this->getPollData($pollId);
     $this->assign($data);
     Mage::getSingleton('Mage_Core_Model_Session')->setJustVotedPoll(false);
     if ($this->_pollModel->isVoted($pollId) === true) {
         $this->setTemplate($this->_templates['results']);
     } else {
         $this->setTemplate($this->_templates['poll']);
     }
     return parent::_toHtml();
 }
Пример #4
0
 /**
  * Limit CMS Poll save
  *
  * @param Mage_Poll_Model_Poll $model
  */
 public function pollSaveBefore($model)
 {
     $originalStoreIds = $model->getResource()->lookupStoreIds($model->getId());
     if ($model->getId() && !$this->_role->hasStoreAccess($originalStoreIds)) {
         $this->_throwSave();
     }
     if (!$this->_role->getIsWebsiteLevel()) {
         $this->_throwSave();
     }
     $model->setData('store_ids', $this->_forceAssignToStore($this->_updateSavingStoreIds($model->getData('store_ids'), $originalStoreIds)));
 }
 /**
  * Render block HTML
  *
  * @return string
  */
 protected function _toHtml()
 {
     /** @var $coreSessionModel Mage_Core_Model_Session */
     $coreSessionModel = Mage::getSingleton('core/session');
     $justVotedPollId = $coreSessionModel->getJustVotedPoll();
     if ($justVotedPollId && !$this->_pollModel->isVoted($justVotedPollId)) {
         $this->_pollModel->setVoted($justVotedPollId);
     }
     $pollId = $this->getPollToShow();
     $data = $this->getPollData($pollId);
     $this->assign($data);
     $coreSessionModel->setJustVotedPoll(false);
     if ($this->_pollModel->isVoted($pollId) === true || $justVotedPollId) {
         $this->setTemplate($this->_templates['results']);
     } else {
         $this->setTemplate($this->_templates['poll']);
     }
     return parent::_toHtml();
 }
Пример #6
0
 public function addVote(Mage_Poll_Model_Poll_Vote $vote)
 {
     if (Mage::getModel('customer/session')->getCustomerId()) {
         $ruleCollection = Mage::getSingleton('rewards/special_validator')->getApplicableRulesOnPoll();
         $hasRecievedPoints = false;
         //Grab all the newsletter point transfers dealing with this customer
         $transferCollection = Mage::getModel('rewards/transfer')->getTransfersAssociatedWithPoll($this->getId());
         foreach ($transferCollection as $transfer) {
             if ($transfer->getCustomerId() == Mage::getModel('customer/session')->getCustomerId()) {
                 $revokedTransfers = Mage::getModel('rewards/transfer')->getTransfersAssociatedWithTransfer($transfer->getId());
                 //If there are no revoked transfers, then the customer has already recieved points for this newsletter
                 //And therefore should not get anymore
                 if ($revokedTransfers->getSize() == 0) {
                     $hasRecievedPoints = true;
                 }
             }
         }
         if (!$hasRecievedPoints) {
             Mage::dispatchEvent('rewards_poll_new_vote', array('poll' => &$this));
             foreach ($ruleCollection as $rule) {
                 if (!$rule->getId()) {
                     continue;
                 }
                 try {
                     //Create the transfer
                     $is_transfer_successful = Mage::helper('rewards/transfer')->transferPollPoints($rule->getPointsAmount(), $rule->getPointsCurrencyId(), $this->getId(), $rule->getId());
                 } catch (Exception $ex) {
                     Mage::getSingleton('core/session')->addError($ex->getMessage());
                 }
                 if ($is_transfer_successful) {
                     //Alert the customer on the distributed points
                     Mage::getSingleton('core/session')->addSuccess(Mage::helper('rewards')->__('You received %s for voting', (string) Mage::getModel('rewards/points')->set($rule)));
                 }
             }
         }
     }
     return parent::addVote($vote);
 }
 public function loadStoreIds(Mage_Poll_Model_Poll $object)
 {
     $pollId = $object->getId();
     $storeIds = array();
     if ($pollId) {
         $storeIds = $this->lookupStoreIds($pollId);
     }
     $object->setStoreIds($storeIds);
 }