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: * Review detailed view block
29: *
30: * @category Mage
31: * @package Mage_Review
32: * @author Magento Core Team <core@magentocommerce.com>
33: */
34:
35: class Mage_Review_Block_View extends Mage_Catalog_Block_Product_Abstract
36: {
37: public function __construct()
38: {
39: parent::__construct();
40: $this->setTemplate('review/view.phtml');
41: }
42:
43: /**
44: * Retrieve current product model from registry
45: *
46: * @return Mage_Catalog_Model_Product
47: */
48: public function getProductData()
49: {
50: return Mage::registry('current_product');
51: }
52:
53: /**
54: * Retrieve current review model from registry
55: *
56: * @return Mage_Review_Model_Review
57: */
58: public function getReviewData()
59: {
60: return Mage::registry('current_review');
61: }
62:
63: /**
64: * Prepare link to review list for current product
65: *
66: * @return string
67: */
68: public function getBackUrl()
69: {
70: return Mage::getUrl('*/*/list', array('id' => $this->getProductData()->getId()));
71: }
72:
73: /**
74: * Retrieve collection of ratings
75: *
76: * @return Mage_Rating_Model_Mysql4_Rating_Option_Vote_Collection
77: */
78: public function getRating()
79: {
80: if( !$this->getRatingCollection() ) {
81: $ratingCollection = Mage::getModel('rating/rating_option_vote')
82: ->getResourceCollection()
83: ->setReviewFilter($this->getReviewId())
84: ->setStoreFilter(Mage::app()->getStore()->getId())
85: ->addRatingInfo(Mage::app()->getStore()->getId())
86: ->load();
87: $this->setRatingCollection( ( $ratingCollection->getSize() ) ? $ratingCollection : false );
88: }
89: return $this->getRatingCollection();
90: }
91:
92: /**
93: * Retrieve rating summary for current product
94: *
95: * @return string
96: */
97: public function getRatingSummary()
98: {
99: if( !$this->getRatingSummaryCache() ) {
100: $this->setRatingSummaryCache(Mage::getModel('rating/rating')->getEntitySummary($this->getProductData()->getId()));
101: }
102: return $this->getRatingSummaryCache();
103: }
104:
105: /**
106: * Retrieve total review count for current product
107: *
108: * @return string
109: */
110: public function getTotalReviews()
111: {
112: if( !$this->getTotalReviewsCache() ) {
113: $this->setTotalReviewsCache(Mage::getModel('review/review')->getTotalReviews($this->getProductData()->getId(), false, Mage::app()->getStore()->getId()));
114: }
115: return $this->getTotalReviewsCache();
116: }
117:
118: /**
119: * Format date in long format
120: *
121: * @param string $date
122: * @return string
123: */
124: public function dateFormat($date)
125: {
126: return $this->formatDate($date, Mage_Core_Model_Locale::FORMAT_TYPE_LONG);
127: }
128: }
129: