diff --git a/app/code/Mage/Rating/Model/Resource/Rating/Collection.php b/app/code/Mage/Rating/Model/Resource/Rating/Collection.php index b74293c6c46d8..dc5792db3ebaf 100644 --- a/app/code/Mage/Rating/Model/Resource/Rating/Collection.php +++ b/app/code/Mage/Rating/Model/Resource/Rating/Collection.php @@ -40,6 +40,12 @@ class Mage_Rating_Model_Resource_Rating_Collection extends Mage_Core_Model_Resou */ protected $_app; + /** + * Add store data flag + * @var bool + */ + protected $_addStoreDataFlag = false; + /** * Collection constructor * @@ -99,7 +105,7 @@ public function addEntityFilter($entity) } /** - * set order by position field + * Set order by position field * * @param string $dir * @return Mage_Rating_Model_Resource_Rating_Collection @@ -113,7 +119,7 @@ public function setPositionOrder($dir='ASC') /** * Set store filter * - * @param int_type $storeId + * @param int $storeId * @return Mage_Rating_Model_Resource_Rating_Collection */ public function setStoreFilter($storeId) @@ -252,19 +258,74 @@ public function addRatingPerStoreName($storeId) return $this; } + /** + * Add stores data to collection + * + * @return Mage_Rating_Model_Resource_Rating_Collection + */ + public function addStoreData() { + if (!$this->_app->isSingleStoreMode()) { + if (!$this->_isCollectionLoaded) { + $this->_addStoreDataFlag = true; + } elseif (!$this->_addStoreDataFlag) { + $this->_addStoreData(); + } + } + + return $this; + } + /** * Add stores to collection * + * @todo mate method deprecated + * * @return Mage_Rating_Model_Resource_Rating_Collection */ public function addStoresToCollection() { - if ($this->_app->isSingleStoreMode()) { + return $this->addStoreData(); + } + + /** + * Set Active Filter + * + * @param bool $isActive + * @return Mage_Rating_Model_Resource_Rating_Collection + */ + public function setActiveFilter($isActive = true) + { + $this->getSelect()->where('main_table.is_active=?', $isActive); + return $this; + } + + /** + * Load data + * + * @param boolean $printQuery + * @param boolean $logQuery + * @return Mage_Review_Model_Resource_Review_Collection + */ + public function load($printQuery = false, $logQuery = false) + { + if ($this->isLoaded()) { return $this; } - if (!$this->_isCollectionLoaded) { - return $this; + Mage::dispatchEvent('rating_rating_collection_load_before', array('collection' => $this)); + parent::load($printQuery, $logQuery); + if ($this->_addStoreDataFlag) { + $this->_addStoreData(); } + return $this; + } + + /** + * Add store data + * + * @return Mage_Review_Model_Resource_Review_Collection + */ + protected function _addStoreData() + { $ratingIds = array(); foreach ($this as $item) { $ratingIds[] = $item->getId(); @@ -275,14 +336,14 @@ public function addStoresToCollection() } $adapter = $this->getConnection(); - $inCond = $adapter->prepareSqlCondition('rating_id', array( + $inCondition = $adapter->prepareSqlCondition('rating_id', array( 'in' => $ratingIds )); $this->_select = $adapter ->select() ->from($this->getTable('rating_store')) - ->where($inCond); + ->where($inCondition); $data = $adapter->fetchAll($this->_select); if (is_array($data) && count($data) > 0) { @@ -291,18 +352,7 @@ public function addStoresToCollection() $item->setStores(array_merge($item->getStores(), array($row['store_id']))); } } - return $this; - } - /** - * Set Active Filter - * - * @param bool $isActive - * @return Mage_Rating_Model_Resource_Rating_Collection - */ - public function setActiveFilter($isActive = true) - { - $this->getSelect()->where('main_table.is_active=?', $isActive); return $this; } }