1: <?php
2: /**
3: * Magento
4: *
5: * NOTICE OF LICENSE
6: *
7: * This source file is subject to the Open Software License (OSL 3.0)
8: * that is bundled with this package in the file LICENSE.txt.
9: * It is also available through the world-wide-web at this URL:
10: * http://opensource.org/licenses/osl-3.0.php
11: * If you did not receive a copy of the license and are unable to
12: * obtain it through the world-wide-web, please send an email
13: * to license@magentocommerce.com so we can send you a copy immediately.
14: *
15: * DISCLAIMER
16: *
17: * Do not edit or add to this file if you wish to upgrade Magento to newer
18: * versions in the future. If you wish to customize Magento for your
19: * needs please refer to http://www.magentocommerce.com for more information.
20: *
21: * @category Mage
22: * @package Mage_Poll
23: * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
24: * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25: */
26:
27: /**
28: * Poll vote controller
29: *
30: * @file Vote.php
31: * @author Magento Core Team <core@magentocommerce.com>
32: */
33:
34: class Mage_Poll_VoteController extends Mage_Core_Controller_Front_Action
35: {
36: /**
37: * Action list where need check enabled cookie
38: *
39: * @var array
40: */
41: protected $_cookieCheckActions = array('add');
42:
43: /**
44: * Add Vote to Poll
45: *
46: * @return void
47: */
48: public function addAction()
49: {
50: $pollId = intval($this->getRequest()->getParam('poll_id'));
51: $answerId = intval($this->getRequest()->getParam('vote'));
52:
53: /** @var $poll Mage_Poll_Model_Poll */
54: $poll = Mage::getModel('poll/poll')->load($pollId);
55:
56: /**
57: * Check poll data
58: */
59: if ($poll->getId() && !$poll->getClosed() && !$poll->isVoted()) {
60: $vote = Mage::getModel('poll/poll_vote')
61: ->setPollAnswerId($answerId)
62: ->setIpAddress(Mage::helper('core/http')->getRemoteAddr(true))
63: ->setCustomerId(Mage::getSingleton('customer/session')->getCustomerId());
64:
65: $poll->addVote($vote);
66: Mage::getSingleton('core/session')->setJustVotedPoll($pollId);
67: Mage::dispatchEvent(
68: 'poll_vote_add',
69: array(
70: 'poll' => $poll,
71: 'vote' => $vote
72: )
73: );
74: }
75: $this->_redirectReferer();
76: }
77: }
78: