1: <?php
2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25:
26:
27: 28: 29: 30: 31: 32: 33:
34: class Mage_XmlConnect_Block_Review_Form extends Mage_Core_Block_Template
35: {
36: 37: 38: 39: 40:
41: protected $_ratings = null;
42:
43: 44: 45: 46: 47:
48: protected function _toHtml()
49: {
50: $customer = Mage::getSingleton('customer/session')->getCustomer();
51:
52: $xmlReview = Mage::getModel('xmlconnect/simplexml_element', '<form></form>');
53: $xmlReview->addAttribute('name', 'review_form');
54: $xmlReview->addAttribute('method', 'post');
55:
56: $nickname = '';
57: if ($customer->getId()) {
58: $nickname = $xmlReview->escapeXml($customer->getFirstname());
59: }
60:
61: if ($this->getRatings()) {
62: $ratingsFieldset = $xmlReview->addCustomChild('fieldset', null, array(
63: 'label' => $this->__('How do you rate this product?')
64: ));
65:
66: foreach ($this->getRatings() as $rating) {
67: $ratingField = $ratingsFieldset->addField('ratings[' . $rating->getId() . ']', 'radio', array(
68: 'label' => $rating->getRatingCode(),
69: 'required' => 'true'
70: ));
71: foreach ($rating->getOptions() as $option) {
72: $ratingField->addCustomChild('value', $option->getId());
73: }
74: }
75: }
76:
77: $reviewFieldset = $xmlReview->addCustomChild('fieldset');
78: $reviewFieldset->addField('nickname', 'text', array(
79: 'label' => $this->__('Nickname'),
80: 'required' => 'true',
81: 'value' => $nickname
82: ));
83: $reviewFieldset->addField('title', 'text', array(
84: 'label' => $this->__('Summary of Your Review'),
85: 'required' => 'true'
86: ));
87: $reviewFieldset->addField('detail', 'textarea', array(
88: 'label' => $this->__('Review'),
89: 'required' => 'true'
90: ));
91:
92: return $xmlReview->asNiceXml();
93: }
94:
95: 96: 97: 98: 99:
100: public function getRatings()
101: {
102: if (is_null($this->_ratings)) {
103: $this->_ratings = Mage::getModel('rating/rating')->getResourceCollection()->addEntityFilter('product')
104: ->setPositionOrder()->addRatingPerStoreName(Mage::app()->getStore()->getId())
105: ->setStoreFilter(Mage::app()->getStore()->getId())->load()->addOptionToItems();
106:
107: if (!$this->_ratings->getSize()) {
108: $this->_ratings = false;
109: }
110: }
111: return $this->_ratings;
112: }
113: }
114: