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: * Customer Reviews list block
30: *
31: * @category Mage
32: * @package Mage_Review
33: * @author Magento Core Team <core@magentocommerce.com>
34: */
35: class Mage_Review_Block_Customer_List extends Mage_Customer_Block_Account_Dashboard
36: {
37: /**
38: * Product reviews collection
39: *
40: * @var Mage_Review_Model_Resource_Review_Product_Collection
41: */
42: protected $_collection;
43:
44: /**
45: * Initializes collection
46: */
47: protected function _construct()
48: {
49: $this->_collection = Mage::getModel('review/review')->getProductCollection();
50: $this->_collection
51: ->addStoreFilter(Mage::app()->getStore()->getId())
52: ->addCustomerFilter(Mage::getSingleton('customer/session')->getCustomerId())
53: ->setDateOrder();
54: }
55:
56: /**
57: * Gets collection items count
58: *
59: * @return int
60: */
61: public function count()
62: {
63: return $this->_collection->getSize();
64: }
65:
66: /**
67: * Get html code for toolbar
68: *
69: * @return string
70: */
71: public function getToolbarHtml()
72: {
73: return $this->getChildHtml('toolbar');
74: }
75:
76: /**
77: * Initializes toolbar
78: *
79: * @return Mage_Core_Block_Abstract
80: */
81: protected function _prepareLayout()
82: {
83: $toolbar = $this->getLayout()->createBlock('page/html_pager', 'customer_review_list.toolbar')
84: ->setCollection($this->getCollection());
85:
86: $this->setChild('toolbar', $toolbar);
87: return parent::_prepareLayout();
88: }
89:
90: /**
91: * Get collection
92: *
93: * @return Mage_Review_Model_Resource_Review_Product_Collection
94: */
95: protected function _getCollection()
96: {
97: return $this->_collection;
98: }
99:
100: /**
101: * Get collection
102: *
103: * @return Mage_Review_Model_Resource_Review_Product_Collection
104: */
105: public function getCollection()
106: {
107: return $this->_getCollection();
108: }
109:
110: /**
111: * Get review link
112: *
113: * @return string
114: */
115: public function getReviewLink()
116: {
117: return Mage::getUrl('review/customer/view/');
118: }
119:
120: /**
121: * Get product link
122: *
123: * @return string
124: */
125: public function getProductLink()
126: {
127: return Mage::getUrl('catalog/product/view/');
128: }
129:
130: /**
131: * Format date in short format
132: *
133: * @param $date
134: * @return string
135: */
136: public function dateFormat($date)
137: {
138: return $this->formatDate($date, Mage_Core_Model_Locale::FORMAT_TYPE_SHORT);
139: }
140:
141: /**
142: * @return Mage_Core_Block_Abstract
143: */
144: protected function _beforeToHtml()
145: {
146: $this->_getCollection()
147: ->load()
148: ->addReviewSummary();
149: return parent::_beforeToHtml();
150: }
151: }
152: