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_Rating_Model_Resource_Rating_Option_Vote_Collection extends Mage_Core_Model_Resource_Db_Collection_Abstract
35: {
36: 37: 38: 39:
40: protected function _construct()
41: {
42: $this->_init('rating/rating_option_vote');
43: }
44:
45: 46: 47: 48: 49: 50:
51: public function setReviewFilter($reviewId)
52: {
53: $this->getSelect()
54: ->where("main_table.review_id = ?", $reviewId);
55: return $this;
56: }
57:
58: 59: 60: 61: 62: 63:
64: public function setEntityPkFilter($entityId)
65: {
66: $this->getSelect()
67: ->where("entity_pk_value = ?", $entityId);
68: return $this;
69: }
70:
71: 72: 73: 74: 75: 76:
77: public function setStoreFilter($storeId)
78: {
79: $this->getSelect()
80: ->join(array('rstore'=>$this->getTable('review/review_store')),
81: $this->getConnection()->quoteInto(
82: 'main_table.review_id=rstore.review_id AND rstore.store_id=?',
83: (int)$storeId),
84: array());
85: return $this;
86: }
87:
88: 89: 90: 91: 92: 93:
94: public function addRatingInfo($storeId=null)
95: {
96: $adapter=$this->getConnection();
97: $ratingCodeCond = $adapter->getIfNullSql('title.value', 'rating.rating_code');
98: $this->getSelect()
99: ->join(
100: array('rating' => $this->getTable('rating/rating')),
101: 'rating.rating_id = main_table.rating_id',
102: array('rating_code'))
103: ->joinLeft(
104: array('title' => $this->getTable('rating/rating_title')),
105: $adapter->quoteInto('main_table.rating_id=title.rating_id AND title.store_id = ?',
106: (int)Mage::app()->getStore()->getId()),
107: array('rating_code' => $ratingCodeCond));
108:
109: if ($storeId == null) {
110: $storeId = Mage::app()->getStore()->getId();
111: }
112:
113: if (is_array($storeId)) {
114: $condition = $adapter->prepareSqlCondition('store.store_id', array(
115: 'in' => $storeId
116: ));
117: } else {
118: $condition = $adapter->quoteInto('store.store_id = ?', $storeId);
119: }
120:
121: $this->getSelect()
122: ->join(
123: array('store' => $this->getTable('rating_store')),
124: 'main_table.rating_id = store.rating_id AND ' . $condition)
125:
126: ;
127:
128: $adapter->fetchAll($this->getSelect());
129: return $this;
130: }
131:
132: 133: 134: 135: 136:
137: public function addOptionInfo()
138: {
139: $this->getSelect()
140: ->join(array('rating_option' => $this->getTable('rating/rating_option')),
141: 'main_table.option_id = rating_option.option_id');
142: return $this;
143: }
144:
145: 146: 147: 148: 149:
150: public function addRatingOptions()
151: {
152: if (!$this->getSize()) {
153: return $this;
154: }
155: foreach ($this->getItems() as $item) {
156: $options = Mage::getModel('rating/rating_option')
157: ->getResourceCollection()
158: ->addRatingFilter($item->getRatingId())
159: ->load();
160:
161: if ($item->getRatingId()) {
162: $item->setRatingOptions($options);
163: } else {
164: return;
165: }
166: }
167: return $this;
168: }
169: }
170: