Mage_Review_Model_Mysql4_Review_Product_Collection Class Reference

Inheritance diagram for Mage_Review_Model_Mysql4_Review_Product_Collection:

Mage_Catalog_Model_Resource_Eav_Mysql4_Product_Collection Mage_Catalog_Model_Resource_Eav_Mysql4_Collection_Abstract Mage_Eav_Model_Entity_Collection_Abstract Varien_Data_Collection_Db Varien_Data_Collection

List of all members.

Public Member Functions

 addStoreFilter ($storeId=null)
 setStoreFilter ($storeId)
 addStoreData ()
 addCustomerFilter ($customerId)
 addEntityFilter ($entityId)
 addStatusFilter ($status)
 setDateOrder ($dir='DESC')
 addReviewSummary ()
 addRateVotes ()
 getAllIds ($limit=null, $offset=null)
 getSelectCountSql ()
 setOrder ($attribute, $dir='desc')
 addAttributeToFilter ($attribute, $condition=null, $joinType='inner')
 getColumnValues ($colName)

Protected Member Functions

 _construct ()
 _initSelect ()
 _joinFields ()
 _afterLoad ()
 _addStoreData ()

Protected Attributes

 $_entitiesAlias = array()
 $_reviewStoreTable
 $_addStoreDataFlag = false


Detailed Description

Definition at line 35 of file Collection.php.


Member Function Documentation

_addStoreData (  )  [protected]

Definition at line 272 of file Collection.php.

00273     {
00274         $reviewsIds = $this->getColumnValues('review_id');
00275         $storesToReviews = array();
00276         if (count($reviewsIds)>0) {
00277             $select = $this->getConnection()->select()
00278                 ->from($this->_reviewStoreTable)
00279                 ->where('review_id IN(?)', $reviewsIds)
00280                 ->where('store_id > ?', 0);
00281             $result = $this->getConnection()->fetchAll($select);
00282             foreach ($result as $row) {
00283                 if (!isset($storesToReviews[$row['review_id']])) {
00284                     $storesToReviews[$row['review_id']] = array();
00285                 }
00286                 $storesToReviews[$row['review_id']][] = $row['store_id'];
00287             }
00288         }
00289 
00290         foreach ($this as $item) {
00291             if(isset($storesToReviews[$item->getReviewId()])) {
00292                 $item->setData('stores',$storesToReviews[$item->getReviewId()]);
00293             } else {
00294                 $item->setData('stores', array());
00295             }
00296 
00297         }
00298     }

_afterLoad (  )  [protected]

Processing collection items after loading Adding url rewrites, minimal prices, final prices, tax percents

Returns:
Mage_Catalog_Model_Resource_Eav_Mysql4_Product_Collection

Reimplemented from Mage_Catalog_Model_Resource_Eav_Mysql4_Product_Collection.

Definition at line 263 of file Collection.php.

00264     {
00265         parent::_afterLoad();
00266         if ($this->_addStoreDataFlag) {
00267             $this->_addStoreData();
00268         }
00269         return $this;
00270     }

_construct (  )  [protected]

Initialize resources

Reimplemented from Mage_Catalog_Model_Resource_Eav_Mysql4_Product_Collection.

Definition at line 41 of file Collection.php.

00042     {
00043         $this->_init('catalog/product');
00044         $this->setRowIdFieldName('review_id');
00045         $this->_reviewStoreTable = Mage::getSingleton('core/resource')->getTableName('review/review_store');
00046     }

_initSelect (  )  [protected]

Initialize collection select Redeclared for remove entity_type_id condition in catalog_product_entity we store just products

Returns:
Mage_Catalog_Model_Resource_Eav_Mysql4_Product_Collection

Reimplemented from Mage_Catalog_Model_Resource_Eav_Mysql4_Product_Collection.

Definition at line 48 of file Collection.php.

00049     {
00050         parent::_initSelect();
00051         $this->_joinFields();
00052         return $this;
00053     }

_joinFields (  )  [protected]

Definition at line 146 of file Collection.php.

