Overview

Packages

  • currencysymbol
  • MAbout
  • Mage
    • Admin
    • Adminhtml
    • AdminNotification
    • Api
    • Api2
    • Authorizenet
    • Backup
    • Bundle
    • Captcha
    • Catalog
    • CatalogIndex
    • CatalogInventory
    • CatalogRule
    • CatalogSearch
    • Centinel
    • Checkout
    • Cms
    • Compiler
    • Connect
    • Contacts
    • Core
    • Cron
    • CurrencySymbol
    • Customer
    • Dataflow
    • Directory
    • DirtectPost
    • Downloadable
    • Eav
    • GiftMessage
    • GoogleAnalytics
    • GoogleBase
    • GoogleCheckout
    • ImportExport
    • Index
    • Install
    • Log
    • Media
    • Newsletter
    • Oauth
    • Page
    • PageCache
    • Paygate
    • Payment
    • Paypal
    • PaypalUk
    • Persistent
    • Poll
    • ProductAlert
    • Rating
    • Reports
    • Review
    • Rss
    • Rule
    • Sales
    • SalesRule
    • Sedfriend
    • Sendfriend
    • Shipping
    • Sitemap
    • Tag
    • Tax
    • Usa
    • Weee
    • Widget
    • Wishlist
    • XmlConnect
  • None
  • Phoenix
    • Moneybookers
  • PHP
  • Zend
    • Date
    • Mime
    • XmlRpc

