Overview

Packages

  • currencysymbol
  • MAbout
  • Mage
    • Admin
    • Adminhtml
    • AdminNotification
    • Api
    • Api2
    • Authorizenet
    • Backup
    • Bundle
    • Captcha
    • Catalog
    • CatalogIndex
    • CatalogInventory
    • CatalogRule
    • CatalogSearch
    • Centinel
    • Checkout
    • Cms
    • Compiler
    • Connect
    • Contacts
    • Core
    • Cron
    • CurrencySymbol
    • Customer
    • Dataflow
    • Directory
    • DirtectPost
    • Downloadable
    • Eav
    • GiftMessage
    • GoogleAnalytics
    • GoogleBase
    • GoogleCheckout
    • ImportExport
    • Index
    • Install
    • Log
    • Media
    • Newsletter
    • Oauth
    • Page
    • PageCache
    • Paygate
    • Payment
    • Paypal
    • PaypalUk
    • Persistent
    • Poll
    • ProductAlert
    • Rating
    • Reports
    • Review
    • Rss
    • Rule
    • Sales
    • SalesRule
    • Sedfriend
    • Sendfriend
    • Shipping
    • Sitemap
    • Tag
    • Tax
    • Usa
    • Weee
    • Widget
    • Wishlist
    • XmlConnect
  • None
  • Phoenix
    • Moneybookers
  • PHP
  • Zend
    • Date
    • Mime
    • XmlRpc

Classes

  • Mage_Tag_Block_All
  • Mage_Tag_Block_Customer_Recent
  • Mage_Tag_Block_Customer_Tags
  • Mage_Tag_Block_Customer_View
  • Mage_Tag_Block_Popular
  • Mage_Tag_Block_Product_List
  • Mage_Tag_Block_Product_Result
  • Mage_Tag_CustomerController
  • Mage_Tag_Helper_Data
  • Mage_Tag_IndexController
  • Mage_Tag_ListController
  • Mage_Tag_Model_Api
  • Mage_Tag_Model_Api_V2
  • Mage_Tag_Model_Entity_Customer_Collection
  • Mage_Tag_Model_Indexer_Summary
  • Mage_Tag_Model_Mysql4_Customer_Collection
  • Mage_Tag_Model_Mysql4_Indexer_Summary
  • Mage_Tag_Model_Mysql4_Popular_Collection
  • Mage_Tag_Model_Mysql4_Product_Collection
  • Mage_Tag_Model_Mysql4_Tag
  • Mage_Tag_Model_Mysql4_Tag_Collection
  • Mage_Tag_Model_Mysql4_Tag_Relation
  • Mage_Tag_Model_Resource_Customer_Collection
  • Mage_Tag_Model_Resource_Indexer_Summary
  • Mage_Tag_Model_Resource_Popular_Collection
  • Mage_Tag_Model_Resource_Product_Collection
  • Mage_Tag_Model_Resource_Tag
  • Mage_Tag_Model_Resource_Tag_Collection
  • Mage_Tag_Model_Resource_Tag_Relation
  • Mage_Tag_Model_Session
  • Mage_Tag_Model_Tag
  • Mage_Tag_Model_Tag_Relation
  • Mage_Tag_ProductController
  • Overview
  • Package
  • Class
  • Tree
  1: <?php
  2: /**
  3:  * Magento
  4:  *
  5:  * NOTICE OF LICENSE
  6:  *
  7:  * This source file is subject to the Open Software License (OSL 3.0)
  8:  * that is bundled with this package in the file LICENSE.txt.
  9:  * It is also available through the world-wide-web at this URL:
 10:  * http://opensource.org/licenses/osl-3.0.php
 11:  * If you did not receive a copy of the license and are unable to
 12:  * obtain it through the world-wide-web, please send an email
 13:  * to license@magentocommerce.com so we can send you a copy immediately.
 14:  *
 15:  * DISCLAIMER
 16:  *
 17:  * Do not edit or add to this file if you wish to upgrade Magento to newer
 18:  * versions in the future. If you wish to customize Magento for your
 19:  * needs please refer to http://www.magentocommerce.com for more information.
 20:  *
 21:  * @category    Mage
 22:  * @package     Mage_Tag
 23:  * @copyright   Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
 24:  * @license     http://opensource.org/licenses/osl-3.0.php  Open Software License (OSL 3.0)
 25:  */
 26: 
 27: 
 28: /**
 29:  * Tag Indexer Model
 30:  *
 31:  * @category    Mage
 32:  * @package     Mage_Tag
 33:  * @author      Magento Core Team <core@magentocommerce.com>
 34:  */
 35: class Mage_Tag_Model_Resource_Indexer_Summary extends Mage_Catalog_Model_Resource_Product_Indexer_Abstract
 36: {
 37:     /**
 38:      * Define main table
 39:      *
 40:      */
 41:     protected function _construct()
 42:     {
 43:         $this->_init('tag/summary', 'tag_id');
 44:     }
 45: 
 46:     /**
 47:      * Process tag save
 48:      *
 49:      * @param Mage_Index_Model_Event $event
 50:      * @return Mage_Tag_Model_Resource_Indexer_Summary
 51:      */
 52:     public function tagSave(Mage_Index_Model_Event $event)
 53:     {
 54:         $data = $event->getNewData();
 55:         if (empty($data['tag_reindex_tag_id'])) {
 56:             return $this;
 57:         }
 58:         return $this->aggregate($data['tag_reindex_tag_id']);
 59:     }
 60: 
 61:     /**
 62:      * Process tag relation save
 63:      *
 64:      * @param Mage_Index_Model_Event $event
 65:      * @return Mage_Tag_Model_Resource_Indexer_Summary
 66:      */
 67:     public function tagRelationSave(Mage_Index_Model_Event $event)
 68:     {
 69:         $data = $event->getNewData();
 70:         if (empty($data['tag_reindex_tag_id'])) {
 71:             return $this;
 72:         }
 73:         return $this->aggregate($data['tag_reindex_tag_id']);
 74:     }
 75: 
 76:     /**
 77:      * Process product save.
 78:      * Method is responsible for index support when product was saved.
 79:      *
 80:      * @param Mage_Index_Model_Event $event
 81:      * @return Mage_Tag_Model_Resource_Indexer_Summary
 82:      */
 83:     public function catalogProductSave(Mage_Index_Model_Event $event)
 84:     {
 85:         $data = $event->getNewData();
 86:         if (empty($data['tag_reindex_required'])) {
 87:             return $this;
 88:         }
 89: 
 90:         $tagIds = Mage::getModel('tag/tag_relation')
 91:             ->setProductId($event->getEntityPk())
 92:             ->getRelatedTagIds();
 93: 
 94:         return $this->aggregate($tagIds);
 95:     }
 96: 
 97:     /**
 98:      * Process product delete.
 99:      * Method is responsible for index support when product was deleted
100:      *
101:      * @param Mage_Index_Model_Event $event
102:      * @return Mage_Tag_Model_Resource_Indexer_Summary
103:      */
104:     public function catalogProductDelete(Mage_Index_Model_Event $event)
105:     {
106:         $data = $event->getNewData();
107:         if (empty($data['tag_reindex_tag_ids'])) {
108:             return $this;
109:         }
110:         return $this->aggregate($data['tag_reindex_tag_ids']);
111:     }
112: 
113:     /**
114:      * Process product massaction
115:      *
116:      * @param Mage_Index_Model_Event $event
117:      * @return Mage_Tag_Model_Resource_Indexer_Summary
118:      */
119:     public function catalogProductMassAction(Mage_Index_Model_Event $event)
120:     {
121:         $data = $event->getNewData();
122:         if (empty($data['tag_reindex_tag_ids'])) {
123:             return $this;
124:         }
125:         return $this->aggregate($data['tag_reindex_tag_ids']);
126:     }
127: 
128:     /**
129:      * Reindex all tags
130:      *
131:      * @return Mage_Tag_Model_Resource_Indexer_Summary
132:      */
133:     public function reindexAll()
134:     {
135:         return $this->aggregate();
136:     }
137: 
138:     /**
139:      * Aggregate tags by specified ids
140:      *
141:      * @param null|int|array $tagIds
142:      * @return Mage_Tag_Model_Resource_Indexer_Summary
143:      */
144:     public function aggregate($tagIds = null)
145:     {
146:         $writeAdapter = $this->_getWriteAdapter();
147:         $this->beginTransaction();
148: 
149:         try {
150:             if (!empty($tagIds)) {
151:                 $writeAdapter->delete(
152:                     $this->getTable('tag/summary'), array('tag_id IN(?)' => $tagIds)
153:                 );
154:             } else {
155:                 $writeAdapter->delete($this->getTable('tag/summary'));
156:             }
157: 
158:             $select = $writeAdapter->select()
159:                 ->from(
160:                     array('tr' => $this->getTable('tag/relation')),
161:                     array(
162:                         'tr.tag_id',
163:                         'tr.store_id',
164:                         'customers'         => 'COUNT(DISTINCT tr.customer_id)',
165:                         'products'          => 'COUNT(DISTINCT tr.product_id)',
166:                         'popularity'        => 'COUNT(tr.customer_id) + MIN('
167:                             . $writeAdapter->getCheckSql(
168:                                 'tp.base_popularity IS NOT NULL',
169:                                 'tp.base_popularity',
170:                                 '0'
171:                                 )
172:                             . ')',
173:                         'uses'              => new Zend_Db_Expr(0), // deprecated since 1.4.0.1
174:                         'historical_uses'   => new Zend_Db_Expr(0), // deprecated since 1.4.0.1
175:                         'base_popularity'   => new Zend_Db_Expr(0)  // deprecated since 1.4.0.1
176:                     )
177:                 )
178:                 ->joinInner(
179:                     array('cs' => $this->getTable('core/store')),
180:                     'cs.store_id = tr.store_id',
181:                     array()
182:                 )
183:                 ->joinInner(
184:                     array('pw' => $this->getTable('catalog/product_website')),
185:                     'cs.website_id = pw.website_id AND tr.product_id = pw.product_id',
186:                     array()
187:                 )
188:                 ->joinInner(
189:                     array('e' => $this->getTable('catalog/product')),
190:                     'tr.product_id = e.entity_id',
191:                     array()
192:                 )
193:                 ->joinLeft(
194:                     array('tp' => $this->getTable('tag/properties')),
195:                     'tp.tag_id = tr.tag_id AND tp.store_id = tr.store_id',
196:                     array()
197:                 )
198:                 ->group(array(
199:                     'tr.tag_id',
200:                     'tr.store_id'
201:                 ))
202:                 ->where('tr.active = 1');
203: 
204:             $statusCond = $writeAdapter->quoteInto('=?', Mage_Catalog_Model_Product_Status::STATUS_ENABLED);
205:             $this->_addAttributeToSelect($select, 'status', 'e.entity_id', 'cs.store_id', $statusCond);
206: 
207:             $visibilityCond = $writeAdapter
208:                 ->quoteInto('!=?', Mage_Catalog_Model_Product_Visibility::VISIBILITY_NOT_VISIBLE);
209:             $this->_addAttributeToSelect($select, 'visibility', 'e.entity_id', 'cs.store_id', $visibilityCond);
210: 
211:             if (!empty($tagIds)) {
212:                 $select->where('tr.tag_id IN(?)', $tagIds);
213:             }
214: 
215:             Mage::dispatchEvent('prepare_catalog_product_index_select', array(
216:                 'select'        => $select,
217:                 'entity_field'  => new Zend_Db_Expr('e.entity_id'),
218:                 'website_field' => new Zend_Db_Expr('cs.website_id'),
219:                 'store_field'   => new Zend_Db_Expr('cs.store_id')
220:             ));
221: 
222:             $writeAdapter->query(
223:                 $select->insertFromSelect($this->getTable('tag/summary'), array(
224:                     'tag_id',
225:                     'store_id',
226:                     'customers',
227:                     'products',
228:                     'popularity',
229:                     'uses',            // deprecated since 1.4.0.1
230:                     'historical_uses', // deprecated since 1.4.0.1
231:                     'base_popularity'  // deprecated since 1.4.0.1
232:                 ))
233:             );
234: 
235: 
236:             $selectedFields = array(
237:                 'tag_id'            => 'tag_id',
238:                 'store_id'          => new Zend_Db_Expr(0),
239:                 'customers'         => 'COUNT(DISTINCT customer_id)',
240:                 'products'          => 'COUNT(DISTINCT product_id)',
241:                 'popularity'        => 'COUNT(customer_id)',
242:                 'uses'              => new Zend_Db_Expr(0), // deprecated since 1.4.0.1
243:                 'historical_uses'   => new Zend_Db_Expr(0), // deprecated since 1.4.0.1
244:                 'base_popularity'   => new Zend_Db_Expr(0)  // deprecated since 1.4.0.1
245:             );
246: 
247:             $agregateSelect = $writeAdapter->select();
248:             $agregateSelect->from($this->getTable('tag/relation'), $selectedFields)
249:                 ->group('tag_id')
250:                 ->where('active = 1');
251: 
252:             if (!empty($tagIds)) {
253:                 $agregateSelect->where('tag_id IN(?)', $tagIds);
254:             }
255: 
256:             $writeAdapter->query(
257:                 $agregateSelect->insertFromSelect($this->getTable('tag/summary'), array_keys($selectedFields))
258:             );
259:             $this->commit();
260:         } catch (Exception $e) {
261:             $this->rollBack();
262:             throw $e;
263:         }
264: 
265:         return $this;
266:     }
267: }
268: 
Magento 1.7.0.2 API documentation generated by ApiGen 2.8.0