00147     {
00148         $reviewTable = Mage::getSingleton('core/resource')->getTableName('review/review');
00149         $reviewDetailTable = Mage::getSingleton('core/resource')->getTableName('review/review_detail');
00150 
00151         $this->addAttributeToSelect('name')
00152             ->addAttributeToSelect('sku');
00153 
00154         $this->getSelect()
00155             ->join(array('rt' => $reviewTable),
00156                 'rt.entity_pk_value = e.entity_id',
00157                 array('review_id', 'created_at', 'entity_pk_value', 'status_id'))
00158             ->join(array('rdt' => $reviewDetailTable), 'rdt.review_id = rt.review_id');
00159         return $this;
00160     }

addAttributeToFilter ( attribute,
condition = null,
joinType = 'inner' 
)

Add attribute to filter

Parameters:
Mage_Eav_Model_Entity_Attribute_Abstract|string $attribute
array $condition
string $joinType
Returns:
Mage_Catalog_Model_Resource_Eav_Mysql4_Product_Collection

Reimplemented from Mage_Catalog_Model_Resource_Eav_Mysql4_Product_Collection.

Definition at line 220 of file Collection.php.

00221     {
00222         switch( $attribute ) {
00223             case 'rt.review_id':
00224             case 'rt.created_at':
00225             case 'rt.status_id':
00226             case 'rdt.title':
00227             case 'rdt.nickname':
00228             case 'rdt.detail':
00229                 $conditionSql = $this->_getConditionSql($attribute, $condition);
00230                 $this->getSelect()->where($conditionSql);
00231                 return $this;
00232                 break;
00233            case 'stores':
00234                 $this->setStoreFilter($condition);
00235                 return $this;
00236                 break;
00237             case 'type':
00238                 if($condition == 1) {
00239                     $this->getSelect()->where('rdt.customer_id = 0');
00240                 } elseif ($condition == 2) {
00241                     $this->getSelect()->where('rdt.customer_id > 0');
00242                 } else {
00243                     $this->getSelect()->where('rdt.customer_id IS NULL');
00244                 }
00245                 return $this;
00246                 break;
00247 
00248             default:
00249                 parent::addAttributeToFilter($attribute, $condition, $joinType);
00250         }
00251         return $this;
00252     }

addCustomerFilter ( customerId  ) 

Definition at line 96 of file Collection.php.

00097     {
00098         $this->getSelect()
00099             ->where('rdt.customer_id = ?', $customerId);
00100         return $this;
00101     }

addEntityFilter ( entityId  ) 

Definition at line 103 of file Collection.php.

00104     {
00105         $this->getSelect()
00106             ->where('rt.entity_pk_value = ?', $entityId);
00107         return $this;
00108     }

addRateVotes (  ) 

Definition at line 133 of file Collection.php.

00134     {
00135         foreach( $this->getItems() as $item ) {
00136             $votesCollection = Mage::getModel('rating/rating_option_vote')
00137                 ->getResourceCollection()
00138                 ->setEntityPkFilter($item->getEntityId())
00139                 ->setStoreFilter(Mage::app()->getStore()->getId())
00140                 ->load();
00141             $item->setRatingVotes( $votesCollection );
00142         }
00143         return $this;
00144     }

addReviewSummary (  ) 

Definition at line 123 of file Collection.php.

00124     {
00125         foreach( $this->getItems() as $item ) {
00126             $model = Mage::getModel('rating/rating');
00127             $model->getReviewSummary($item->getReviewId());
00128             $item->addData($model->getData());
00129         }
00130         return $this;
00131     }

addStatusFilter ( status  ) 

Definition at line 110 of file Collection.php.

00111     {
00112         $this->getSelect()
00113             ->where('rt.status_id = ?', $status);
00114         return $this;
00115     }

addStoreData (  ) 

Add stores data

Parameters:
int $storeId
Returns:
Varien_Data_Collection_Db

Definition at line 91 of file Collection.php.

00092     {
00093         $this->_addStoreDataFlag = true;
00094         return $this;
00095     }

addStoreFilter ( store = null  ) 

Add store availability filter. Include availability product for store website

Parameters:
mixed $store
Returns:
Mage_Catalog_Model_Resource_Eav_Mysql4_Product_Collection

Reimplemented from Mage_Catalog_Model_Resource_Eav_Mysql4_Product_Collection.

Definition at line 55 of file Collection.php.

00056     {
00057         parent::addStoreFilter($storeId);
00058         $this->getSelect()
00059             ->join(array('store'=>$this->_reviewStoreTable),
00060                 'rt.review_id=store.review_id AND store.store_id=' . (int)$storeId, array());
00061         return $this;
00062     }

getAllIds ( limit = null,
offset = null 
)

Retrive all ids for collection

Returns:
array

Reimplemented from Mage_Catalog_Model_Resource_Eav_Mysql4_Product_Collection.

Definition at line 167 of file Collection.php.

00168     {
00169         $idsSelect = clone $this->getSelect();
00170         $idsSelect->reset(Zend_Db_Select::ORDER);
00171         $idsSelect->reset(Zend_Db_Select::LIMIT_COUNT);
00172         $idsSelect->reset(Zend_Db_Select::LIMIT_OFFSET);
00173         $idsSelect->reset(Zend_Db_Select::COLUMNS);
00174         $idsSelect->from(null, 'rt.review_id');
00175         return $this->getConnection()->fetchCol($idsSelect);
00176     }

getColumnValues ( colName  ) 

Retrieve field values from all items

Parameters:
string $colName
Returns:
array

Reimplemented from Varien_Data_Collection.

Definition at line 254 of file Collection.php.

00255     {
00256         $col = array();
00257         foreach ($this->getItems() as $item) {
00258             $col[] = $item->getData($colName);
00259         }
00260         return $col;
00261     }

getSelectCountSql (  ) 

Render SQL for retrieve product count

Returns:
string

Reimplemented from Mage_Catalog_Model_Resource_Eav_Mysql4_Product_Collection.

Definition at line 184 of file Collection.php.

00185     {
00186         $countSelect = clone $this->getSelect();
00187         $countSelect->reset(Zend_Db_Select::ORDER);
00188         $countSelect->reset(Zend_Db_Select::LIMIT_COUNT);
00189         $countSelect->reset(Zend_Db_Select::LIMIT_OFFSET);
00190 
00191         $sql = $countSelect->__toString();
00192         $sql = preg_replace('/^select\s+.+?\s+from\s+/is', 'select count(e.entity_id) from ', $sql);
00193 
00194         return $sql;
00195     }

setDateOrder ( dir = 'DESC'  ) 

Definition at line 117 of file Collection.php.

00118     {
00119         $this->setOrder('rt.created_at', $dir);
00120         return $this;
00121     }

setOrder ( attribute,
dir = 'desc' 
)

Set sorting order

$attribute can also be an array of attributes

Parameters:
string|array $attribute
string $dir
Returns:
Mage_Eav_Model_Entity_Collection_Abstract

Reimplemented from Mage_Eav_Model_Entity_Collection_Abstract.

Definition at line 197 of file Collection.php.

00198     {
00199         switch( $attribute ) {
00200             case 'rt.review_id':
00201             case 'rt.created_at':
00202             case 'rt.status_id':
00203             case 'rdt.title':
00204             case 'rdt.nickname':
00205             case 'rdt.detail':
00206                 $this->getSelect()->order($attribute . ' ' . $dir);
00207                 break;
00208             case 'stores':
00209                 // No way to sort
00210                 break;
00211             case 'type':
00212                 $this->getSelect()->order('rdt.customer_id ' . $dir);
00213                 break;
00214             default:
00215                 parent::setOrder($attribute, $dir);
00216         }
00217         return $this;
00218     }

setStoreFilter ( storeId  ) 

Definition at line 64 of file Collection.php.

00065     {
00066         if( is_array($storeId) && isset($storeId['eq']) ) {
00067             $storeId = array_shift($storeId);
00068         }
00069 
00070         if( is_array($storeId) ) {
00071             $this->getSelect()
00072                 ->join(array('store'=>$this->_reviewStoreTable),
00073                     $this->getConnection()->quoteInto('rt.review_id=store.review_id AND store.store_id IN(?)', $storeId), array())
00074                 ->distinct(true)
00075                 ;
00076         } else {
00077             $this->getSelect()
00078                 ->join(array('store'=>$this->_reviewStoreTable),
00079                     'rt.review_id=store.review_id AND store.store_id=' . (int)$storeId, array());
00080         }
00081 
00082         return $this;
00083     }


Member Data Documentation

$_addStoreDataFlag = false [protected]

Definition at line 39 of file Collection.php.

$_entitiesAlias = array() [protected]

Definition at line 37 of file Collection.php.

$_reviewStoreTable [protected]

Definition at line 38 of file Collection.php.


The documentation for this class was generated from the following file:

Generated on Sat Jul 4 17:24:38 2009 for Magento by  doxygen 1.5.8