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_Review - DOC block update #754

Merged
merged 3 commits into from
Jun 27, 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
2 changes: 1 addition & 1 deletion app/code/core/Mage/Review/Block/Customer/List.php
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ public function getProductLink()
/**
* Format date in short format
*
* @param $date
* @param string|Zend_Date|null $date
* @return string
*/
public function dateFormat($date)
Expand Down
29 changes: 28 additions & 1 deletion app/code/core/Mage/Review/Block/Customer/Recent.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,9 @@
* @category Mage
* @package Mage_Review
* @author Magento Core Team <core@magentocommerce.com>
*
* @property Mage_Review_Model_Resource_Review_Product_Collection $_collection
*/

class Mage_Review_Block_Customer_Recent extends Mage_Core_Block_Template
{
public function __construct()
Expand All @@ -50,41 +51,67 @@ public function __construct()
->addReviewSummary();
}

/**
* @return int
*/
public function count()
{
return $this->_collection->getSize();
}

/**
* @return Mage_Review_Model_Resource_Review_Product_Collection
*/
protected function _getCollection()
{
return $this->_collection;
}

/**
* @return Mage_Review_Model_Resource_Review_Product_Collection
*/
public function getCollection()
{
return $this->_getCollection();
}

/**
* @return string
*/
public function getReviewLink()
{
return Mage::getUrl('review/customer/view/');
}

/**
* @return string
*/
public function getProductLink()
{
return Mage::getUrl('catalog/product/view/');
}

/**
* @param string $date
* @return string
*/
public function dateFormat($date)
{
return $this->formatDate($date, Mage_Core_Model_Locale::FORMAT_TYPE_SHORT);
}

/**
* @return string
*/
public function getAllReviewsUrl()
{
return Mage::getUrl('review/customer');
}

/**
* @param int $id
* @return string
*/
public function getReviewUrl($id)
{
return Mage::getUrl('review/customer/view', array('id' => $id));
Expand Down
51 changes: 44 additions & 7 deletions app/code/core/Mage/Review/Block/Customer/View.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,20 @@
* @category Mage
* @package Mage_Review
* @author Magento Core Team <core@magentocommerce.com>
*
* @method string getReviewId()
* @method $this setReviewId(string $value)
* @method Mage_Catalog_Model_Product getProductCacheData()
* @method $this setProductCacheData(Mage_Catalog_Model_Product $value)
* @method Mage_Rating_Model_Resource_Rating_Option_Vote_Collection|false getRatingCollection()
* @method $this setRatingCollection(Mage_Rating_Model_Resource_Rating_Option_Vote_Collection|false $value)
* @method array getRatingSummaryCache()
* @method setRatingSummaryCache(array $value)
* @method Mage_Review_Model_Review getReviewCachedData()
* @method $this setReviewCachedData(Mage_Review_Model_Review $value)
* @method int getTotalReviewsCache()
* @method $this setTotalReviewsCache(int $entityPkValue, bool $approvedOnly, int $storeId)
*/

class Mage_Review_Block_Customer_View extends Mage_Catalog_Block_Product_Abstract
{
public function __construct()
Expand All @@ -42,9 +54,13 @@ public function __construct()
$this->setReviewId($this->getRequest()->getParam('id', false));
}

/**
* @return Mage_Catalog_Model_Product
* @throws Mage_Core_Model_Store_Exception
*/
public function getProductData()
{
if( $this->getReviewId() && !$this->getProductCacheData() ) {
if ($this->getReviewId() && !$this->getProductCacheData()) {
$product = Mage::getModel('catalog/product')
->setStoreId(Mage::app()->getStore()->getId())
->load($this->getReviewData()->getEntityPkValue());
Expand All @@ -53,51 +69,72 @@ public function getProductData()
return $this->getProductCacheData();
}

/**
* @return Mage_Review_Model_Review
*/
public function getReviewData()
{
if( $this->getReviewId() && !$this->getReviewCachedData() ) {
if ($this->getReviewId() && !$this->getReviewCachedData()) {
$this->setReviewCachedData(Mage::getModel('review/review')->load($this->getReviewId()));
}
return $this->getReviewCachedData();
}

/**
* @return string
*/
public function getBackUrl()
{
return Mage::getUrl('review/customer');
}

/**
* @return Mage_Rating_Model_Resource_Rating_Option_Vote_Collection
* @throws Mage_Core_Model_Store_Exception
*/
public function getRating()
{
if( !$this->getRatingCollection() ) {
if (!$this->getRatingCollection()) {
$ratingCollection = Mage::getModel('rating/rating_option_vote')
->getResourceCollection()
->setReviewFilter($this->getReviewId())
->addRatingInfo(Mage::app()->getStore()->getId())
->setStoreFilter(Mage::app()->getStore()->getId())
->load();

$this->setRatingCollection( ( $ratingCollection->getSize() ) ? $ratingCollection : false );
$this->setRatingCollection(( $ratingCollection->getSize() ) ? $ratingCollection : false);
}

return $this->getRatingCollection();
}

/**
* @return array
*/
public function getRatingSummary()
{
if( !$this->getRatingSummaryCache() ) {
if (!$this->getRatingSummaryCache()) {
$this->setRatingSummaryCache(Mage::getModel('rating/rating')->getEntitySummary($this->getProductData()->getId()));
}
return $this->getRatingSummaryCache();
}

/**
* @return int
* @throws Mage_Core_Model_Store_Exception
*/
public function getTotalReviews()
{
if( !$this->getTotalReviewsCache() ) {
if (!$this->getTotalReviewsCache()) {
$this->setTotalReviewsCache(Mage::getModel('review/review')->getTotalReviews($this->getProductData()->getId()), false, Mage::app()->getStore()->getId());
}
return $this->getTotalReviewsCache();
}

/**
* @param string $date
* @return string
*/
public function dateFormat($date)
{
return $this->formatDate($date, Mage_Core_Model_Locale::FORMAT_TYPE_LONG);
Expand Down
21 changes: 18 additions & 3 deletions app/code/core/Mage/Review/Block/Form.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@
* @category Mage
* @package Mage_Review
* @author Magento Core Team <core@magentocommerce.com>
*
* @method bool getAllowWriteReviewFlag()
* @method $this setAllowWriteReviewFlag(bool $value)
* @method $this setLoginLink(string $value)
*/
class Mage_Review_Block_Form extends Mage_Core_Block_Template
{
Expand All @@ -55,14 +59,14 @@ public function __construct()
Mage::helper('review')->getIsGuestAllowToWrite()
);

if (!$this->getAllowWriteReviewFlag) {
if (!$this->getAllowWriteReviewFlag()) {
$this->setLoginLink(
Mage::getUrl('customer/account/login/', array(
Mage_Customer_Helper_Data::REFERER_QUERY_PARAM_NAME => Mage::helper('core')->urlEncode(
Mage::getUrl('*/*/*', array('_current' => true)) .
'#review-form')
'#review-form'
)
)
))
);
}

Expand All @@ -71,18 +75,29 @@ public function __construct()
->assign('messages', Mage::getSingleton('review/session')->getMessages(true));
}

/**
* @return false|Mage_Catalog_Model_Product|Mage_Core_Model_Abstract
* @throws Exception
*/
public function getProductInfo()
{
$product = Mage::getModel('catalog/product');
return $product->load($this->getRequest()->getParam('id'));
}

/**
* @return string
*/
public function getAction()
{
$productId = Mage::app()->getRequest()->getParam('id', false);
return Mage::getUrl('review/product/post', array('id' => $productId, '_secure' => $this->_isSecure()));
}

/**
* @return Mage_Rating_Model_Resource_Rating_Collection
* @throws Mage_Core_Model_Store_Exception
*/
public function getRatings()
{
$ratingCollection = Mage::getModel('rating/rating')
Expand Down
20 changes: 20 additions & 0 deletions app/code/core/Mage/Review/Block/Helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@
* @category Mage
* @package Mage_Review
* @author Magento Core Team <core@magentocommerce.com>
*
* @method $this setDisplayIfEmpty(bool $value)
* @method Mage_Catalog_Model_Product getProduct()
* @method $this setProduct(Mage_Catalog_Model_Product $value)
*/
class Mage_Review_Block_Helper extends Mage_Core_Block_Template
{
Expand All @@ -38,6 +42,13 @@ class Mage_Review_Block_Helper extends Mage_Core_Block_Template
'short' => 'review/helper/summary_short.phtml'
);

/**
* @param Mage_Catalog_Model_Product $product
* @param string $templateType
* @param bool $displayIfNoReviews
* @return string
* @throws Mage_Core_Model_Store_Exception
*/
public function getSummaryHtml($product, $templateType, $displayIfNoReviews)
{
// pick template among available
Expand All @@ -57,16 +68,25 @@ public function getSummaryHtml($product, $templateType, $displayIfNoReviews)
return $this->toHtml();
}

/**
* @return array
*/
public function getRatingSummary()
{
return $this->getProduct()->getRatingSummary()->getRatingSummary();
}

/**
* @return int
*/
public function getReviewsCount()
{
return $this->getProduct()->getRatingSummary()->getReviewsCount();
}

/**
* @return string
*/
public function getReviewsUrl()
{
return Mage::getUrl('review/product/list', array(
Expand Down
7 changes: 6 additions & 1 deletion app/code/core/Mage/Review/Block/Product/View.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,10 @@ protected function _toHtml()
* Reviews collection count will be jerked here
*
* @param Mage_Catalog_Model_Product $product
* @param string $templateType
* @param bool $templateType
* @param bool $displayIfNoReviews
* @return string
* @throws Mage_Core_Model_Store_Exception
*/
public function getReviewsSummaryHtml(Mage_Catalog_Model_Product $product, $templateType = false, $displayIfNoReviews = false)
{
Expand All @@ -69,6 +70,10 @@ public function getReviewsSummaryHtml(Mage_Catalog_Model_Product $product, $temp
;
}

/**
* @return Mage_Review_Model_Resource_Review_Collection
* @throws Mage_Core_Model_Store_Exception
*/
public function getReviewsCollection()
{
if (null === $this->_reviewsCollection) {
Expand Down
15 changes: 15 additions & 0 deletions app/code/core/Mage/Review/Block/Product/View/List.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,18 @@ class Mage_Review_Block_Product_View_List extends Mage_Review_Block_Product_View
{
protected $_forceHasOptions = false;

/**
* @return int
*/
public function getProductId()
{
return Mage::registry('product')->getId();
}

/**
* @return $this
* @throws Mage_Core_Model_Store_Exception
*/
protected function _prepareLayout()
{
parent::_prepareLayout();
Expand All @@ -52,6 +59,10 @@ protected function _prepareLayout()
return $this;
}

/**
* @inheritDoc
* @throws Mage_Core_Model_Store_Exception
*/
protected function _beforeToHtml()
{
$this->getReviewsCollection()
Expand All @@ -60,6 +71,10 @@ protected function _beforeToHtml()
return parent::_beforeToHtml();
}

/**
* @param int $id
* @return string
*/
public function getReviewUrl($id)
{
return Mage::getUrl('review/product/view', array('id' => $id));
Expand Down
Loading