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 xml renderer
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 extends Mage_XmlConnect_Block_Catalog
35: {
36: /**
37: * Limit to product review text length
38: */
39: const REVIEW_DETAIL_TRUNCATE_LEN = 200;
40:
41: /**
42: * Retrieve review data as xml object
43: *
44: * @param Mage_Review_Model_Review $review
45: * @param string $itemNodeName
46: * @return Mage_XmlConnect_Model_Simplexml_Element
47: */
48: public function reviewToXmlObject(Mage_Review_Model_Review $review, $itemNodeName = 'item')
49: {
50: $rating = 0;
51: $item = Mage::getModel('xmlconnect/simplexml_element', '<' . $itemNodeName . '></' . $itemNodeName . '>');
52: if ($review->getId()) {
53: $item->addChild('review_id', $review->getId());
54: $item->addChild('created_at', $this->formatDate($review->getCreatedAt()));
55: $item->addChild('title', $item->escapeXml($review->getTitle()));
56: $item->addChild('nickname', $item->escapeXml($review->getNickname()));
57: $detail = $item->escapeXml($review->getDetail());
58: if ($itemNodeName == 'item') {
59: $remainder = '';
60: $deviceType = Mage::helper('xmlconnect')->getDeviceType();
61: if ($deviceType != Mage_XmlConnect_Helper_Data::DEVICE_TYPE_IPAD) {
62: $detail = Mage::helper('core/string')
63: ->truncate($detail, self::REVIEW_DETAIL_TRUNCATE_LEN, '', $remainder, false);
64: }
65: }
66: $item->addChild('detail', $detail);
67:
68: $summary = Mage::getModel('rating/rating')->getReviewSummary($review->getId());
69: if ($summary->getCount() > 0) {
70: $rating = round($summary->getSum() / $summary->getCount() / 10);
71: }
72: if ($rating) {
73: $item->addChild('rating_votes', $rating);
74: }
75: }
76: return $item;
77: }
78:
79: /**
80: * Render review xml
81: *
82: * @return string
83: */
84: protected function _toHtml()
85: {
86: $review = Mage::getModel('review/review')->load((int)$this->getRequest()->getParam('id', 0));
87: return $this->reviewToXmlObject($review, 'review')->asNiceXml();
88: }
89: }
90: