Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mage_Rating - DOC block update #756

Merged
merged 1 commit into from
Jul 6, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion app/code/core/Mage/Rating/Block/Entity/Detailed.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@
* @category Mage
* @package Mage_Rating
* @author Magento Core Team <core@magentocommerce.com>
*
* @method $this setEntityId(int $value)
*/
class Mage_Rating_Block_Entity_Detailed extends Mage_Core_Block_Template
{
Expand All @@ -39,6 +41,10 @@ public function __construct()
$this->setTemplate('rating/detailed.phtml');
}

/**
* @return string
* @throws Mage_Core_Model_Store_Exception
*/
protected function _toHtml()
{
$entityId = Mage::app()->getRequest()->getParam('id');
Expand All @@ -56,7 +62,7 @@ protected function _toHtml()

$ratingCollection = Mage::getModel('rating/rating')
->getResourceCollection()
->addEntityFilter('product') # TOFIX
->addEntityFilter('product') # @todo TOFIX
->setPositionOrder()
->setStoreFilter(Mage::app()->getStore()->getId())
->addRatingPerStoreName(Mage::app()->getStore()->getId())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
* @package Mage_Rating
* @author Magento Core Team <core@magentocommerce.com>
*/
class Mage_Rating_Model_Mysql4_Rating_Option_Vote_Collection
extends Mage_Rating_Model_Resource_Rating_Option_Vote_Collection
class Mage_Rating_Model_Mysql4_Rating_Option_Vote_Collection extends Mage_Rating_Model_Resource_Rating_Option_Vote_Collection
{
}
5 changes: 3 additions & 2 deletions app/code/core/Mage/Rating/Model/Observer.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,12 @@ class Mage_Rating_Model_Observer
/**
* Cleanup product ratings after product delete
*
* @param Varien_Event_Observer $observer
* @return Mage_CatalogIndex_Model_Observer
* @param Varien_Event_Observer $observer
* @return Mage_Rating_Model_Observer
*/
public function processProductAfterDeleteEvent(Varien_Event_Observer $observer)
{
/** @var Mage_Catalog_Model_Product $eventProduct */
$eventProduct = $observer->getEvent()->getProduct();
if ($eventProduct && $eventProduct->getId()) {
Mage::getResourceSingleton('rating/rating')->deleteAggregatedRatingsByProductId($eventProduct->getId());
Expand Down
55 changes: 45 additions & 10 deletions app/code/core/Mage/Rating/Model/Rating.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,16 +29,36 @@
*
* @method Mage_Rating_Model_Resource_Rating getResource()
* @method Mage_Rating_Model_Resource_Rating _getResource()
* @method Mage_Rating_Model_Resource_Rating_Collection getCollection()
* @method Mage_Rating_Model_Resource_Rating_Collection getResourceCollection()
*
* @method $this setCount(int $value)
* @method $this setCustomerId(int $value)
* @method $this setEntityId(int $value)
* @method string getEntityPkValue()
* @method $this setEntityPkValue(string $value)
* @method $this setId(string $value)
* @method $this setPosition(string $value)
* @method bool hasRatingCodes()
* @method string getRatingCode()
* @method $this setRatingCode(string $value)
* @method array getRatingCodes()
* @method Mage_Rating_Model_Rating setRatingCodes(array $value)
* @method $this setRatingCodes(array $value)
* @method $this setRatingId(int $value)
* @method int getReviewId()
* @method $this setReviewId(int $value)
* @method bool hasStores()
* @method int getStoreId()
* @method $this setStoreId(int $value)
* @method array getStores()
* @method Mage_Rating_Model_Rating setStores(array $value)
* @method string getRatingCode()
* @method Mage_Rating_Model_Rating getRatingCode(string $value)
* @method $this setStores(array $value)
* @method $this setSum(int $value)
* @method $this setSummary(float|int $param)
* @method int getVoteId()
*
* @category Mage
* @package Mage_Rating
* @author Magento Core Team <core@magentocommerce.com>
* @author Magento Core Team <core@magentocommerce.com>
*/
class Mage_Rating_Model_Rating extends Mage_Core_Model_Abstract
{
Expand All @@ -60,6 +80,11 @@ protected function _construct()
$this->_init('rating/rating');
}

/**
* @param int $optionId
* @param string $entityPkValue
* @return $this
*/
public function addOptionVote($optionId, $entityPkValue)
{
Mage::getModel('rating/rating_option')->setOptionId($optionId)
Expand All @@ -70,6 +95,10 @@ public function addOptionVote($optionId, $entityPkValue)
return $this;
}

/**
* @param int $optionId
* @return $this
*/
public function updateOptionVote($optionId)
{
Mage::getModel('rating/rating_option')->setOptionId($optionId)
Expand All @@ -89,8 +118,7 @@ public function getOptions()
{
if ($options = $this->getData('options')) {
return $options;
}
elseif ($id = $this->getId()) {
} elseif ($id = $this->getId()) {
return Mage::getResourceModel('rating/rating_option_collection')
->addRatingFilter($id)
->setPositionOrder()
Expand All @@ -103,16 +131,23 @@ public function getOptions()
/**
* Get rating collection object
*
* @return array
* @param string $entityPkValue
* @param bool $onlyForCurrentStore
* @return array|Mage_Rating_Model_Rating
*/

public function getEntitySummary($entityPkValue, $onlyForCurrentStore = true)
public function getEntitySummary($entityPkValue, $onlyForCurrentStore = true)
{
$this->setEntityPkValue($entityPkValue);
return $this->_getResource()->getEntitySummary($this, $onlyForCurrentStore);
}

public function getReviewSummary($reviewId, $onlyForCurrentStore = true)
/**
* @param int $reviewId
* @param bool $onlyForCurrentStore
* @return array
*/
public function getReviewSummary($reviewId, $onlyForCurrentStore = true)
{
$this->setReviewId($reviewId);
return $this->_getResource()->getReviewSummary($this, $onlyForCurrentStore);
Expand Down
4 changes: 4 additions & 0 deletions app/code/core/Mage/Rating/Model/Rating/Entity.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,10 @@ protected function _construct()
$this->_init('rating/rating_entity');
}

/**
* @param string $entityCode
* @return int
*/
public function getIdByCode($entityCode)
{
return $this->_getResource()->getIdByCode($entityCode);
Expand Down
30 changes: 24 additions & 6 deletions app/code/core/Mage/Rating/Model/Rating/Option.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,16 +27,26 @@
/**
* Rating option model
*
* @method Mage_Rating_Model_Resource_Rating_Option_Collection getResourceCollection()
* @method Mage_Rating_Model_Resource_Rating_Option _getResource()
* @method Mage_Rating_Model_Resource_Rating_Option getResource()
* @method int getRatingId()
* @method Mage_Rating_Model_Rating_Option setRatingId(int $value)
* @method string getCode()
* @method Mage_Rating_Model_Rating_Option setCode(string $value)
* @method int getValue()
* @method Mage_Rating_Model_Rating_Option setValue(int $value)
* @method $this setCode(string $value)
* @method int getDoUpdate()
* @method $this setDoUpdate(int $value)
* @method string getEntityPkValue()
* @method $this setEntityPkValue(string $value)
* @method $this setOptionId(int $value)
* @method int getPosition()
* @method Mage_Rating_Model_Rating_Option setPosition(int $value)
* @method $this setPosition(int $value)
* @method int getRatingId()
* @method $this setRatingId(int $value)
* @method int getReviewId()
* @method $this setReviewId(int $value)
* @method int getValue()
* @method $this setValue(int $value)
* @method int getVoteId()
* @method $this setVoteId(int $value)
*
* @category Mage
* @package Mage_Rating
Expand All @@ -49,12 +59,20 @@ protected function _construct()
$this->_init('rating/rating_option');
}

/**
* @return $this
* @throws Exception
*/
public function addVote()
{
$this->getResource()->addVote($this);
return $this;
}

/**
* @param int $id
* @return $this
*/
public function setId($id)
{
$this->setOptionId($id);
Expand Down
5 changes: 5 additions & 0 deletions app/code/core/Mage/Rating/Model/Rating/Option/Vote.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,11 @@
* @category Mage
* @package Mage_Rating
* @author Magento Core Team <core@magentocommerce.com>
*
* @method Mage_Rating_Model_Resource_Rating_Option_Vote_Collection getResourceCollection()()
* @method string getEntityPkValue()
* @method int getRatingId()
* @method $this setRatingOptions(Mage_Rating_Model_Resource_Rating_Option_Collection $options)
*/

class Mage_Rating_Model_Rating_Option_Vote extends Mage_Core_Model_Abstract
Expand Down
70 changes: 44 additions & 26 deletions app/code/core/Mage/Rating/Model/Resource/Rating.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,15 +77,16 @@ protected function _getLoadSelect($field, $value, $object)
$select->joinLeft(
array('title' => $this->getTable('rating/rating_title')),
$adapter->quoteInto("{$table}.rating_id = title.rating_id AND title.store_id = ?", $storeId),
array('rating_code' => $codeExpr));
array('rating_code' => $codeExpr)
);

return $select;
}

/**
* Actions after load
*
* @param Mage_Rating_Model_Rating $object
* @param Mage_Core_Model_Abstract|Mage_Rating_Model_Rating $object
* @return $this
*/
protected function _afterLoad(Mage_Core_Model_Abstract $object)
Expand Down Expand Up @@ -131,7 +132,7 @@ public function getStores($ratingId)
/**
* Actions after save
*
* @param Mage_Rating_Model_Rating $object
* @param Mage_Core_Model_Abstract|Mage_Rating_Model_Rating $object
* @return $this
*/
protected function _afterSave(Mage_Core_Model_Abstract $object)
Expand Down Expand Up @@ -227,7 +228,7 @@ protected function _afterSave(Mage_Core_Model_Abstract $object)
* Perform actions after object delete
* Prepare rating data for reaggregate all data for reviews
*
* @param Mage_Rating_Model_Rating $object
* @param Mage_Core_Model_Abstract|Mage_Rating_Model_Rating $object
* @return $this
*/
protected function _afterDelete(Mage_Core_Model_Abstract $object)
Expand All @@ -252,7 +253,7 @@ protected function _afterDelete(Mage_Core_Model_Abstract $object)
*
* @param Mage_Rating_Model_Rating $object
* @param boolean $onlyForCurrentStore
* @return array
* @return array|Mage_Rating_Model_Rating
*/
public function getEntitySummary($object, $onlyForCurrentStore = true)
{
Expand Down Expand Up @@ -280,6 +281,7 @@ public function getEntitySummary($object, $onlyForCurrentStore = true)

$usedStoresId = array_keys($result);

/** @var Mage_Core_Model_Store $store */
foreach ($stores as $store) {
if (!in_array($store->getId(), $usedStoresId)) {
$clone = clone $object;
Expand Down Expand Up @@ -307,23 +309,33 @@ protected function _getEntitySummaryData($object)
$countColumn = new Zend_Db_Expr("COUNT(*)");

$select = $adapter->select()
->from(array('rating_vote' => $this->getTable('rating/rating_option_vote')),
->from(
array('rating_vote' => $this->getTable('rating/rating_option_vote')),
array(
'entity_pk_value' => 'rating_vote.entity_pk_value',
'sum' => $sumColumn,
'count' => $countColumn))
->join(array('review' => $this->getTable('review/review')),
'count' => $countColumn)
)
->join(
array('review' => $this->getTable('review/review')),
'rating_vote.review_id=review.review_id',
array())
->joinLeft(array('review_store' => $this->getTable('review/review_store')),
array()
)
->joinLeft(
array('review_store' => $this->getTable('review/review_store')),
'rating_vote.review_id=review_store.review_id',
array('review_store.store_id'))
->join(array('rating_store' => $this->getTable('rating/rating_store')),
array('review_store.store_id')
)
->join(
array('rating_store' => $this->getTable('rating/rating_store')),
'rating_store.rating_id = rating_vote.rating_id AND rating_store.store_id = review_store.store_id',
array())
->join(array('review_status' => $this->getTable('review/review_status')),
array()
)
->join(
array('review_status' => $this->getTable('review/review_status')),
'review.status_id = review_status.status_id',
array())
array()
)
->where('review_status.status_code = :status_code')
->group('rating_vote.entity_pk_value')
->group('review_store.store_id');
Expand All @@ -343,7 +355,7 @@ protected function _getEntitySummaryData($object)
*
* @param Mage_Rating_Model_Rating $object
* @param boolean $onlyForCurrentStore
* @return array
* @return array|Mage_Rating_Model_Rating
*/
public function getReviewSummary($object, $onlyForCurrentStore = true)
{
Expand All @@ -352,17 +364,23 @@ public function getReviewSummary($object, $onlyForCurrentStore = true)
$sumColumn = new Zend_Db_Expr("SUM(rating_vote.{$adapter->quoteIdentifier('percent')})");
$countColumn = new Zend_Db_Expr('COUNT(*)');
$select = $adapter->select()
->from(array('rating_vote' => $this->getTable('rating/rating_option_vote')),
->from(
array('rating_vote' => $this->getTable('rating/rating_option_vote')),
array(
'sum' => $sumColumn,
'count' => $countColumn
))
->joinLeft(array('review_store' => $this->getTable('review/review_store')),
)
)
->joinLeft(
array('review_store' => $this->getTable('review/review_store')),
'rating_vote.review_id = review_store.review_id',
array('review_store.store_id'))
->join(array('rating_store' => $this->getTable('rating/rating_store')),
array('review_store.store_id')
)
->join(
array('rating_store' => $this->getTable('rating/rating_store')),
'rating_store.rating_id = rating_vote.rating_id AND rating_store.store_id = review_store.store_id',
array())
array()
)
->where('rating_vote.review_id = :review_id')
->group('rating_vote.review_id')
->group('review_store.store_id');
Expand Down Expand Up @@ -390,15 +408,15 @@ public function getReviewSummary($object, $onlyForCurrentStore = true)

$usedStoresId = array_keys($result);

/** @var Mage_Core_Model_Store $store */
foreach ($stores as $store) {
if (!in_array($store->getId(), $usedStoresId)) {
$clone = clone $object;
if (!in_array($store->getId(), $usedStoresId)) {
$clone = clone $object;
$clone->setCount(0);
$clone->setSum(0);
$clone->setStoreId($store->getId());
$result[$store->getId()] = $clone;

}
}
}

return array_values($result);
Expand Down
Loading