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_XmlConnect
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 block
29: *
30: * @category Mage
31: * @package Mage_XmlConnect
32: * @author Magento Core Team <core@magentocommerce.com>
33: */
34: class Mage_XmlConnect_Block_Catalog_Product_Review_List extends Mage_XmlConnect_Block_Catalog_Product_Review
35: {
36: /**
37: * Store reviews collection
38: *
39: * @var Mage_Review_Model_Mysql4_Review_Collection
40: */
41: protected $_reviewCollection = null;
42:
43: /**
44: * Produce reviews list xml object
45: *
46: * @return Mage_XmlConnect_Model_Simplexml_Element
47: */
48: public function getReviewsXmlObject()
49: {
50: $reviewsXmlObj = Mage::getModel('xmlconnect/simplexml_element', '<reviews></reviews>');
51: $collection = $this->_getReviewCollection();
52:
53: if (!$collection) {
54: return $reviewsXmlObj;
55: }
56: foreach ($collection->getItems() as $review) {
57: $reviewXmlObj = $this->reviewToXmlObject($review);
58: if ($reviewXmlObj) {
59: $reviewsXmlObj->appendChild($reviewXmlObj);
60: }
61: }
62:
63: return $reviewsXmlObj;
64: }
65:
66: /**
67: * Retrieve reviews collection with all prepared data and limitations
68: *
69: * @return Mage_Eav_Model_Entity_Collection_Abstract
70: */
71: protected function _getReviewCollection()
72: {
73: if (is_null($this->_reviewCollection)) {
74: $product = $this->getProduct();
75: $request = $this->getRequest();
76: if (!$product) {
77: return null;
78: }
79: /** @var $collection Mage_Review_Model_Mysql4_Review_Collection */
80: $collection = Mage::getResourceModel('review/review_collection')
81: ->addEntityFilter('product', $product->getId())->addStoreFilter(Mage::app()->getStore()->getId())
82: ->addStatusFilter('approved')->setDateOrder();
83:
84: /**
85: * Apply offset and count
86: */
87: $offset = (int)$request->getParam('offset', 0);
88: $count = (int)$request->getParam('count', 0);
89: $count = $count <= 0 ? 1 : $count;
90: $collection->getSelect()->limit($count, $offset);
91:
92: $this->_reviewCollection = $collection;
93: }
94: return $this->_reviewCollection;
95: }
96:
97: /**
98: * Render reviews list xml
99: *
100: * @return string
101: */
102: protected function _toHtml()
103: {
104: $product = Mage::getModel('catalog/product')->load((int)$this->getRequest()->getParam('id', 0));
105: if ($product->getId()) {
106: $this->setProduct($product);
107: }
108:
109: return $this->getReviewsXmlObject()->asNiceXml();
110: }
111: }
112: