00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035 class Mage_Rating_Model_Mysql4_Rating_Option_Vote_Collection extends Mage_Core_Model_Mysql4_Collection_Abstract
00036 {
00037 public function _construct()
00038 {
00039 $this->_init('rating/rating_option_vote');
00040 }
00041
00042 public function setReviewFilter($reviewId)
00043 {
00044 $this->_select->where("main_table.review_id = ?", $reviewId);
00045 return $this;
00046 }
00047
00048 public function setEntityPkFilter($entityId)
00049 {
00050 $this->_select->where("entity_pk_value = ?", $entityId);
00051 return $this;
00052 }
00053
00054 public function setStoreFilter($storeId)
00055 {
00056 $this->_select->join(array('rstore'=>$this->getTable('review/review_store')), 'main_table.review_id=rstore.review_id AND rstore.store_id=' . (int)$storeId, array());
00057 return $this;
00058 }
00059
00060 public function addRatingInfo($storeId=null)
00061 {
00062 $this->_select->join($this->getTable('rating/rating'), "{$this->getTable('rating/rating')}.rating_id = main_table.rating_id", "{$this->getTable('rating/rating')}.*")
00063 ->joinLeft(array('title'=>$this->getTable('rating/rating_title')),
00064 "main_table.rating_id=title.rating_id AND title.store_id = ". (int) Mage::app()->getStore()->getId(),
00065 array("IF(title.value IS NULL, {$this->getTable('rating/rating')}.rating_code, title.value) AS rating_code"));
00066
00067 if($storeId == null) {
00068 $storeId = Mage::app()->getStore()->getId();
00069 }
00070
00071 if(is_array($storeId)) {
00072 $condition = $this->getConnection()->quoteInto('store.store_id IN(?)', $storeId);
00073 } else {
00074 $condition = $this->getConnection()->quoteInto('store.store_id = ?', $storeId);
00075 }
00076
00077 $this->_select->join(array('store'=>$this->getTable('rating_store')), 'main_table.rating_id = store.rating_id AND '. $condition);
00078 $this->_select->group('main_table.vote_id');
00079
00080 return $this;
00081 }
00082
00083 public function addOptionInfo()
00084 {
00085 $this->_select->join($this->getTable('rating/rating_option'), "main_table.option_id = {$this->getTable('rating/rating_option')}.option_id", "{$this->getTable('rating/rating_option')}.*");
00086 return $this;
00087 }
00088
00089 public function addRatingOptions()
00090 {
00091 if( !$this->getSize() ) {
00092 return $this;
00093 }
00094 foreach( $this->getItems() as $item ) {
00095 $options = Mage::getModel('rating/rating_option')
00096 ->getResourceCollection()
00097 ->addRatingFilter($item->getRatingId())
00098 ->load();
00099
00100 if( $item->getRatingId() ) {
00101 $item->setRatingOptions($options);
00102 } else {
00103 return;
00104 }
00105 }
00106 return $this;
00107 }
00108 }