Public Member Functions | |
setJoinFlag ($table) | |
getJoinFlag ($table) | |
unsetJoinFlag ($table=null) | |
addStoresVisibility () | |
addGroupByTag () | |
addCustomerFilter ($customerId) | |
addTagFilter ($tagId) | |
addStatusFilter ($status) | |
setDescOrder ($dir= 'DESC') | |
addPopularity ($tagId, $storeId=null) | |
addPopularityFilter ($condition) | |
setActiveFilter () | |
addProductTags ($storeId=null) | |
getSelectCountSql () | |
setOrder ($attribute, $dir='desc') | |
setRelationId () | |
Protected Member Functions | |
_initSelect () | |
_addStoresVisibility () | |
_joinFields () | |
_afterLoad () | |
Protected Attributes | |
$_customerFilterId | |
$_tagIdFilter | |
$_joinFlags = array() |
Definition at line 35 of file Collection.php.
_addStoresVisibility | ( | ) | [protected] |
Add tag visibility on stores process
Definition at line 130 of file Collection.php.
00131 { 00132 $tagIds = array(); 00133 foreach ($this as $item) { 00134 $tagIds[] = $item->getTagId(); 00135 } 00136 00137 $tagsStores = array(); 00138 if (sizeof($tagIds) > 0) { 00139 $select = $this->getConnection()->select() 00140 ->from($this->getTable('tag/summary'), array('store_id', 'tag_id')) 00141 ->where('tag_id IN(?)', $tagIds); 00142 $tagsRaw = $this->getConnection()->fetchAll($select); 00143 foreach ($tagsRaw as $tag) { 00144 if (!isset($tagsStores[$tag['tag_id']])) { 00145 $tagsStores[$tag['tag_id']] = array(); 00146 } 00147 00148 $tagsStores[$tag['tag_id']][] = $tag['store_id']; 00149 } 00150 } 00151 00152 foreach ($this as $item) { 00153 if (isset($tagsStores[$item->getTagId()])) { 00154 $item->setStores($tagsStores[$item->getTagId()]); 00155 } 00156 else { 00157 $item->setStores(array()); 00158 } 00159 } 00160 00161 return $this; 00162 }
_afterLoad | ( | ) | [protected] |
After load adding data
Reimplemented from Mage_Catalog_Model_Resource_Eav_Mysql4_Product_Collection.
Definition at line 360 of file Collection.php.
00361 { 00362 parent::_afterLoad(); 00363 00364 if ($this->getJoinFlag('add_stores_after')) { 00365 $this->_addStoresVisibility(); 00366 } 00367 00368 if (count($this) > 0) { 00369 Mage::dispatchEvent('tag_tag_product_collection_load_after', array( 00370 'collection' => $this 00371 )); 00372 } 00373 00374 return $this; 00375 }
_initSelect | ( | ) | [protected] |
Initialize collection select
Reimplemented from Mage_Catalog_Model_Resource_Eav_Mysql4_Product_Collection.
Definition at line 63 of file Collection.php.
00064 { 00065 parent::_initSelect(); 00066 00067 $this->_joinFields(); 00068 $this->getSelect()->group('e.entity_id'); 00069 00070 return $this; 00071 }
_joinFields | ( | ) | [protected] |
Join fields process
Reimplemented in Mage_Reports_Model_Mysql4_Tag_Product_Collection.
Definition at line 337 of file Collection.php.
00338 { 00339 $tagTable = $this->getTable('tag/tag'); 00340 $tagRelationTable = $this->getTable('tag/relation'); 00341 00342 $this->addAttributeToSelect('name') 00343 ->addAttributeToSelect('price') 00344 ->addAttributeToSelect('small_image'); 00345 00346 $this->getSelect() 00347 ->join(array('relation' => $tagRelationTable), 'relation.product_id = e.entity_id') 00348 ->join(array('t' => $tagTable), 00349 't.tag_id = relation.tag_id', 00350 array('tag_id', 'name', 'tag_status' => 'status', 'tag_name' => 'name') 00351 ); 00352 return $this; 00353 }
addCustomerFilter | ( | $ | customerId | ) |
Set Customer filter
int | $customerId |
Definition at line 181 of file Collection.php.
00182 { 00183 $this->getSelect() 00184 ->where('relation.customer_id = ?', $customerId); 00185 $this->_customerFilterId = $customerId; 00186 return $this; 00187 }
addGroupByTag | ( | ) |
Add group by tag
Reimplemented in Mage_Reports_Model_Mysql4_Tag_Product_Collection.
Definition at line 169 of file Collection.php.
00170 { 00171 $this->getSelect()->group('relation.tag_relation_id'); 00172 return $this; 00173 }
addPopularity | ( | $ | tagId, | |
$ | storeId = null | |||
) |
Add Popularity
int | $tagId | |
int | $storeId |
Definition at line 233 of file Collection.php.
00234 { 00235 $tagRelationTable = $this->getTable('tag/relation'); 00236 00237 $condition = array( 00238 'prelation.product_id=e.entity_id' 00239 ); 00240 if (!is_null($storeId)) { 00241 $condition[] = $this->getConnection() 00242 ->quoteInto('prelation.store_id=?', $storeId); 00243 } 00244 $condition = join(' AND ', $condition); 00245 00246 $this->getSelect() 00247 ->joinLeft( 00248 array('prelation' => $tagRelationTable), 00249 $condition, 00250 array('popularity' => 'COUNT(DISTINCT prelation.tag_relation_id)')) 00251 ->where('prelation.tag_id = ?', $tagId); 00252 00253 $this->_tagIdFilter = $tagId; 00254 $this->setJoinFlag('prelation'); 00255 return $this; 00256 }
addPopularityFilter | ( | $ | condition | ) |
Add Popularity Filter
mixed | $condition |
Definition at line 264 of file Collection.php.
00265 { 00266 $tagRelationTable = Mage::getSingleton('core/resource') 00267 ->getTableName('tag/relation'); 00268 00269 $select = $this->getConnection()->select() 00270 ->from($tagRelationTable, array('product_id', 'popularity' => 'COUNT(DISTINCT tag_relation_id)')) 00271 ->where('tag_id = ?', $this->_tagIdFilter) 00272 ->group('product_id') 00273 ->having($this->_getConditionSql('popularity', $condition)); 00274 00275 $prodIds = array(); 00276 foreach ($this->getConnection()->fetchAll($select) as $item) { 00277 $prodIds[] = $item['product_id']; 00278 } 00279 00280 if (sizeof($prodIds) > 0) { 00281 $this->getSelect()->where('e.entity_id IN(?)', $prodIds); 00282 } 00283 else { 00284 $this->getSelect()->where('e.entity_id IN(0)'); 00285 } 00286 00287 return $this; 00288 }
addProductTags | ( | $ | storeId = null |
) |
Add Product Tags
int | $storeId |
Definition at line 311 of file Collection.php.
00312 { 00313 foreach ($this->getItems() as $item) { 00314 $tagsCollection = Mage::getModel('tag/tag')->getResourceCollection(); 00315 00316 if (!is_null($storeId)) { 00317 $tagsCollection->addStoreFilter($storeId); 00318 } 00319 00320 $tagsCollection->addPopularity() 00321 ->addProductFilter($item->getEntityId()) 00322 ->addCustomerFilter($this->_customerFilterId) 00323 ->setActiveFilter(); 00324 00325 $tagsCollection->load(); 00326 $item->setProductTags($tagsCollection); 00327 } 00328 00329 return $this; 00330 }
addStatusFilter | ( | $ | status | ) |
Add tag status filter
int | $status |
Definition at line 208 of file Collection.php.
00209 { 00210 $this->getSelect()->where('t.status = ?', $status); 00211 return $this; 00212 }
addStoresVisibility | ( | ) |
Add tag visibility on stores
Definition at line 119 of file Collection.php.
00120 { 00121 $this->setJoinFlag('add_stores_after'); 00122 return $this; 00123 }
addTagFilter | ( | $ | tagId | ) |
Set tag filter
int | $tagId |
Definition at line 195 of file Collection.php.
00196 { 00197 $this->getSelect()->where('relation.tag_id = ?', $tagId); 00198 $this->setJoinFlag('distinct'); 00199 return $this; 00200 }
getJoinFlag | ( | $ | table | ) |
Retrieve join flag
string | $table |
Definition at line 91 of file Collection.php.
00092 { 00093 return isset($this->_joinFlags[$table]); 00094 }
getSelectCountSql | ( | ) |
Render SQL for retrieve product count
Reimplemented from Mage_Catalog_Model_Resource_Eav_Mysql4_Product_Collection.
Definition at line 382 of file Collection.php.
00383 { 00384 $countSelect = clone $this->getSelect(); 00385 00386 $countSelect->reset(Zend_Db_Select::COLUMNS); 00387 $countSelect->reset(Zend_Db_Select::ORDER); 00388 $countSelect->reset(Zend_Db_Select::LIMIT_COUNT); 00389 $countSelect->reset(Zend_Db_Select::LIMIT_OFFSET); 00390 $countSelect->reset(Zend_Db_Select::GROUP); 00391 00392 if ($this->getJoinFlag('group_tag')) { 00393 $field = 'relation.tag_id'; 00394 } 00395 else { 00396 $field = 'e.entity_id'; 00397 } 00398 $expr = new Zend_Db_Expr('COUNT(' 00399 . ($this->getJoinFlag('distinct') ? 'DISTINCT ' : '') 00400 . $field . ')'); 00401 00402 $countSelect->from(null, $expr); 00403 00404 return $countSelect; 00405 }
setActiveFilter | ( | ) |
Set tag active filter to collection
Definition at line 295 of file Collection.php.
00296 { 00297 $active = Mage_Tag_Model_Tag_Relation::STATUS_ACTIVE; 00298 $this->getSelect()->where('relation.active=?', $active); 00299 if ($this->getJoinFlag('prelation')) { 00300 $this->getSelect()->where('prelation.active=?', $active); 00301 } 00302 return $this; 00303 }
setDescOrder | ( | $ | dir = 'DESC' |
) |
Set DESC order to collection
string | $dir |
Definition at line 220 of file Collection.php.
00221 { 00222 $this->setOrder('relation.tag_relation_id', $dir); 00223 return $this; 00224 }
setJoinFlag | ( | $ | table | ) |
Set join flag
string | $table |
Definition at line 79 of file Collection.php.
00080 { 00081 $this->_joinFlags[$table] = true; 00082 return $this; 00083 }
setOrder | ( | $ | attribute, | |
$ | dir = 'desc' | |||
) |
Set attribute order
string | $attribute | |
string | $dir |
Reimplemented from Mage_Eav_Model_Entity_Collection_Abstract.
Reimplemented in Mage_Reports_Model_Mysql4_Tag_Product_Collection.
Definition at line 414 of file Collection.php.
00415 { 00416 if ($attribute == 'popularity') { 00417 $this->getSelect()->order($attribute . ' ' . $dir); 00418 } 00419 else { 00420 parent::setOrder($attribute, $dir); 00421 } 00422 return $this; 00423 }
setRelationId | ( | ) |
Set Id Fieldname as Tag Relation Id
Definition at line 430 of file Collection.php.
00431 { 00432 $this->_setIdFieldName('tag_relation_id'); 00433 return $this; 00434 }
unsetJoinFlag | ( | $ | table = null |
) |
Unset join flag
string | $table |
Definition at line 102 of file Collection.php.
00103 { 00104 if (is_null($table)) { 00105 $this->_joinFlags = array(); 00106 } 00107 elseif ($this->getJoinFlag($table)) { 00108 unset($this->_joinFlags[$table]); 00109 } 00110 00111 return $this; 00112 }
$_customerFilterId [protected] |
Definition at line 42 of file Collection.php.
$_joinFlags = array() [protected] |
Definition at line 56 of file Collection.php.
$_tagIdFilter [protected] |
Definition at line 49 of file Collection.php.