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:
35: class Mage_Adminhtml_Block_Review_Rating_Detailed extends Mage_Adminhtml_Block_Template
36: {
37: protected $_voteCollection = false;
38: public function __construct()
39: {
40: parent::__construct();
41: $this->setTemplate('rating/detailed.phtml');
42: if( Mage::registry('review_data') ) {
43: $this->setReviewId(Mage::registry('review_data')->getReviewId());
44: }
45: }
46:
47: public function getRating()
48: {
49: if( !$this->getRatingCollection() ) {
50: if( Mage::registry('review_data') ) {
51: $stores = Mage::registry('review_data')->getStores();
52:
53: $stores = array_diff($stores, array(0));
54:
55: $ratingCollection = Mage::getModel('rating/rating')
56: ->getResourceCollection()
57: ->addEntityFilter('product')
58: ->setStoreFilter($stores)
59: ->setPositionOrder()
60: ->load()
61: ->addOptionToItems();
62:
63: $this->_voteCollection = Mage::getModel('rating/rating_option_vote')
64: ->getResourceCollection()
65: ->setReviewFilter($this->getReviewId())
66: ->addOptionInfo()
67: ->load()
68: ->addRatingOptions();
69:
70: } elseif (!$this->getIsIndependentMode()) {
71: $ratingCollection = Mage::getModel('rating/rating')
72: ->getResourceCollection()
73: ->addEntityFilter('product')
74: ->setStoreFilter(null)
75: ->setPositionOrder()
76: ->load()
77: ->addOptionToItems();
78: } else {
79: $ratingCollection = Mage::getModel('rating/rating')
80: ->getResourceCollection()
81: ->addEntityFilter('product')
82: ->setStoreFilter($this->getRequest()->getParam('select_stores') ? $this->getRequest()->getParam('select_stores') : $this->getRequest()->getParam('stores'))
83: ->setPositionOrder()
84: ->load()
85: ->addOptionToItems();
86: if(intval($this->getRequest()->getParam('id'))){
87: $this->_voteCollection = Mage::getModel('rating/rating_option_vote')
88: ->getResourceCollection()
89: ->setReviewFilter(intval($this->getRequest()->getParam('id')))
90: ->addOptionInfo()
91: ->load()
92: ->addRatingOptions();
93: }
94: }
95: $this->setRatingCollection( ( $ratingCollection->getSize() ) ? $ratingCollection : false );
96: }
97: return $this->getRatingCollection();
98: }
99:
100: public function setIndependentMode()
101: {
102: $this->setIsIndependentMode(true);
103: return $this;
104: }
105:
106: public function isSelected($option, $rating)
107: {
108: if($this->getIsIndependentMode()) {
109: $ratings = $this->getRequest()->getParam('ratings');
110:
111: if(isset($ratings[$option->getRatingId()])) {
112: return $option->getId() == $ratings[$option->getRatingId()];
113: }elseif(!$this->_voteCollection) {
114: return false;
115: }
116: }
117:
118: if($this->_voteCollection) {
119: foreach($this->_voteCollection as $vote) {
120: if($option->getId() == $vote->getOptionId()) {
121: return true;
122: }
123: }
124: }
125:
126: return false;
127: }
128: }
129: