Mage_Reports_Model_Mysql4_Event Class Reference

Inheritance diagram for Mage_Reports_Model_Mysql4_Event:

Mage_Core_Model_Mysql4_Abstract Mage_Core_Model_Resource_Abstract

List of all members.

Public Member Functions

 updateCustomerType (Mage_Reports_Model_Event $model, $visitorId, $customerId, $types=array())
 applyLogToCollection (Varien_Data_Collection_Db $collection, $eventTypeId, $eventSubjectId, $subtype, $skipIds=array())
 getCurrentStoreIds (array $predefinedStoreIds=null)
 clean (Mage_Reports_Model_Event $object)

Protected Member Functions

 _construct ()


Detailed Description

Definition at line 34 of file Event.php.


Member Function Documentation

_construct (  )  [protected]

Initialize connection

Reimplemented from Mage_Core_Model_Resource_Abstract.

Definition at line 40 of file Event.php.

00041     {
00042         $this->_init('reports/event', 'event_id');
00043     }

applyLogToCollection ( Varien_Data_Collection_Db collection,
eventTypeId,
eventSubjectId,
subtype,
skipIds = array() 
)

Add events log to a collection The collection id field is used without corellation, so it must be unique. DESC ordering by event will be added to the collection

Parameters:
Varien_Data_Collection_Db $collection
int $eventTypeId
int $eventSubjectId
int $subtype
array $skipIds

Definition at line 80 of file Event.php.

00081     {
00082         $idFieldName = $collection->getResource()->getIdFieldName();
00083 
00084         $derivedSelect = $this->getReadConnection()->select()
00085             ->from($this->getTable('reports/event'), array('event_id' => new Zend_Db_Expr('MAX(event_id)'), 'object_id'))
00086             ->where('event_type_id=?', (int)$eventTypeId)
00087             ->where('subject_id=?',    (int)$eventSubjectId)
00088             ->where('subtype=?',       (int)$subtype)
00089             ->where('store_id IN(?)', $this->getCurrentStoreIds())
00090             ->group('object_id')
00091         ;
00092         if ($skipIds) {
00093             if (!is_array($skipIds)) {
00094                 $skipIds = array((int)$skipIds);
00095             }
00096             $derivedSelect->where('object_id NOT IN(?)', $skipIds);
00097         }
00098 
00099         $collection->getSelect()
00100             ->joinInner(array('evt' => new Zend_Db_Expr("({$derivedSelect})")), "`{$idFieldName}`=evt.object_id", array())
00101             ->order('evt.event_id DESC');
00102     }

clean ( Mage_Reports_Model_Event object  ) 

Clean report event table

Parameters:
Mage_Reports_Model_Event $object
Returns:
Mage_Reports_Model_Mysql4_Event

Definition at line 154 of file Event.php.

00155     {
00156         while (true) {
00157             $select = $this->_getReadAdapter()->select()
00158                 ->from(array('event_table' => $this->getMainTable()), array('event_id'))
00159                 ->joinLeft(
00160                     array('visitor_table' => $this->getTable('log/visitor')),
00161                     'event_table.subject_id = visitor_table.visitor_id',
00162                     array())
00163                 ->where('visitor_table.visitor_id IS NULL')
00164                 ->where('event_table.subtype=?', 1)
00165                 ->limit(1000);
00166             $eventIds = $this->_getReadAdapter()->fetchCol($select);
00167 
00168             if (!$eventIds) {
00169                 break;
00170             }
00171 
00172             $this->_getWriteAdapter()->delete(
00173                 $this->getMainTable(),
00174                 $this->_getWriteAdapter()->quoteInto('event_id IN(?)', $eventIds)
00175             );
00176         }
00177         return $this;
00178     }

getCurrentStoreIds ( array predefinedStoreIds = null  ) 

Obtain all current store ids, depending on configuration

Parameters:
array $predefinedStoreIds
Returns:
array

Definition at line 110 of file Event.php.

00111     {
00112         $stores = array();
00113         // get all or specified stores
00114         if (Mage::app()->getStore()->getId() == 0) {
00115             if (null !== $predefinedStoreIds) {
00116                 $stores = $predefinedStoreIds;
00117             }
00118             else {
00119                 foreach (Mage::app()->getStores() as $store) {
00120                     $stores[] = $store->getId();
00121                 }
00122             }
00123         }
00124         // get all stores, required by configuration in current store scope
00125         else {
00126             switch (Mage::getStoreConfig('catalog/recently_products/scope')) {
00127                 case 'website':
00128                     $resourceStore = Mage::app()->getStore()->getWebsite()->getStores();
00129                     break;
00130                 case 'group':
00131                     $resourceStore = Mage::app()->getStore()->getGroup()->getStores();
00132                     break;
00133                 default:
00134                     $resourceStore = array(Mage::app()->getStore());
00135                     break;
00136             }
00137 
00138             foreach ($resourceStore as $store) {
00139                 $stores[] = $store->getId();
00140             }
00141         }
00142         foreach ($stores as $key => $store) {
00143             $stores[$key] = (int)$store;
00144         }
00145         return $stores;
00146     }

updateCustomerType ( Mage_Reports_Model_Event model,
visitorId,
customerId,
types = array() 
)

Update customer type after customer login

Parameters:
Mage_Reports_Model_Event $model
int $visitorId
int $customerId
array $types
Returns:
Mage_Reports_Model_Mysql4_Event

Definition at line 54 of file Event.php.

00055     {
00056         if ($types) {
00057             $this->_getWriteAdapter()->update($this->getMainTable(),
00058                 array('subject_id' => $customerId, 'subtype' => 0),
00059                 array(
00060                     $this->_getWriteAdapter()->quoteInto('subject_id=?', $visitorId),
00061                     $this->_getWriteAdapter()->quoteInto('subtype=?', 1),
00062                     $this->_getWriteAdapter()->quoteInto('event_type_id IN(?)', $types)
00063                 )
00064             );
00065         }
00066         return $this;
00067     }


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

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