Public Member Functions | |
load ($printQuery=false, $logQuery=false) | |
setJoinFlag ($table) | |
getJoinFlag ($table) | |
unsetJoinFlag ($table=null) | |
limit ($limit) | |
addPopularity ($limit=null) | |
addSummary ($storeId) | |
addStoresVisibility () | |
addFieldToFilter ($field, $condition=null) | |
getSelectCountSql () | |
addStoreFilter ($storeId, $allFilter=true) | |
setActiveFilter () | |
addStatusFilter ($status) | |
addProductFilter ($productId) | |
addCustomerFilter ($customerId) | |
addTagGroup () | |
joinRel () | |
Public Attributes | |
$_map | |
Protected Member Functions | |
_construct () | |
_addStoresVisibility () | |
Protected Attributes | |
$_isStoreFilter = false | |
$_joinFlags = array() |
Definition at line 35 of file Collection.php.
_addStoresVisibility | ( | ) | [protected] |
Definition at line 136 of file Collection.php.
00137 { 00138 $tagIds = $this->getColumnValues('tag_id'); 00139 00140 $tagsStores = array(); 00141 if (sizeof($tagIds)>0) { 00142 $select = $this->getConnection()->select() 00143 ->from($this->getTable('summary'), array('store_id', 'tag_id')) 00144 ->where('tag_id IN(?)', $tagIds); 00145 $tagsRaw = $this->getConnection()->fetchAll($select); 00146 foreach ($tagsRaw as $tag) { 00147 if (!isset($tagsStores[$tag['tag_id']])) { 00148 $tagsStores[$tag['tag_id']] = array(); 00149 } 00150 00151 $tagsStores[$tag['tag_id']][] = $tag['store_id']; 00152 } 00153 } 00154 00155 foreach ($this as $item) { 00156 if(isset($tagsStores[$item->getId()])) { 00157 $item->setStores($tagsStores[$item->getId()]); 00158 } else { 00159 $item->setStores(array()); 00160 } 00161 } 00162 00163 return $this; 00164 }
_construct | ( | ) | [protected] |
Initialization here
Reimplemented from Mage_Core_Model_Mysql4_Collection_Abstract.
Definition at line 46 of file Collection.php.
00047 { 00048 $this->_init('tag/tag'); 00049 }
addCustomerFilter | ( | $ | customerId | ) |
Definition at line 252 of file Collection.php.
00253 { 00254 $this->getSelect() 00255 ->where('relation.customer_id = ?', $customerId); 00256 if($this->getJoinFlag('prelation')) { 00257 $this->getSelect() 00258 ->where('prelation.customer_id = ?', $customerId); 00259 } 00260 return $this; 00261 }
addFieldToFilter | ( | $ | field, | |
$ | condition = null | |||
) |
Add field filter to collection
If $attribute is an array will add OR condition with following format: array( array('attribute'=>'firstname', 'like'=>'test'), array('attribute'=>'lastname', 'like'=>'test'), )
string|array | $attribute | |
null|string|array | $condition |
Reimplemented from Varien_Data_Collection_Db.
Definition at line 166 of file Collection.php.
00167 { 00168 if ($this->getJoinFlag('relation') && 'popularity' == $field) { 00169 // TOFIX 00170 $this->getSelect()->having($this->_getConditionSql('count(relation.tag_relation_id)', $condition)); 00171 } elseif ($this->getJoinFlag('summary') && in_array($field, array('customers', 'products', 'uses', 'historical_uses', 'popularity'))) { 00172 $this->getSelect()->where($this->_getConditionSql('summary.'.$field, $condition)); 00173 } else { 00174 parent::addFieldToFilter($field, $condition); 00175 } 00176 return $this; 00177 }
addPopularity | ( | $ | limit = null |
) |
Definition at line 93 of file Collection.php.
00094 { 00095 $this->getSelect() 00096 ->joinLeft( 00097 array('prelation'=>$this->getTable('tag/relation')), 00098 'main_table.tag_id=prelation.tag_id', 00099 array('popularity' => 'COUNT(DISTINCT relation.tag_relation_id)' 00100 )) 00101 ->group('main_table.tag_id'); 00102 $this->joinRel(); 00103 if (! is_null($limit)) { 00104 $this->getSelect()->limit($limit); 00105 } 00106 $this->setJoinFlag('prelation'); 00107 return $this; 00108 }
addProductFilter | ( | $ | productId | ) |
Definition at line 243 of file Collection.php.
00244 { 00245 $this->addFieldToFilter('relation.product_id', $productId); 00246 if($this->getJoinFlag('prelation')) { 00247 $this->addFieldToFilter('prelation.product_id', $productId); 00248 } 00249 return $this; 00250 }
addStatusFilter | ( | $ | status | ) |
Definition at line 237 of file Collection.php.
00238 { 00239 $this->addFieldToFilter('main_table.status', $status); 00240 return $this; 00241 }
addStoreFilter | ( | $ | storeId, | |
$ | allFilter = true | |||
) |
Definition at line 200 of file Collection.php.
00201 { 00202 if ($this->_isStoreFilter) { 00203 return $this; 00204 } 00205 if (!is_array($storeId)) { 00206 $storeId = array($storeId); 00207 } 00208 $this->getSelect()->join(array( 00209 'summary_store'=>$this->getTable('summary')), 00210 'main_table.tag_id = summary_store.tag_id 00211 AND summary_store.store_id IN (' . implode(',', $storeId) . ')', 00212 array()); 00213 00214 $this->getSelect()->group('summary_store.tag_id'); 00215 00216 if($this->getJoinFlag('relation') && $allFilter) { 00217 $this->getSelect()->where('relation.store_id IN (' . implode(',', $storeId) . ')'); 00218 } 00219 00220 if($this->getJoinFlag('prelation') && $allFilter) { 00221 $this->getSelect()->where('prelation.store_id IN (' . implode(',', $storeId) . ')'); 00222 } 00223 $this->_isStoreFilter = true; 00224 00225 return $this; 00226 }
addStoresVisibility | ( | ) |
Definition at line 130 of file Collection.php.
00131 { 00132 $this->setJoinFlag('add_stores_after'); 00133 return $this; 00134 }
addSummary | ( | $ | storeId | ) |
Definition at line 110 of file Collection.php.
00111 { 00112 $joinCondition = ''; 00113 if (is_array($storeId)) { 00114 $joinCondition = ' AND summary.store_id IN (' . implode(',', $storeId) . ')'; 00115 } else { 00116 $joinCondition = $this->getConnection()->quoteInto(' AND summary.store_id = ?', (int)$storeId); 00117 } 00118 00119 $this->getSelect() 00120 ->joinLeft( 00121 array('summary'=>$this->getTable('tag/summary')), 00122 'main_table.tag_id=summary.tag_id' . $joinCondition, 00123 array('store_id','popularity', 'customers', 'products', 'uses', 'historical_uses' 00124 )); 00125 00126 $this->setJoinFlag('summary'); 00127 return $this; 00128 }
addTagGroup | ( | ) |
Definition at line 264 of file Collection.php.
00265 { 00266 $this->getSelect()->group('main_table.tag_id'); 00267 return $this; 00268 }
getJoinFlag | ( | $ | table | ) |
Definition at line 69 of file Collection.php.
00070 { 00071 return isset($this->_joinFlags[$table]); 00072 }
getSelectCountSql | ( | ) |
Get sql for get record count
Reimplemented from Varien_Data_Collection_Db.
Definition at line 185 of file Collection.php.
00186 { 00187 $this->_renderFilters(); 00188 $countSelect = clone $this->_select; 00189 $countSelect->reset(Zend_Db_Select::ORDER); 00190 $countSelect->reset(Zend_Db_Select::GROUP); 00191 $countSelect->reset(Zend_Db_Select::LIMIT_COUNT); 00192 $countSelect->reset(Zend_Db_Select::LIMIT_OFFSET); 00193 00194 $sql = $countSelect->__toString(); 00195 // TOFIX 00196 $sql = preg_replace('/^select\s+.+?\s+from\s+/is', 'select COUNT(DISTINCT main_table.tag_id) from ', $sql); 00197 return $sql; 00198 }
joinRel | ( | ) |
Definition at line 271 of file Collection.php.
00272 { 00273 $this->setJoinFlag('relation'); 00274 $this->getSelect()->joinLeft(array('relation'=>$this->getTable('tag/relation')), 'main_table.tag_id=relation.tag_id'); 00275 return $this; 00276 }
limit | ( | $ | limit | ) |
Definition at line 86 of file Collection.php.
00087 { 00088 $this->getSelect()->limit($limit); 00089 return $this; 00090 }
load | ( | $ | printQuery = false , |
|
$ | logQuery = false | |||
) |
Load data
Reimplemented from Mage_Core_Model_Mysql4_Collection_Abstract.
Definition at line 51 of file Collection.php.
00052 { 00053 if ($this->isLoaded()) { 00054 return $this; 00055 } 00056 parent::load($printQuery, $logQuery); 00057 if ($this->getJoinFlag('add_stores_after')) { 00058 $this->_addStoresVisibility(); 00059 } 00060 return $this; 00061 }
setActiveFilter | ( | ) |
Definition at line 228 of file Collection.php.
00229 { 00230 $this->getSelect()->where('relation.active = 1'); 00231 if($this->getJoinFlag('prelation')) { 00232 $this->getSelect()->where('prelation.active = 1'); 00233 } 00234 return $this; 00235 }
setJoinFlag | ( | $ | table | ) |
Definition at line 63 of file Collection.php.
00064 { 00065 $this->_joinFlags[$table] = true; 00066 return $this; 00067 }
unsetJoinFlag | ( | $ | table = null |
) |
Definition at line 74 of file Collection.php.
00075 { 00076 if (is_null($table)) { 00077 $this->_joinFlags = array(); 00078 } elseif ($this->getJoinFlag($table)) { 00079 unset($this->_joinFlags[$table]); 00080 } 00081 00082 return $this; 00083 }
$_isStoreFilter = false [protected] |
Definition at line 37 of file Collection.php.
$_joinFlags = array() [protected] |
Definition at line 38 of file Collection.php.
$_map |
Initial value:
Reimplemented from Varien_Data_Collection_Db.
Definition at line 40 of file Collection.php.