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_Review_Block_Customer_List
  • Mage_Review_Block_Customer_Recent
  • Mage_Review_Block_Customer_View
  • Mage_Review_Block_Form
  • Mage_Review_Block_Helper
  • Mage_Review_Block_Product_View
  • Mage_Review_Block_Product_View_List
  • Mage_Review_Block_View
  • Mage_Review_CustomerController
  • Mage_Review_Helper_Data
  • Mage_Review_Model_Mysql4_Review
  • Mage_Review_Model_Mysql4_Review_Collection
  • Mage_Review_Model_Mysql4_Review_Product_Collection
  • Mage_Review_Model_Mysql4_Review_Status_Collection
  • Mage_Review_Model_Mysql4_Review_Summary
  • Mage_Review_Model_Mysql4_Review_Summary_Collection
  • Mage_Review_Model_Observer
  • Mage_Review_Model_Resource_Review
  • Mage_Review_Model_Resource_Review_Collection
  • Mage_Review_Model_Resource_Review_Product_Collection
  • Mage_Review_Model_Resource_Review_Status
  • Mage_Review_Model_Resource_Review_Status_Collection
  • Mage_Review_Model_Resource_Review_Summary
  • Mage_Review_Model_Resource_Review_Summary_Collection
  • Mage_Review_Model_Review
  • Mage_Review_Model_Review_Status
  • Mage_Review_Model_Review_Summary
  • Mage_Review_Model_Session
  • Mage_Review_ProductController
  • 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_Review
 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:  * Review collection resource model
 30:  *
 31:  * @category    Mage
 32:  * @package     Mage_Review
 33:  * @author      Magento Core Team <core@magentocommerce.com>
 34:  */
 35: class Mage_Review_Model_Resource_Review_Collection extends Mage_Core_Model_Resource_Db_Collection_Abstract
 36: {
 37:     /**
 38:      * Review table
 39:      *
 40:      * @var string
 41:      */
 42:     protected $_reviewTable;
 43: 
 44:     /**
 45:      * Review detail table
 46:      *
 47:      * @var string
 48:      */
 49:     protected $_reviewDetailTable;
 50: 
 51:     /**
 52:      * Review status table
 53:      *
 54:      * @var string
 55:      */
 56:     protected $_reviewStatusTable;
 57: 
 58:     /**
 59:      * Review entity table
 60:      *
 61:      * @var string
 62:      */
 63:     protected $_reviewEntityTable;
 64: 
 65:     /**
 66:      * Review store table
 67:      *
 68:      * @var string
 69:      */
 70:     protected $_reviewStoreTable;
 71: 
 72:     /**
 73:      * Add store data flag
 74:      * @var bool
 75:      */
 76:     protected $_addStoreDataFlag   = false;
 77: 
 78:     /**
 79:      * Define module
 80:      *
 81:      */
 82:     protected function _construct()
 83:     {
 84:         $this->_init('review/review');
 85:         $this->_reviewTable         = $this->getTable('review/review');
 86:         $this->_reviewDetailTable   = $this->getTable('review/review_detail');
 87:         $this->_reviewStatusTable   = $this->getTable('review/review_status');
 88:         $this->_reviewEntityTable   = $this->getTable('review/review_entity');
 89:         $this->_reviewStoreTable    = $this->getTable('review/review_store');
 90: 
 91:     }
 92: 
 93:     /**
 94:      * init select
 95:      *
 96:      * @return Mage_Review_Model_Resource_Review_Product_Collection
 97:      */
 98:     protected function _initSelect()
 99:     {
100:         parent::_initSelect();
101:         $this->getSelect()
102:             ->join(array('detail' => $this->_reviewDetailTable),
103:                 'main_table.review_id = detail.review_id',
104:                 array('detail_id', 'title', 'detail', 'nickname', 'customer_id'));
105:         return $this;
106:     }
107: 
108:     /**
109:      * Enter description here ...
110:      *
111:      * @param unknown_type $customerId
112:      * @return Mage_Review_Model_Resource_Review_Collection
113:      */
114:     public function addCustomerFilter($customerId)
115:     {
116:         $this->addFilter('customer',
117:             $this->getConnection()->quoteInto('detail.customer_id=?', $customerId),
118:             'string');
119:         return $this;
120:     }
121: 
122:     /**
123:      * Add store filter
124:      *
125:      * @param int|array $storeId
126:      * @return Mage_Review_Model_Resource_Review_Collection
127:      */
128:     public function addStoreFilter($storeId)
129:     {
130:         $inCond = $this->getConnection()->prepareSqlCondition('store.store_id', array('in' => $storeId));
131:         $this->getSelect()->join(array('store'=>$this->_reviewStoreTable),
132:             'main_table.review_id=store.review_id',
133:             array());
134:         $this->getSelect()->where($inCond);
135:         return $this;
136:     }
137: 
138:     /**
139:      * Add stores data
140:      *
141:      * @return Mage_Review_Model_Resource_Review_Collection
142:      */
143:     public function addStoreData()
144:     {
145:         $this->_addStoreDataFlag = true;
146:         return $this;
147:     }
148: 
149:     /**
150:      * Add entity filter
151:      *
152:      * @param int|string $entity
153:      * @param int $pkValue
154:      * @return Mage_Review_Model_Resource_Review_Collection
155:      */
156:     public function addEntityFilter($entity, $pkValue)
157:     {
158:         if (is_numeric($entity)) {
159:             $this->addFilter('entity',
160:                 $this->getConnection()->quoteInto('main_table.entity_id=?', $entity),
161:                 'string');
162:         } elseif (is_string($entity)) {
163:             $this->_select->join($this->_reviewEntityTable,
164:                 'main_table.entity_id='.$this->_reviewEntityTable.'.entity_id',
165:                 array('entity_code'));
166: 
167:             $this->addFilter('entity',
168:                 $this->getConnection()->quoteInto($this->_reviewEntityTable.'.entity_code=?', $entity),
169:                 'string');
170:         }
171: 
172:         $this->addFilter('entity_pk_value',
173:             $this->getConnection()->quoteInto('main_table.entity_pk_value=?', $pkValue),
174:             'string');
175: 
176:         return $this;
177:     }
178: 
179:     /**
180:      * Add status filter
181:      *
182:      * @param int|string $status
183:      * @return Mage_Review_Model_Resource_Review_Collection
184:      */
185:     public function addStatusFilter($status)
186:     {
187:         if (is_numeric($status)) {
188:             $this->addFilter('status',
189:                 $this->getConnection()->quoteInto('main_table.status_id=?', $status),
190:                 'string');
191:         } elseif (is_string($status)) {
192:             $this->_select->join($this->_reviewStatusTable,
193:                 'main_table.status_id='.$this->_reviewStatusTable.'.status_id',
194:                 array('status_code'));
195: 
196:             $this->addFilter('status',
197:                 $this->getConnection()->quoteInto($this->_reviewStatusTable.'.status_code=?', $status),
198:                 'string');
199:         }
200:         return $this;
201:     }
202: 
203:     /**
204:      * Set date order
205:      *
206:      * @param string $dir
207:      * @return Mage_Review_Model_Resource_Review_Collection
208:      */
209:     public function setDateOrder($dir = 'DESC')
210:     {
211:         $this->setOrder('main_table.created_at', $dir);
212:         return $this;
213:     }
214: 
215:     /**
216:      * Add rate votes
217:      *
218:      * @return Mage_Review_Model_Resource_Review_Collection
219:      */
220:     public function addRateVotes()
221:     {
222:         foreach ($this->getItems() as $item) {
223:             $votesCollection = Mage::getModel('rating/rating_option_vote')
224:                 ->getResourceCollection()
225:                 ->setReviewFilter($item->getId())
226:                 ->setStoreFilter(Mage::app()->getStore()->getId())
227:                 ->addRatingInfo(Mage::app()->getStore()->getId())
228:                 ->load();
229:             $item->setRatingVotes($votesCollection);
230:         }
231: 
232:         return $this;
233:     }
234: 
235:     /**
236:      * Add reviews total count
237:      *
238:      * @return Mage_Review_Model_Resource_Review_Collection
239:      */
240:     public function addReviewsTotalCount()
241:     {
242:         $this->_select->joinLeft(
243:             array('r' => $this->_reviewTable),
244:             'main_table.entity_pk_value = r.entity_pk_value',
245:             array('total_reviews' => new Zend_Db_Expr('COUNT(r.review_id)'))
246:         )
247:         ->group('main_table.review_id');
248: 
249:         /*
250:          * Allow analytic functions usage
251:          */
252:         $this->_useAnalyticFunction = true;
253: 
254:         return $this;
255:     }
256: 
257:     /**
258:      * Load data
259:      *
260:      * @param boolean $printQuery
261:      * @param boolean $logQuery
262:      * @return Mage_Review_Model_Resource_Review_Collection
263:      */
264:     public function load($printQuery = false, $logQuery = false)
265:     {
266:         if ($this->isLoaded()) {
267:             return $this;
268:         }
269:         Mage::dispatchEvent('review_review_collection_load_before', array('collection' => $this));
270:         parent::load($printQuery, $logQuery);
271:         if ($this->_addStoreDataFlag) {
272:             $this->_addStoreData();
273:         }
274:         return $this;
275:     }
276: 
277:     /**
278:      * Add store data
279:      *
280:      */
281:     protected function _addStoreData()
282:     {
283:         $adapter = $this->getConnection();
284: 
285:         $reviewsIds = $this->getColumnValues('review_id');
286:         $storesToReviews = array();
287:         if (count($reviewsIds)>0) {
288:             $inCond = $adapter->prepareSqlCondition('review_id', array('in' => $reviewsIds));
289:             $select = $adapter->select()
290:                 ->from($this->_reviewStoreTable)
291:                 ->where($inCond);
292:             $result = $adapter->fetchAll($select);
293:             foreach ($result as $row) {
294:                 if (!isset($storesToReviews[$row['review_id']])) {
295:                     $storesToReviews[$row['review_id']] = array();
296:                 }
297:                 $storesToReviews[$row['review_id']][] = $row['store_id'];
298:             }
299:         }
300: 
301:         foreach ($this as $item) {
302:             if (isset($storesToReviews[$item->getId()])) {
303:                 $item->setStores($storesToReviews[$item->getId()]);
304:             } else {
305:                 $item->setStores(array());
306:             }
307:         }
308:     }
309: }
310: 
Magento 1.7.0.2 API documentation generated by ApiGen 2.8.0