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_Rating_Block_Entity_Detailed
  • Mage_Rating_Helper_Data
  • Mage_Rating_Model_Mysql4_Rating
  • Mage_Rating_Model_Mysql4_Rating_Collection
  • Mage_Rating_Model_Mysql4_Rating_Entity
  • Mage_Rating_Model_Mysql4_Rating_Option
  • Mage_Rating_Model_Mysql4_Rating_Option_Collection
  • Mage_Rating_Model_Mysql4_Rating_Option_Vote
  • Mage_Rating_Model_Mysql4_Rating_Option_Vote_Collection
  • Mage_Rating_Model_Observer
  • Mage_Rating_Model_Rating
  • Mage_Rating_Model_Rating_Entity
  • Mage_Rating_Model_Rating_Option
  • Mage_Rating_Model_Rating_Option_Vote
  • Mage_Rating_Model_Resource_Rating
  • Mage_Rating_Model_Resource_Rating_Collection
  • Mage_Rating_Model_Resource_Rating_Entity
  • Mage_Rating_Model_Resource_Rating_Option
  • Mage_Rating_Model_Resource_Rating_Option_Collection
  • Mage_Rating_Model_Resource_Rating_Option_Vote
  • Mage_Rating_Model_Resource_Rating_Option_Vote_Collection
  • 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_Rating
 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:  * Rating collection resource model
 29:  *
 30:  * @category    Mage
 31:  * @package     Mage_Rating
 32:  * @author      Magento Core Team <core@magentocommerce.com>
 33:  */
 34: class Mage_Rating_Model_Resource_Rating_Collection extends Mage_Core_Model_Resource_Db_Collection_Abstract
 35: {
 36:     /**
 37:      * @var bool
 38:      */
 39:     protected $_isStoreJoined = false;
 40: 
 41:     /**
 42:      * Resource initialization
 43:      *
 44:      */
 45:     protected function _construct()
 46:     {
 47:         $this->_init('rating/rating');
 48:     }
 49: 
 50:     /**
 51:      * Add entity filter
 52:      *
 53:      * @param   int|string $entity
 54:      * @return  Mage_Rating_Model_Resource_Rating_Collection
 55:      */
 56:     public function addEntityFilter($entity)
 57:     {
 58:         $adapter = $this->getConnection();
 59: 
 60:         $this->getSelect()
 61:             ->join($this->getTable('rating_entity'),
 62:                 'main_table.entity_id=' . $this->getTable('rating_entity') . '.entity_id',
 63:                 array('entity_code'));
 64: 
 65:         if (is_numeric($entity)) {
 66:             $this->addFilter('entity',
 67:                 $adapter->quoteInto($this->getTable('rating_entity') . '.entity_id=?', $entity),
 68:                 'string');
 69:         } elseif (is_string($entity)) {
 70:             $this->addFilter('entity',
 71:                 $adapter->quoteInto($this->getTable('rating_entity') . '.entity_code=?', $entity),
 72:                 'string');
 73:         }
 74:         return $this;
 75:     }
 76: 
 77:     /**
 78:      * set order by position field
 79:      *
 80:      * @param   string $dir
 81:      * @return  Mage_Rating_Model_Resource_Rating_Collection
 82:      */
 83:     public function setPositionOrder($dir='ASC')
 84:     {
 85:         $this->setOrder('main_table.position', $dir);
 86:         return $this;
 87:     }
 88: 
 89:     /**
 90:      * Set store filter
 91:      *
 92:      * @param int_type $storeId
 93:      * @return Mage_Rating_Model_Resource_Rating_Collection
 94:      */
 95:     public function setStoreFilter($storeId)
 96:     {
 97:         $adapter = $this->getConnection();
 98:         if (!is_array($storeId)) {
 99:             $storeId = array($storeId === null ? -1 : $storeId);
100:         }
101:         if (empty($storeId)) {
102:             return $this;
103:         }
104:         if (!$this->_isStoreJoined) {
105:             $this->getSelect()
106:                 ->distinct(true)
107:                 ->join(
108:                     array('store'=>$this->getTable('rating_store')),
109:                     'main_table.rating_id = store.rating_id',
110:                     array())
111:         //        ->group('main_table.rating_id')
112:                 ;
113:             $this->_isStoreJoined = true;
114:         }
115:         $inCond = $adapter->prepareSqlCondition('store.store_id', array(
116:             'in' => $storeId
117:         ));
118:         $this->getSelect()
119:             ->where($inCond);
120:         $this->setPositionOrder();
121:         return $this;
122:     }
123: 
124:     /**
125:      * Add options to ratings in collection
126:      *
127:      * @return Mage_Rating_Model_Resource_Rating_Collection
128:      */
129:     public function addOptionToItems()
130:     {
131:         $arrRatingId = $this->getColumnValues('rating_id');
132: 
133:         if (!empty($arrRatingId)) {
134:             $collection = Mage::getResourceModel('rating/rating_option_collection')
135:                 ->addRatingFilter($arrRatingId)
136:                 ->setPositionOrder()
137:                 ->load();
138: 
139:             foreach ($this as $rating) {
140:                 $rating->setOptions($collection->getItemsByColumnValue('rating_id', $rating->getId()));
141:             }
142:         }
143: 
144:         return $this;
145:     }
146: 
147:     /**
148:      * Add entity summary to item
149:      *
150:      * @param int $entityPkValue
151:      * @param int $storeId
152:      * @return Mage_Rating_Model_Resource_Rating_Collection
153:      */
154:     public function addEntitySummaryToItem($entityPkValue, $storeId)
155:     {
156:         $arrRatingId = $this->getColumnValues('rating_id');
157:         if (count($arrRatingId) == 0) {
158:             return $this;
159:         }
160: 
161:         $adapter = $this->getConnection();
162: 
163:         $inCond = $adapter->prepareSqlCondition('rating_option_vote.rating_id', array(
164:             'in' => $arrRatingId
165:         ));
166:         $sumCond = new Zend_Db_Expr("SUM(rating_option_vote.{$adapter->quoteIdentifier('percent')})");
167:         $countCond = new Zend_Db_Expr('COUNT(*)');
168:         $select = $adapter->select()
169:             ->from(array('rating_option_vote'  => $this->getTable('rating/rating_option_vote')),
170:                 array(
171:                     'rating_id' => 'rating_option_vote.rating_id',
172:                     'sum'         => $sumCond,
173:                     'count'       => $countCond
174:                 ))
175:             ->join(
176:                 array('review_store' => $this->getTable('review/review_store')),
177:                 'rating_option_vote.review_id=review_store.review_id AND review_store.store_id = :store_id',
178:                 array())
179:             ->join(
180:                 array('rst' => $this->getTable('rating/rating_store')),
181:                 'rst.rating_id = rating_option_vote.rating_id AND rst.store_id = :rst_store_id',
182:                 array())
183:             ->join(array('review'              => $this->getTable('review/review')),
184:                 'review_store.review_id=review.review_id AND review.status_id=1',
185:                 array())
186:             ->where($inCond)
187:             ->where('rating_option_vote.entity_pk_value=:pk_value')
188:             ->group('rating_option_vote.rating_id');
189:         $bind = array(
190:             ':store_id' => (int)$storeId,
191:             ':rst_store_id' => (int)$storeId,
192:             ':pk_value'     => $entityPkValue
193:         );
194:         $data = $this->getConnection()->fetchAll($select, $bind);
195: 
196:         foreach ($data as $item) {
197:             $rating = $this->getItemById($item['rating_id']);
198:             if ($rating && $item['count']>0) {
199:                 $rating->setSummary($item['sum']/$item['count']);
200:             }
201:         }
202:         return $this;
203:     }
204: 
205:     /**
206:      * Add rating store name
207:      *
208:      * @param int $storeId
209:      * @return Mage_Rating_Model_Resource_Rating_Collection
210:      */
211:     public function addRatingPerStoreName($storeId)
212:     {
213:         $adapter = $this->getConnection();
214:         $ratingCodeCond = $adapter->getIfNullSql('title.value', 'main_table.rating_code');
215:         $this->getSelect()
216:             ->joinLeft(array('title' => $this->getTable('rating_title')),
217:                 $adapter->quoteInto('main_table.rating_id=title.rating_id AND title.store_id = ?', (int) $storeId),
218:                 array('rating_code' => $ratingCodeCond));
219:         return $this;
220:     }
221: 
222:     /**
223:      * Add stores to collection
224:      *
225:      * @return Mage_Rating_Model_Resource_Rating_Collection
226:      */
227:     public function addStoresToCollection()
228:     {
229:         if (!$this->_isCollectionLoaded) {
230:             return $this;
231:         }
232:         $ratingIds = array();
233:         foreach ($this as $item) {
234:             $ratingIds[] = $item->getId();
235:             $item->setStores(array());
236:         }
237:         if (!$ratingIds) {
238:             return $this;
239:         }
240:         $adapter = $this->getConnection();
241: 
242:         $inCond = $adapter->prepareSqlCondition('rating_id', array(
243:             'in' => $ratingIds
244:         ));
245: 
246:         $this->_select = $adapter
247:             ->select()
248:             ->from($this->getTable('rating_store'))
249:             ->where($inCond);
250: 
251:         $data = $adapter->fetchAll($this->_select);
252:         if (is_array($data) && count($data) > 0) {
253:             foreach ($data as $row) {
254:                 $item = $this->getItemById($row['rating_id']);
255:                 $item->setStores(array_merge($item->getStores(), array($row['store_id'])));
256:             }
257:         }
258:         return $this;
259:     }
260: }
261: 
Magento 1.7.0.2 API documentation generated by ApiGen 2.8.0