Classes

  • Mage_Poll_Block_ActivePoll
  • Mage_Poll_Block_Poll
  • Mage_Poll_Helper_Data
  • Mage_Poll_Model_Mysql4_Poll
  • Mage_Poll_Model_Mysql4_Poll_Answer
  • Mage_Poll_Model_Mysql4_Poll_Answer_Collection
  • Mage_Poll_Model_Mysql4_Poll_Collection
  • Mage_Poll_Model_Mysql4_Poll_Vote
  • Mage_Poll_Model_Poll
  • Mage_Poll_Model_Poll_Answer
  • Mage_Poll_Model_Poll_Vote
  • Mage_Poll_Model_Resource_Poll
  • Mage_Poll_Model_Resource_Poll_Answer
  • Mage_Poll_Model_Resource_Poll_Answer_Collection
  • Mage_Poll_Model_Resource_Poll_Collection
  • Mage_Poll_Model_Resource_Poll_Vote
  • Mage_Poll_VoteController
  • Overview
  • Package
  • Class
  • Tree
  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: /**
 29:  * Poll Mysql4 resource model
 30:  *
 31:  * @category    Mage
 32:  * @package     Mage_Poll
 33:  * @author      Magento Core Team <core@magentocommerce.com>
 34:  */
 35: class Mage_Poll_Model_Resource_Poll extends Mage_Core_Model_Resource_Db_Abstract
 36: {
 37:     /**
 38:      * Initialize resource
 39:      *
 40:      */
 41:     protected function _construct()
 42:     {
 43:         $this->_init('poll/poll', 'poll_id');
 44:     }
 45: 
 46:     /**
 47:      * Initialize unique fields
 48:      *
 49:      * @return Mage_Poll_Model_Resource_Poll
 50:      */
 51:     protected function _initUniqueFields()
 52:     {
 53:         $this->_uniqueFields = array(array(
 54:             'field' => 'poll_title',
 55:             'title' => Mage::helper('poll')->__('Poll with the same question')
 56:         ));
 57:         return $this;
 58:     }
 59: 
 60:     /**
 61:      * Get select object for not closed poll ids
 62:      *
 63:      * @param Mage_Poll_Model_Poll $object
 64:      * @return
 65:      */
 66:     protected function _getSelectIds($object)
 67:     {
 68:         $read = $this->_getReadAdapter();
 69:         $select = $read->select()
 70:             ->from(array('main_table'=>$this->getMainTable()), $this->getIdFieldName())
 71:             ->where('closed = ?', 0);
 72: 
 73:         $excludeIds = $object->getExcludeFilter();
 74:         if ($excludeIds) {
 75:             $select->where('main_table.poll_id NOT IN(?)', $excludeIds);
 76:         }
 77: 
 78:         $storeId = $object->getStoreFilter();
 79:         if ($storeId) {
 80:             $select->join(
 81:                 array('store' => $this->getTable('poll/poll_store')),
 82:                 'main_table.poll_id=store.poll_id AND store.store_id = ' . $read->quote($storeId),
 83:                 array()
 84:             );
 85:         }
 86: 
 87:         return $select;
 88:     }
 89: 
 90:     /**
 91:      * Get random identifier not closed poll
 92:      *
 93:      * @param Mage_Poll_Model_Poll $object
 94:      * @return int
 95:      */
 96:     public function getRandomId($object)
 97:     {
 98:         $select = $this->_getSelectIds($object)->orderRand()->limit(1);
 99:         return $this->_getReadAdapter()->fetchOne($select);
100:     }
101: 
102:     /**
103:      * Get all ids for not closed polls
104:      *
105:      * @param Mage_Poll_Model_Poll $object
106:      * @return array
107:      */
108:     public function getAllIds($object)
109:     {
110:         $select = $this->_getSelectIds($object);
111:         return $this->_getReadAdapter()->fetchCol($select);
112:     }
113: 
114:     /**
115:      * Check answer id existing for poll
116:      *
117:      * @param Mage_Poll_Model_Poll $poll
118:      * @param int $answerId
119:      * @return bool
120:      */
121:     public function checkAnswerId($poll, $answerId)
122:     {
123:         $select = $this->_getReadAdapter()->select()
124:             ->from($this->getTable('poll_answer'), 'answer_id')
125:             ->where('poll_id = :poll_id')
126:             ->where('answer_id = :answer_id');
127:         $bind = array(':poll_id' => $poll->getId(), ':answer_id' => $answerId);
128:         return $this->_getReadAdapter()->fetchOne($select, $bind);
129:     }
130: 
131:     /**
132:      * Get voted poll ids by specified IP-address
133:      * Will return non-empty only if appropriate option in config is enabled
134:      * If poll id is not empty, it will look only for records with specified value
135:      *
136:      * @param string $ipAddress
137:      * @param int $pollId
138:      * @return array
139:      */
140:     public function getVotedPollIdsByIp($ipAddress, $pollId = false)
141:     {
142:         // check if validation by ip is enabled
143:         if (!Mage::getModel('poll/poll')->isValidationByIp()) {
144:             return array();
145:         }
146: 
147:         // look for ids in database
148:         $select = $this->_getReadAdapter()->select()
149:             ->distinct()
150:             ->from($this->getTable('poll_vote'), 'poll_id')
151:             ->where('ip_address = :ip_address');
152:         $bind = array(':ip_address' => ip2long($ipAddress));
153:         if (!empty($pollId)) {
154:             $select->where('poll_id = :poll_id');
155:             $bind[':poll_id'] = $pollId;
156:         }
157:         $result = $this->_getReadAdapter()->fetchCol($select, $bind);
158:         if (empty($result)) {
159:             $result = array();
160:         }
161:         return $result;
162:     }
163: 
164:     /**
165:      * Resett votes count
166:      *
167:      * @param Mage_Poll_Model_Poll $object
168:      * @return Mage_Poll_Model_Poll
169:      */
170:     public function resetVotesCount($object)
171:     {
172:         $adapter = $this->_getWriteAdapter();
173:         $select = $adapter->select()
174:             ->from($this->getTable('poll_answer'), new Zend_Db_Expr("SUM(votes_count)"))
175:             ->where('poll_id = ?', $object->getPollId());
176:         $adapter->update(
177:             $this->getMainTable(),
178:             array('votes_count' => new Zend_Db_Expr("($select)")),
179:             array('poll_id = ' . $adapter->quote($object->getPollId()))
180:         );
181:         return $object;
182:     }
183: 
184:     /**
185:      * Load store Ids array
186:      *
187:      * @param Mage_Poll_Model_Poll $object
188:      */
189:     public function loadStoreIds(Mage_Poll_Model_Poll $object)
190:     {
191:         $pollId   = $object->getId();
192:         $storeIds = array();
193:         if ($pollId) {
194:             $storeIds = $this->lookupStoreIds($pollId);
195:         }
196:         $object->setStoreIds($storeIds);
197:     }
198: 
199:     /**
200:      * Delete current poll from the table poll_store and then
201:      * insert to update "poll to store" relations
202:      *
203:      * @param Mage_Core_Model_Abstract $object
204:      */
205:     public function _afterSave(Mage_Core_Model_Abstract $object)
206:     {
207:         /** stores */
208:         $deleteWhere = $this->_getWriteAdapter()->quoteInto('poll_id = ?', $object->getId());
209:         $this->_getWriteAdapter()->delete($this->getTable('poll/poll_store'), $deleteWhere);
210: 
211:         foreach ($object->getStoreIds() as $storeId) {
212:             $pollStoreData = array(
213:             'poll_id'   => $object->getId(),
214:             'store_id'  => $storeId
215:             );
216:             $this->_getWriteAdapter()->insert($this->getTable('poll/poll_store'), $pollStoreData);
217:         }
218: 
219:         /** answers */
220:         foreach ($object->getAnswers() as $answer) {
221:             $answer->setPollId($object->getId());
222:             $answer->save();
223:         }
224:     }
225: 
226:     /**
227:      * Get store ids to which specified item is assigned
228:      *
229:      * @param int $id
230:      * @return array
231:      */
232:     public function lookupStoreIds($id)
233:     {
234:         return $this->_getReadAdapter()->fetchCol(
235:             $this->_getReadAdapter()->select()
236:                 ->from($this->getTable('poll/poll_store'), 'store_id')
237:                 ->where("{$this->getIdFieldName()} = :id_field"),
238:             array(':id_field' => $id)
239:         );
240:     }
241: }
242: 
Magento 1.7.0.2 API documentation generated by ApiGen 2.8.0