Public Member Functions | |
getCacheData ($key, $storeId) | |
saveCacheData ($data, $key, $tags, $storeId) | |
clearCacheData ($tags, $storeId) | |
getProductCategoryPaths ($productIds) | |
Protected Member Functions | |
_construct () | |
_saveTagRelations ($aggregationId, $tags) | |
_getTagIds ($tags) | |
_addTags ($tags) | |
Protected Attributes | |
$_tagTable | |
$_toTagTable |
Definition at line 27 of file Aggregation.php.
_addTags | ( | $ | tags | ) | [protected] |
Insert tags to tag table
string | | array $tags |
Definition at line 182 of file Aggregation.php.
00183 { 00184 if (is_array($tags)) { 00185 $tags = array_unique($tags); 00186 foreach ($tags as $index => $tag) { 00187 $tags[$index] = $this->_getWriteAdapter()->quote($tag); 00188 } 00189 $query = "INSERT INTO `{$this->_tagTable}` (tag_code) VALUES (".implode('),(', $tags).")"; 00190 $this->_getWriteAdapter()->query($query); 00191 } 00192 else { 00193 $this->_getWriteAdapter()->insert($this->_tagTable, array( 00194 'tag_code' => $tags 00195 )); 00196 } 00197 return $this; 00198 }
_construct | ( | ) | [protected] |
Initialize resource tables
Reimplemented from Mage_Core_Model_Resource_Abstract.
Definition at line 35 of file Aggregation.php.
00036 { 00037 $this->_init('catalogindex/aggregation', 'aggregation_id'); 00038 $this->_tagTable = $this->getTable('catalogindex/aggregation_tag'); 00039 $this->_toTagTable = $this->getTable('catalogindex/aggregation_to_tag'); 00040 }
_getTagIds | ( | $ | tags | ) | [protected] |
Get identifiers of tags if some tags not exist they will be added
array | $tags |
Detect new tags
Definition at line 150 of file Aggregation.php.
00151 { 00152 if (!is_array($tags)) { 00153 $tags = array($tags); 00154 } 00155 00156 $select = $this->_getReadAdapter()->select() 00157 ->from(array('tags'=>$this->_tagTable), array('tag_code', 'tag_id')) 00158 ->where('tags.tag_code IN (?)', $tags); 00159 00160 $tagIds = $this->_getReadAdapter()->fetchPairs($select); 00161 00162 /** 00163 * Detect new tags 00164 */ 00165 $newTags = array_diff($tags, array_keys($tagIds)); 00166 if (!empty($newTags)) { 00167 $this->_addTags($newTags); 00168 $select->reset(Zend_Db_Select::WHERE) 00169 ->where('tags.tag_code IN (?)', $newTags); 00170 $newTags = $this->_getReadAdapter()->fetchPairs($select); 00171 $tagIds = array_merge($tagIds, $newTags); 00172 } 00173 return $tagIds; 00174 }
_saveTagRelations | ( | $ | aggregationId, | |
$ | tags | |||
) | [protected] |
Save related tags for aggreagation data
int | $aggregationId | |
array | $tags |
Definition at line 131 of file Aggregation.php.
00132 { 00133 $query = "REPLACE INTO `{$this->_toTagTable}` (aggregation_id, tag_id) VALUES "; 00134 $data = array(); 00135 foreach ($tags as $tagId) { 00136 $data[] = $aggregationId.','.$tagId; 00137 } 00138 $query.= '(' . implode('),(', $data) . ')'; 00139 $this->_getWriteAdapter()->query($query); 00140 return $this; 00141 }
clearCacheData | ( | $ | tags, | |
$ | storeId | |||
) |
Definition at line 102 of file Aggregation.php.
00103 { 00104 $conditions = array(); 00105 if (!$write = $this->_getWriteAdapter()) { 00106 return $this; 00107 } 00108 if (!empty($tags)) { 00109 $tagIds = $this->_getTagIds($tags); 00110 $select = $write->select() 00111 ->from($this->_toTagTable, 'aggregation_id') 00112 ->where('tag_id IN (?)', $tagIds); 00113 $conditions[] = $write->quoteInto('aggregation_id IN ?', $select); 00114 } 00115 00116 if ($storeId !== null) { 00117 $conditions[] = $write->quoteInto('store_id=?', $storeId); 00118 } 00119 00120 $write->delete($this->getMainTable(), implode(' AND ', $conditions)); 00121 return $this; 00122 }
getCacheData | ( | $ | key, | |
$ | storeId | |||
) |
Get aggregated cache data by data key and store
string | $key | |
int | $store |
Definition at line 49 of file Aggregation.php.
00050 { 00051 $select = $this->_getReadAdapter()->select() 00052 ->from(array('a'=>$this->getMainTable()), 'data') 00053 ->where('a.store_id=?', $storeId) 00054 ->where('a.key=?', $key); 00055 $data = $this->_getReadAdapter()->fetchOne($select); 00056 if ($data) { 00057 $data = unserialize($data); 00058 } else { 00059 $data = array(); 00060 } 00061 return $data; 00062 }
getProductCategoryPaths | ( | $ | productIds | ) |
Definition at line 200 of file Aggregation.php.
00201 { 00202 $select = $this->_getReadAdapter()->select() 00203 ->from(array('cat'=>$this->getTable('catalog/category')), 'path') 00204 ->joinInner( 00205 array('cat_prod'=>$this->getTable('catalog/category_product')), 00206 $this->_getReadAdapter()->quoteInto( 00207 'cat.entity_id=cat_prod.category_id AND cat_prod.product_id IN (?)', 00208 $productIds 00209 ), 00210 array() 00211 ); 00212 return $this->_getReadAdapter()->fetchCol($select); 00213 }
saveCacheData | ( | $ | data, | |
$ | key, | |||
$ | tags, | |||
$ | storeId | |||
) |
Save data to aggreagation table with tags relations
array | $data | |
string | $key | |
array|string | $tags | |
int | $storeId |
Definition at line 73 of file Aggregation.php.
00074 { 00075 $data = serialize($data); 00076 $tags = $this->_getTagIds($tags); 00077 $select = $this->_getWriteAdapter()->select() 00078 ->from(array('a'=>$this->getMainTable()), $this->getIdFieldName()) 00079 ->where('a.store_id=?', $storeId) 00080 ->where('a.key=?', $key); 00081 00082 $id = $this->_getWriteAdapter()->fetchOne($select); 00083 if ($id) { 00084 $this->_getWriteAdapter()->update( 00085 $this->getMainTable(), 00086 array('data'=>$data), 00087 $this->_getWriteAdapter()->quoteInto($this->getIdFieldName().'=?', $id) 00088 ); 00089 } else { 00090 $this->_getWriteAdapter()->insert($this->getMainTable(), array( 00091 'store_id' => $storeId, 00092 'created_at'=> $this->formatDate(time()), 00093 'key' => $key, 00094 'data' => $data 00095 )); 00096 $id = $this->_getWriteAdapter()->lastInsertId(); 00097 } 00098 $this->_saveTagRelations($id, $tags); 00099 return $this; 00100 }
$_tagTable [protected] |
Definition at line 29 of file Aggregation.php.
$_toTagTable [protected] |
Definition at line 30 of file Aggregation.php.